Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84a5db0
commit 705cab1
Showing
15 changed files
with
220 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3.5' | ||
|
||
services: | ||
fastify-cloudprnt: | ||
container_name: fastify-cloudprnt | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- '3000:3000' | ||
command: "npm run example:basic:start" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: '3.5' | ||
|
||
services: | ||
redis: | ||
container_name: cloudprnt-redis | ||
image: redis | ||
ports: | ||
- '6379:6379' | ||
fastify-cloudprnt: | ||
container_name: fastify-cloudprnt | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- '3000:3000' | ||
environment: | ||
- REDIS_URL=redis://host.docker.internal:6379 | ||
depends_on: | ||
- redis | ||
command: "npm run example:redis:start" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ services: | |
dockerfile: Dockerfile | ||
ports: | ||
- '3000:3000' | ||
command: "npm run test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createClient } from 'redis' | ||
import view from '@fastify/view' | ||
import nunjucks from 'nunjucks' | ||
|
||
import fastifyCloudPrnt from '../../index.js' | ||
|
||
const JOB_DATA = 'printJobData' | ||
const PRINT_QUEUE = 'printJobQueue' | ||
const REDIS_URL = process.env.REDIS_URL | ||
|
||
export default async function basic (fastify, options) { | ||
// redis connection url defaults to localhost on port 6379 | ||
const redis = createClient({ url: REDIS_URL }) | ||
await redis.connect() | ||
|
||
await fastify.register(view, { | ||
engine: { nunjucks }, | ||
root: './examples' | ||
}) | ||
|
||
await fastify.register(fastifyCloudPrnt, { | ||
queueJob: async (token, jobData) => { | ||
await redis.HSET(JOB_DATA, token, JSON.stringify(jobData)) | ||
await redis.LPUSH(PRINT_QUEUE, token) | ||
}, | ||
getJob: async () => { | ||
const token = await redis.LINDEX(PRINT_QUEUE, 0) | ||
return token === undefined ? null : token | ||
}, | ||
getJobData: async token => { | ||
const jsonJobData = await redis.HGET(JOB_DATA, token) | ||
if (!jsonJobData) { | ||
return null | ||
} | ||
return JSON.parse(jsonJobData) | ||
}, | ||
deleteJob: async token => { | ||
await redis.HDEL(JOB_DATA, token) | ||
const deletedPrintJob = await redis.LREM(PRINT_QUEUE, 1, token) | ||
|
||
return deletedPrintJob > 0 | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.