From 1af36c847594d18151c58dcd6ee9cd1851c0f410 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 27 Nov 2020 17:21:56 +0100 Subject: [PATCH] queued status --- src/config.js | 2 +- src/constants.js | 20 ++++++++++++++++++++ src/controller.js | 2 +- src/jobTypes.js | 5 ----- src/queue.js | 2 ++ src/worker.js | 11 +---------- 6 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 src/constants.js delete mode 100644 src/jobTypes.js diff --git a/src/config.js b/src/config.js index bcb8595..d02b1bd 100644 --- a/src/config.js +++ b/src/config.js @@ -1,6 +1,6 @@ require('dotenv').config() -const jobType = require('./jobTypes') +const { jobType } = require('./constants') const tornConfig = require('torn-token') module.exports = { netId: Number(process.env.NET_ID) || 42, diff --git a/src/constants.js b/src/constants.js new file mode 100644 index 0000000..88a3834 --- /dev/null +++ b/src/constants.js @@ -0,0 +1,20 @@ +const jobType = Object.freeze({ + TORNADO_WITHDRAW: 'TORNADO_WITHDRAW', + MINING_REWARD: 'MINING_REWARD', + MINING_WITHDRAW: 'MINING_WITHDRAW', +}) + +const status = Object.freeze({ + QUEUED: 'QUEUED', + ACCEPTED: 'ACCEPTED', + SENT: 'SENT', + MINED: 'MINED', + RESUBMITTED: 'RESUBMITTED', + CONFIRMED: 'CONFIRMED', + FAILED: 'FAILED', +}) + +module.exports = { + jobType, + status, +} diff --git a/src/controller.js b/src/controller.js index d1fbdc2..7b0d831 100644 --- a/src/controller.js +++ b/src/controller.js @@ -4,7 +4,7 @@ const { getMiningWithdrawInputError, } = require('./validator') const { postJob } = require('./queue') -const jobType = require('./jobTypes') +const { jobType } = require('./constants') async function tornadoWithdraw(req, res) { const inputError = getTornadoWithdrawInputError(req.body) diff --git a/src/jobTypes.js b/src/jobTypes.js deleted file mode 100644 index 4ba40f0..0000000 --- a/src/jobTypes.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = Object.freeze({ - TORNADO_WITHDRAW: 'TORNADO_WITHDRAW', - MINING_REWARD: 'MINING_REWARD', - MINING_WITHDRAW: 'MINING_WITHDRAW', -}) diff --git a/src/queue.js b/src/queue.js index 433eeed..ee1c4ca 100644 --- a/src/queue.js +++ b/src/queue.js @@ -2,6 +2,7 @@ const { v4: uuid } = require('uuid') const Queue = require('bull') const Redis = require('ioredis') const { redisUrl } = require('./config') +const { status } = require('./constants') const redis = new Redis(redisUrl) const queue = new Queue('proofs', redisUrl) @@ -13,6 +14,7 @@ async function postJob({ type, request }) { { id, type, + status: status.QUEUED, ...request, // proof, args, ?contract }, // { removeOnComplete: true }, diff --git a/src/worker.js b/src/worker.js index 350b50d..7183b47 100644 --- a/src/worker.js +++ b/src/worker.js @@ -12,7 +12,7 @@ const miningABI = require('../abis/mining.abi.json') const swapABI = require('../abis/swap.abi.json') const { queue } = require('./queue') const { poseidonHash2, getInstance, fromDecimals } = require('./utils') -const jobType = require('./jobTypes') +const { jobType, status } = require('./constants') const { netId, torn, @@ -42,15 +42,6 @@ const redis = new Redis(redisUrl) const redisSubscribe = new Redis(redisUrl) const gasPriceOracle = new GasPriceOracle({ defaultRpc: httpRpcUrl }) -const status = Object.freeze({ - ACCEPTED: 'ACCEPTED', - SENT: 'SENT', - MINED: 'MINED', - CONFIRMED: 'CONFIRMED', - FAILED: 'FAILED', - RESUBMITTED: 'RESUBMITTED', -}) - async function fetchTree() { const elements = await redis.get('tree:elements') const convert = (_, val) => (typeof val === 'string' ? toBN(val) : val)