From 869139260b313781d1901e1380c9ac6beb1203c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 27 Oct 2016 17:36:40 +0200 Subject: [PATCH] Implement function to save work-in-progress jobs --- batch/job_backend.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/batch/job_backend.js b/batch/job_backend.js index ae522f20..ca964329 100644 --- a/batch/job_backend.js +++ b/batch/job_backend.js @@ -9,6 +9,7 @@ function JobBackend(metadataBackend, jobQueue) { this.jobQueue = jobQueue; this.maxNumberOfQueuedJobs = global.settings.batch_max_queued_jobs || 64; this.inSecondsJobTTLAfterFinished = global.settings.finished_jobs_ttl_in_seconds || 2 * 3600; // 2 hours + this.hostname = global.settings.api_hostname || 'batch'; } function toRedisParams(job) { @@ -164,6 +165,21 @@ JobBackend.prototype.save = function (job, callback) { }); }; +var WORK_IN_PROGRESS_JOB = { + DB: 5, + PREFIX: 'batch:wip:' +}; + +JobBackend.prototype.addWorkInProgressJob = function (job_id, user, callback) { + var hostWIPKey = WORK_IN_PROGRESS_JOB.PREFIX + this.hostname; // Will be used for draining jobs. + var userWIPKey = WORK_IN_PROGRESS_JOB.PREFIX + user; // Will be used for listing users and running jobs + + this.metadataBackend.redisMultiCmd(WORK_IN_PROGRESS_JOB.DB, [ + ['RPUSH', hostWIPKey, job_id], + ['RPUSH', userWIPKey, job_id] + ], callback); +}; + JobBackend.prototype.setTTL = function (job, callback) { var self = this; var redisKey = REDIS_PREFIX + job.job_id;