Skip to content

Instantly share code, notes, and snippets.

@cggaurav
Created April 7, 2017 16:25
Show Gist options
  • Save cggaurav/34be6ba5e6601d152af1fade3812894a to your computer and use it in GitHub Desktop.
Save cggaurav/34be6ba5e6601d152af1fade3812894a to your computer and use it in GitHub Desktop.
Gisting!
// ---------------------------------
// Redis
// ------------------------------
import redis from 'redis'
import redisConfig from '../config/redis-config'
const redisArgs = [redisConfig.redis.port, redisConfig.redis.hostname, {auth_pass: redisConfig.redis.password}]
const r = redis.createClient(...redisArgs)
// ---------------------------------
// Queues
// ------------------------------
import Queue from 'bull'
global.queues = {
'errors': new Queue('errors', ...redisArgs),
'items': new Queue('items', ...redisArgs),
}
// ---------------------------------
// Queues: Processing
// ------------------------------
// QUEUE: video
queues['items']
.on('ready', () => {
debug(`worker process video`)('ready')
})
.on('error', (err) => {
debug(`worker process video`)('error', err)
})
.on('active', (job, jobPromise) => {
debug(`worker process video`)('active', job.jobId)
})
.on('stalled', (job) => {
debug(`worker process video`)('stalled', job.jobId)
})
.on('progress', (job, progress) => {
debug(`worker process video`)('progress')
})
.on('completed', (job, result) => {
debug(`worker process video`)('completed', job.jobId, result)
})
.on('failed', (job, err) => {
debug(`worker process video`)('failed', job.jobId, err)
})
.on('paused', () => {
debug(`worker process video`)('paused')
})
.on('resumed', (job) => {
debug(`worker process video`)('resumed', job.jobId)
})
.on('cleaned', (jobs, type) => {
debug(`worker process video`)('cleaned', jobs.map(job => job.jobId), type)
})
.process((job, done) => {
const arg = job.data
Video.process(arg)
.then(data => {
done()
})
.catch(err => {
err.status = 400
handleQueueError(err)
done(err)
})
.finally(() => {
done()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment