Fix loop DB in docker with autosave
parent
a51b65dd3f
commit
609a265d20
12
crontab.js
12
crontab.js
|
@ -25,6 +25,7 @@ var fs = require('fs');
|
|||
var cron_parser = require("cron-parser");
|
||||
var cronstrue = require('cronstrue/i18n');
|
||||
var humanCronLocate = process.env.HUMANCRON ?? "en"
|
||||
var noNeedUpdateDB = false;
|
||||
|
||||
|
||||
crontab = function(name, command, schedule, stopped, logging, mailing){
|
||||
|
@ -47,20 +48,24 @@ exports.create_new = function(name, command, schedule, logging, mailing){
|
|||
var tab = crontab(name, command, schedule, false, logging, mailing);
|
||||
tab.created = new Date().valueOf();
|
||||
tab.saved = false;
|
||||
noNeedUpdateDB = false;
|
||||
db.insert(tab);
|
||||
};
|
||||
|
||||
exports.update = function(data){
|
||||
var tab = crontab(data.name, data.command, data.schedule, null, data.logging, data.mailing);
|
||||
tab.saved = false;
|
||||
noNeedUpdateDB = false;
|
||||
db.update({_id: data._id}, tab);
|
||||
};
|
||||
|
||||
exports.status = function(_id, stopped){
|
||||
noNeedUpdateDB = false;
|
||||
db.update({_id: _id},{$set: {stopped: stopped, saved: false}});
|
||||
};
|
||||
|
||||
exports.remove = function(_id){
|
||||
noNeedUpdateDB = false;
|
||||
db.remove({_id: _id}, {});
|
||||
};
|
||||
|
||||
|
@ -204,6 +209,7 @@ exports.set_crontab = function(env_vars, callback) {
|
|||
return callback(err);
|
||||
}
|
||||
else {
|
||||
noNeedUpdateDB = true;
|
||||
db.update({},{$set: {saved: true}}, {multi: true});
|
||||
callback();
|
||||
}
|
||||
|
@ -294,6 +300,8 @@ exports.import_crontab = function(){
|
|||
};
|
||||
|
||||
exports.autosave_crontab = function(callback) {
|
||||
let env_vars = exports.get_env();
|
||||
exports.set_crontab(env_vars, callback);
|
||||
if (!noNeedUpdateDB) {
|
||||
let env_vars = exports.get_env();
|
||||
exports.set_crontab(env_vars, callback);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue