@@ -154,7 +154,7 @@ api.post('/hook', function (req, res) {
154154We setup our crontab to continuously look for jobs that have not yet been completed.
155155
156156``` bash
157- * * * * * node $( npm bin -g) /pdf-bot -c ./pdf-bot.config.js shift >> /var/log/pdfbot.log 2>&1
157+ * * * * * node $( npm bin -g) /pdf-bot -c ./pdf-bot.config.js shift:all >> /var/log/pdfbot.log 2>&1
158158* * * * * node $( npm bin -g) /pdf-bot -c ./pdf-bot.config.js ping:retry-failed >> /var/log/pdfbot.log 2>&1
159159```
160160
@@ -166,10 +166,10 @@ Let us assume I want to generate a PDF for `https://esbenp.github.io`. I can add
166166$ pdf-bot -c ./pdf-bot.config.js push https://esbenp.github.io --meta ' {"id":1}'
167167```
168168
169- Next, if my crontab is not setup to run it automatically I can run it using the ` shift ` command
169+ Next, if my crontab is not setup to run it automatically I can run it using the ` shift:all ` command
170170
171171``` bash
172- $ pdf-bot -c ./pdf-bot.config.js shift
172+ $ pdf-bot -c ./pdf-bot.config.js shift:all
173173```
174174
175175This will look for the oldest uncompleted job and run it.
@@ -283,6 +283,54 @@ curl -X POST -H 'Authorization: Bearer api-token' -H 'Content-Type: application/
283283 }'
284284```
285285
286+ ## Database
287+
288+ ### LowDB (file-database) (default)
289+
290+ If you have low conurrency (run a job every now and then) you can use the default database driver that uses LowDB.
291+
292+ ``` javascript
293+ var LowDB = require (' pdf-bot/src/db/lowdb' )
294+
295+ module .exports = {
296+ api: {
297+ token: ' api-token'
298+ },
299+ db: LowDB ({
300+ lowDbOptions: {},
301+ path: ' ' // defaults to $storagePath/db/db.json
302+ }),
303+ webhook: {
304+ secret: ' 1234' ,
305+ url: ' http://localhost:3000/webhooks/pdf'
306+ }
307+ }
308+ ```
309+
310+ ### PostgreSQL
311+
312+ ``` javascript
313+ var pgsql = require (' pdf-bot/src/db/pgsql' )
314+
315+ module .exports = {
316+ api: {
317+ token: ' api-token'
318+ },
319+ db: pgsql ({
320+ database: ' pdfbot' ,
321+ username: ' pdfbot' ,
322+ password: ' pdfbot' ,
323+ port: 5432
324+ }),
325+ webhook: {
326+ secret: ' 1234' ,
327+ url: ' http://localhost:3000/webhooks/pdf'
328+ }
329+ }
330+ ```
331+
332+ To install the necessary database tables, run ` db:migrate ` . You can also destroy the database by running ` db:destroy ` .
333+
286334## Storage
287335
288336Currently ` pdf-bot ` comes bundled with build-in support for storing PDFs on Amazon S3.
@@ -335,6 +383,7 @@ module.exports = {
335383 // The token used to validate requests to your API. Not required, but 100% recommended.
336384 token: ' api-token'
337385 },
386+ db: LowDB (), // see other drivers under Database
338387 // html-pdf-chrome
339388 generator: {
340389 // Triggers that specify when the PDF should be generated
@@ -351,20 +400,16 @@ module.exports = {
351400 // How many times should pdf-bot try to generate a PDF?
352401 // (default: 5)
353402 generationMaxTries: 5 ,
403+ // How many generations to run at the same time when using shift:all
404+ parallelism: 4 ,
354405 // How frequent should pdf-bot retry failed webhook pings?
355406 // (default: 1 min, 3 min, 10 min, 30 min, 60 min)
356407 webhookRetryStrategy : function (job , retries ) {
357408 return decaySchedule[retries - 1 ] ? decaySchedule[retries - 1 ] : 0
358409 },
359410 // How many times should pdf-bot try to ping a webhook?
360411 // (default: 5)
361- webhookMaxTries: 5 ,
362- // In what path should the database be stored?
363- path: ' storage/db/db.json' ,
364- // pdf-bot uses lowdb. You can pass options to it here.
365- lowDbOptions: {
366-
367- }
412+ webhookMaxTries: 5
368413 },
369414 storage: {
370415 ' s3' : createS3Config ({
@@ -412,6 +457,8 @@ $ pdf-bot.js --config ./examples/pdf-bot.config.js --help
412457 Commands:
413458
414459 api Start the API
460+ db:migrate
461+ db:destroy
415462 install
416463 generate [jobID] Generate PDF for job
417464 jobs [options] List all completed jobs
@@ -421,6 +468,7 @@ $ pdf-bot.js --config ./examples/pdf-bot.config.js --help
421468 purge [options] Will remove all completed jobs
422469 push [options] [url] Push new job to the queue
423470 shift Run the next job in the queue
471+ shift:all Run all unfinished jobs in the queue
424472```
425473
426474## Debug mode
0 commit comments