1.0.17 • Published 5 years ago
@collectoriq/qeuu v1.0.17
qeuu
Jobs system based on MySQL.
Installation
Install the npm packages:
npm i
Setup the job
schema table:
CREATE TABLE `job` (
`job_id` varchar(36) NOT NULL,
`status` varchar(20) NOT NULL DEFAULT '',
`queue_name` varchar(255) NOT NULL DEFAULT '',
`timeout` int(11) DEFAULT NULL,
`retry` int(11) NOT NULL DEFAULT '0',
`description` text,
`params` text,
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`timeElapsed` int(10) unsigned DEFAULT NULL,
`timeStarted` timestamp NULL DEFAULT NULL,
`timeEnded` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`job_id`),
KEY `idx_status` (`status`(1)),
KEY `idx_group_hour` (`queue_name`,`status`(1),`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Usage
const Qeuu = require('Qeuu');
const qeuu = new Qeuu({
database: {
hostname: 'localhost:,
user: 'root',
password: 'root',
database: 'my-super-database'
}
})
// Setup the 'task' queue to listen incoming job and execute 10 jobs at the same time
qeuu.execute('task', 10, ({ message }) => {
console.log(message);
return Promise.resolve();
})
// Add new jobs to the 'task' queue
qeuu.add('task', {
params: {
message: 'Hello World'
},
timeout: 60,
retry: 5
})
// Fetch all activities by hour happened on 2018-02-20
const activitiesHour = qeuu.activitiesByHour(2018-02-20')
// [{
// queue_name: 'task',
// status: 'PENDING',
// date: '2018-02-20',
// hour: 16
// total : 1
// }]
// Fetch all activities by hour happened between 2018-02-20 and 2018-03-01
const activitiesDate = qeuu.activitiesByDate('2018-02-20', '2018-03-01')
// [{
// queue_name: 'task',
// status: 'PENDING',
// date: '2018-02-20',
// total : 1
// }]
Documentation
Status possible for a job
PENDING
IN_PROGRESS
COMPLETED
FAILED
STALLED
WARNING
On restart
When .execute
method is called, all jobs IN_PROGRESS
OR STALLED
from the queue_name
queue will be set as PENDING
.