Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Primary task scheduler for fanignite.
This queries the site api for tasks to schedule, then schedules them.
_ = require 'underscore'
async = require 'async'
request = require 'request'
logSetup = require './log-setup'
iron_mq = require 'iron_mq'
logger = logSetup 'worker-task-scheduler',"",0
ironMq = new iron_mq.Client
token: ""
project_id: ""
ironMqQueue = ironMq.queue "scheduler"
pushData =
push_type: "unicast"
retries: 5
retries_delay: 60
subscribers: [
url: ""
ironMqQueue.update pushData, (err,body) ->
logger.error err if err
return if err "Fetching scheduled tasks at #{new Date()}"
uri: ""
'Content-Type': 'application/json'
'Accept' : 'application/json'
body: JSON.stringify({})
method: "POST"
, (err, res, bodyBeforeJson) ->
logger.error err if err
return if err
result = JSON.parse(bodyBeforeJson)
items = result.items || [] "Queuing #{items.length} scheduled tasks"
Loading one item from the backend, then add it to the queue.
fbOneItem = (item,cb) ->
msg =
body: JSON.stringify({schedulerId : item._id})
delay: 1
expires_in: 60 * 15 # Expires after 15 minutes msg, (err,item) ->
logger.error {error: JSON.stringify(err), message: err.message} if err
cb null
async.eachSeries items, fbOneItem, (err) ->
return logger.error err if err "Queuing #{items.length} scheduled tasks COMPLETE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment