2016-05-14 00:50:55 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var util = require('util');
|
2019-10-04 00:24:39 +08:00
|
|
|
var JobBase = require('./job-base');
|
|
|
|
var jobStatus = require('../job-status');
|
2016-05-14 00:50:55 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
function JobSimple (jobDefinition) {
|
2016-05-23 17:37:09 +08:00
|
|
|
JobBase.call(this, jobDefinition);
|
2016-05-17 07:00:27 +08:00
|
|
|
|
|
|
|
if (!this.data.status) {
|
|
|
|
this.data.status = jobStatus.PENDING;
|
|
|
|
}
|
2016-05-14 00:50:55 +08:00
|
|
|
}
|
|
|
|
util.inherits(JobSimple, JobBase);
|
|
|
|
|
|
|
|
module.exports = JobSimple;
|
|
|
|
|
2016-05-16 07:22:47 +08:00
|
|
|
JobSimple.is = function (query) {
|
2016-05-14 00:50:55 +08:00
|
|
|
return typeof query === 'string';
|
|
|
|
};
|
|
|
|
|
|
|
|
JobSimple.prototype.getNextQuery = function () {
|
2016-05-16 07:22:47 +08:00
|
|
|
if (this.isPending()) {
|
2016-05-14 00:50:55 +08:00
|
|
|
return this.data.query;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
JobSimple.prototype.setQuery = function (query) {
|
2016-05-16 07:22:47 +08:00
|
|
|
if (!JobSimple.is(query)) {
|
|
|
|
throw new Error('You must indicate a valid SQL');
|
2016-05-14 00:50:55 +08:00
|
|
|
}
|
|
|
|
|
2016-05-16 07:22:47 +08:00
|
|
|
JobSimple.super_.prototype.setQuery.call(this, query);
|
2016-05-14 00:50:55 +08:00
|
|
|
};
|
2020-06-30 23:42:59 +08:00
|
|
|
|
|
|
|
JobSimple.prototype.toJSON = function () {
|
|
|
|
return {
|
|
|
|
class: this.constructor.name,
|
|
|
|
id: this.data.job_id,
|
|
|
|
username: this.data.user,
|
|
|
|
status: this.data.status,
|
|
|
|
failed_reason: this.data.failed_reason,
|
|
|
|
created: this.data.created_at,
|
|
|
|
updated: this.data.updated_at,
|
|
|
|
elapsed: elapsedTime(this.data.created_at, this.data.updated_at),
|
|
|
|
dbhost: this.data.host
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
function elapsedTime (startedAt, endedAt) {
|
|
|
|
if (!startedAt || !endedAt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var start = new Date(startedAt);
|
|
|
|
var end = new Date(endedAt);
|
|
|
|
return end.getTime() - start.getTime();
|
|
|
|
}
|