Question

Say I want to run a custom Node script on my DocPad server once a day (like a cron job), where would I put it? I can build a Node script that does stuff after an interval, I'm more curious about where to reference / run the script in the DocPad server.

A plugin is possible, though I've seen that you can require Node libraries within the DocPad configuration file so it could go in there.

Is there a suggested way to approach this?

Was it helpful?

Solution

If you're wanting something purely cron-like, probably using the docpadReady event would be the way to go, doing something like:

docpadReady: ->
  require('schedule').every('2 minutes').do ->
    require('safeps').spawn('your cron job')

Alternatively, maybe DocPad's regenerateEvery configuration option is suitable. This tells DocPad to regenerate every X millseconds, which will naturally call the generate events that you could hook into.

Alternatively, is there a need for these crons to run on the same server as DocPad? If not, you could do them completely separately.

A final option, is to see if your server you are deploying to supports spawning multiple files. So DocPad's Server is spawned, and so is cron, with DocPad not knowing about the cron task at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top