adding a check to jobs before importing from file
parent
4226311766
commit
b207df5332
19
crontab.js
19
crontab.js
|
@ -65,11 +65,17 @@ exports.set_crontab = function(env_vars, callback){
|
|||
tabs.forEach(function(tab){
|
||||
if(!tab.stopped) {
|
||||
if (tab.logging && tab.logging == "true") {
|
||||
tmp_log = "/tmp/" + tab._id + ".log";
|
||||
log_file = exports.log_folder + "/" + tab._id + ".log";
|
||||
let tmp_log = "/tmp/" + tab._id + ".log";
|
||||
let log_file = exports.log_folder + "/" + tab._id + ".log";
|
||||
if(tab.command[tab.command.length-1] != ";") // add semicolon
|
||||
tab.command +=";";
|
||||
crontab_string += tab.schedule + " { " + tab.command + " } 2> " + tmp_log +"; if test -f " + tmp_log +"; then date >> " + log_file + "; cat " + tmp_log + " >> " + log_file + "; rm " + tmp_log + "; fi \n";
|
||||
// hook is in beta
|
||||
if (tab.hook){
|
||||
let tmp_hook = "/tmp/" + tab._id + ".hook";
|
||||
crontab_string += tab.schedule + " ({ " + tab.command + " } | tee " + tmp_hook + ") 3>&1 1>&2 2>&3 | tee " + tmp_log +"; if test -f " + tmp_log +"; then date >> " + log_file + "; cat " + tmp_log + " >> " + log_file + "; rm " + tmp_log + "; fi; if test -f " + tmp_hook + "; then " + tab.hook + " < " + tmp_hook + "; rm " + tmp_hook + "; fi \n";
|
||||
} else {
|
||||
crontab_string += tab.schedule + " { " + tab.command + " } 2> " + tmp_log +"; if test -f " + tmp_log +"; then date >> " + log_file + "; cat " + tmp_log + " >> " + log_file + "; rm " + tmp_log + "; fi \n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
crontab_string += tab.schedule + " " + tab.command + "\n";
|
||||
|
@ -96,7 +102,7 @@ exports.get_backup_names = function(){
|
|||
var backups = [];
|
||||
fs.readdirSync(__dirname + '/crontabs').forEach(function(file){
|
||||
// file name begins with backup
|
||||
if(file.indexOf("backup") == 0){
|
||||
if(file.indexOf("backup") === 0){
|
||||
backups.push(file);
|
||||
}
|
||||
});
|
||||
|
@ -150,7 +156,10 @@ exports.import_crontab = function(){
|
|||
var command = line.replace(regex, '').trim();
|
||||
var schedule = line.replace(command, '').trim();
|
||||
|
||||
if(command && schedule){
|
||||
var is_valid = false;
|
||||
try { is_valid = cron_parser.parseString(line).expressions.length > 0; } catch (e){}
|
||||
|
||||
if(command && schedule && is_valid){
|
||||
var name = namePrefix + '_' + index;
|
||||
|
||||
db.findOne({ command: command, schedule: schedule }, function(err, doc) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "crontab-ui",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"description": "Easy and safe way to manage your crontab file",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -26,6 +26,9 @@ function messageBox(body, title, ok_text, close_text, callback){
|
|||
|
||||
|
||||
/*********** crontab actions ****************/
|
||||
// TODO get rid of global variables
|
||||
var schedule = "";
|
||||
var job_command = "";
|
||||
|
||||
function deleteJob(_id){
|
||||
// TODO fix this. pass callback properly
|
||||
|
@ -84,7 +87,7 @@ function editJob(_id){
|
|||
$("#job-name").val(job.name);
|
||||
$("#job-command").val(job.command);
|
||||
// if macro not used
|
||||
if(job.schedule.indexOf("@") != 0){
|
||||
if(job.schedule.indexOf("@") !== 0){
|
||||
var components = job.schedule.split(" ");
|
||||
$("#job-minute").val(components[0]);
|
||||
$("#job-hour").val(components[1]);
|
||||
|
@ -102,6 +105,9 @@ function editJob(_id){
|
|||
$("#job-save").unbind("click"); // remove existing events attached to this
|
||||
$("#job-save").click(function(){
|
||||
// TODO good old boring validations
|
||||
if (!schedule) {
|
||||
schedule = "* * * * *";
|
||||
}
|
||||
$.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: _id, logging: $("#job-logging").prop("checked")}, function(){
|
||||
location.reload();
|
||||
});
|
||||
|
@ -124,6 +130,9 @@ function newJob(){
|
|||
$("#job-save").unbind("click"); // remove existing events attached to this
|
||||
$("#job-save").click(function(){
|
||||
// TODO good old boring validations
|
||||
if (!schedule) {
|
||||
schedule = "* * * * *";
|
||||
}
|
||||
$.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: -1, logging: $("#job-logging").prop("checked")}, function(){
|
||||
location.reload();
|
||||
});
|
||||
|
@ -162,8 +171,6 @@ function import_db(){
|
|||
|
||||
|
||||
// script corresponding to job popup management
|
||||
var schedule = "";
|
||||
var job_command = "";
|
||||
function job_string(){
|
||||
$("#job-string").val(schedule + " " + job_command);
|
||||
return schedule + " " + job_command;
|
||||
|
|
|
@ -72,7 +72,8 @@
|
|||
<br />
|
||||
<label>Job</label>
|
||||
<input type='text' class='form-control' id='job-string' disabled='disabled'/><br />
|
||||
<label><input type="checkbox" id="job-logging" style="position:relative;top:2px"/> Enable error logging.</label>
|
||||
<label><input type="checkbox" id="job-logging" style="position:relative;top:2px"/> Enable error logging.</label><br />
|
||||
<!-- <label><input type="checkbox" id="job-mail_toggle" style="position:relative;top:2px"/> Enable email.</label> -->
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
|
|
Loading…
Reference in New Issue