2020-09-28 05:28:34 +03:00
|
|
|
const { v4: uuid } = require('uuid')
|
|
|
|
const Queue = require('bull')
|
|
|
|
const Redis = require('ioredis')
|
|
|
|
const { redisUrl } = require('../config')
|
|
|
|
const redis = new Redis(redisUrl)
|
|
|
|
|
|
|
|
const queue = new Queue('proofs', redisUrl)
|
|
|
|
|
2020-09-30 18:35:48 +03:00
|
|
|
async function postJob({ type, data }) {
|
2020-09-28 05:28:34 +03:00
|
|
|
const id = uuid()
|
|
|
|
|
|
|
|
const job = await queue.add(
|
|
|
|
{
|
|
|
|
id,
|
|
|
|
type,
|
|
|
|
data,
|
|
|
|
},
|
|
|
|
// { removeOnComplete: true },
|
|
|
|
)
|
|
|
|
await redis.set(`job:${id}`, job.id)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getJob(uuid) {
|
|
|
|
const id = await redis.get(`job:${uuid}`)
|
|
|
|
return queue.getJobFromId(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getJobStatus(uuid) {
|
|
|
|
const job = await getJob(uuid)
|
2020-10-02 08:38:31 +03:00
|
|
|
// todo job.data doesn't contain current status and other stuff?
|
2020-10-01 16:08:33 +03:00
|
|
|
return job.data
|
2020-09-28 05:28:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
postJob,
|
|
|
|
getJob,
|
|
|
|
getJobStatus,
|
|
|
|
queue,
|
|
|
|
}
|