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