Permalink
Browse files

Add async to packages, use parallel to run mongo commands for jobs, t…

…ake out retryonerror and logoutputonsuccess, don't seem very useful
  • Loading branch information...
1 parent aaf0d21 commit 2acd8ecbc638e24e012d8b8dd16eb55aa5655b46 @rfink committed Feb 25, 2012
Showing with 38 additions and 29 deletions.
  1. +0 −2 lib/model/jobschedule.js
  2. +1 −3 lib/model/singlejob.js
  3. +35 −9 lib/tock.js
  4. +0 −10 lib/view/jobschedule/create.html
  5. +0 −4 lib/view/jobschedule/index.html
  6. +2 −1 package.json
View
@@ -9,8 +9,6 @@ var JobSchedule = new Schema({
DaysOfMonth: String,
Months: String,
DaysOfWeek: String,
- RetryOnError: Boolean,
- LogOutputOnSuccess: Boolean,
BindHost: String
});
View
@@ -4,10 +4,8 @@ var Schema = mongoose.Schema;
var SingleJob = new Schema({
Command: String,
Parameters: [String],
- ScheduleDateTime: Date,
+ ScheduleDateTime: { type: Date, index: true },
RunSync: Boolean,
- RetryOnError: Boolean,
- LogOutputOnSuccess: Boolean,
BindHost: String
});
View
@@ -9,6 +9,7 @@
var moment = require('moment');
var config = require('./config');
var _ = require('underscore');
+var async = require('async');
var fs = require('fs');
var http = require('http');
var mongoose = require('mongoose');
@@ -33,7 +34,7 @@ errorHandler.ERROR_CRITICAL = 3;
mongoose.connect('mongodb://' + config.dataStore.host + '/Tock', function(err) {
if (err) {
- console.error(err);
+ errorHandler(errorHandler.ERROR_CRITICAL, JSON.stringify(err));
process.exit(1);
}
});
@@ -55,10 +56,25 @@ io.sockets.on('connection', function(socket) {
/**
* Get our jobs to run
+ * @param {Date} curMinute
* @param {Function} callback
* @return {object}
*/
-var getJobs = function(callback) {
+var getJobs = function(curMinute, callback) {
+ async.parallel(
+ {
+ schedule: function(cb) {
+ JobSchedule.find().run(cb);
+ },
+ singleJob: function(cb) {
+ SingleJob.find({ ScheduleDateTime: curMinute }).run(cb);
+ }
+ },
+ function(err, results) {
+ if (err) return callback(err);
+ return _.union(results.schedule, results.singleJob);
+ }
+ );
JobSchedule.find().run(function(err, results) {
if (err) return callback(err);
return callback(null, results);
@@ -161,7 +177,7 @@ var spawnJob = function(job, callback) {
});
} else if (typeof obj.errorCode !== 'undefined') {
errorCode = obj.errorCode;
- // TODO: Error
+ return errorHandler(errorHandler.ERROR_WARNING, errorCode);
} else if (typeof obj.stats !== 'undefined') {
JobModel.TotalRunTime = obj.stats.totalRunTime;
JobModel.Pid = obj.stats.pid;
@@ -242,7 +258,7 @@ var dispatch = function() {
// I don't QUITE trust javascript's set-timeout, so instead of trusting that we ran on or after
// the :00 seconds, round the time to the nearest minute
var curMinute = new Date(Math.round(Date.now() / (1000 * 60)) * 1000 * 60);
- getJobs(function(err, results) {
+ getJobs(curMinute, function(err, results) {
results.forEach(function(job) {
if (isEligibleSlot(job, curMinute)) {
spawnJob(job);
@@ -274,10 +290,18 @@ http.createServer(function(request, response) {
var singleJobModel = new SingleJob(reqBody.job, true);
if (!singleJobModel.ScheduleDateTime) singleJobModel.ScheduleDateTime = Date.now();
singleJobModel.save(function(err) {
- // TODO: If error
+ if (err) {
+ response.write(JSON.stringify(err));
+ response.end();
+ return errorHandler(errorHandler.ERROR_CRITICAL, err);
+ }
if (reqBody.job.RunSync) {
spawnJob(reqBody.job, function(err, spawnJobResponse) {
- // TODO: If error
+ if (err) {
+ response.write(JSON.stringify(err));
+ response.end();
+ return errorHandler(errorHandler.ERROR_WARNING, err);
+ }
response.write(JSON.stringify(spawnJobResponse));
response.end();
});
@@ -289,13 +313,15 @@ http.createServer(function(request, response) {
break;
case 'killJob':
killJob(reqBody.id, function(err, killJobResponse) {
- // TODO: If error
+ if (err) {
+ response.write(JSON.stringify(err));
+ response.end();
+ return errorHandler(errorHandler.ERROR_WARNING, err);
+ }
response.write(JSON.stringify(killJobResponse));
response.end();
});
break;
- case '':
- break;
default:
errorHandler(errorHandler.ERROR_NOTICE, 'Invalid request type');
}
@@ -34,16 +34,6 @@
</div>
{% endfor %}
<div class="input-row">
- <label for="input-retryonerror">Retry Job on Error</label>
- <input type="checkbox" value="1" id="input-retryonerror"
- name="JobSchedule[RetryOnError]" {% if RetryOnError %}checked="checked"{% endif %} />
- </div>
- <div class="input-row">
- <label for="input-logoutputonsuccess">Log Output on Success</label>
- <input type="checkbox" id="input-logoutputonsuccess"
- name="JobSchedule[LogOutputOnSuccess]" {% if LogOutputOnSuccess %}checked="checked"{% endif %} />
- </div>
- <div class="input-row">
<label for="input-bindhost">Bind Host</label>
<select name="JobSchedule[BindHost]">
<option value="">None</option>
@@ -11,8 +11,6 @@
<th>Days Of Month</th>
<th>Months</th>
<th>Days Of Week</th>
- <th>Retries</th>
- <th>Supress Success Output</th>
<th>Bind Host</th>
<th></th>
</tr>
@@ -27,8 +25,6 @@
<td>{{ job.DaysOfMonth }}</td>
<td>{{ job.Months }}</td>
<td>{{ job.DaysOfWeek }}</td>
- <td>{{ job.RetryOnError }}</td>
- <td>{{ job.LogOutputOnSuccess }}</td>
<td>{{ job.BindHost }}</td>
<td><a href="/jobschedule/{{ job._id }}">Edit</a></td>
</tr>
View
@@ -24,7 +24,8 @@
"mongoose": "2.4.10",
"swig": "0.9.4",
"socket.io": "0.8.7",
- "JSONParse": "0.0.1"
+ "JSONParse": "0.0.1",
+ "async": "0.1.15"
},
"engine": "node >= 0.6.0"
}

0 comments on commit 2acd8ec

Please sign in to comment.