Skip to content

Commit

Permalink
Add runsync option (inline job processing), a few style changes, and …
Browse files Browse the repository at this point in the history
…a bug fix for double saving jobs
  • Loading branch information
rfink committed Feb 22, 2012
1 parent 24725d1 commit 5128da6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ app.post('/singlejob/post', function(req, res, next) {
response.on('end', function() {
var dataObject = JSON.parse(data);
// TODO: Check for error, flash message
req.flash('Successfully scheduled job');
req.flash('success', 'Successfully scheduled job');
return res.redirect('/singlejob/create');
});
});
Expand All @@ -230,7 +230,7 @@ app.post('/singlejob/post', function(req, res, next) {
* @return {object}
*/
app.get('/singlejob/create', function(req, res, next) {
return res.render('singlejob/index.html');
return res.render('singlejob/index.html', {messages: req.flash()});
});

/**
Expand Down
14 changes: 14 additions & 0 deletions lib/model/singlejob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var SingleJob = new Schema({
Command: String,
Parameters: [String],
ScheduleDateTime: Date,
RunSync: Boolean,
RetryOnError: Boolean,
LogOutputOnSuccess: Boolean,
BindHost: String
});

exports = module.exports = mongoose.model('SingleJob', SingleJob);
3 changes: 3 additions & 0 deletions lib/public/assets/styles/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ div.button-row { text-align: center; padding: 15px; }
#tock-param-add:hover { cursor: pointer; }
.tock-param-remove:hover { cursor: pointer; }

#messages { margin-top: 25px; }
#messages .success { padding: 10px 20px; background-color: #6f6; border: 1px solid #292; margin-top: 5px; }

/* - Data table stuff - */
.dataTable { width: 100%; font-size: 80%; }
table.dataTable { border-spacing: 0; }
Expand Down
25 changes: 20 additions & 5 deletions lib/tock.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var mongoose = require('mongoose');
var io = require('socket.io').listen(config.ioSocketPort);
var Job = require('./model/job');
var JobSchedule = require('./model/jobschedule');
var SingleJob = require('./model/singlejob');
var jsonParse = require('JSONStream').parse;

/**
Expand Down Expand Up @@ -122,7 +123,11 @@ var spawnJob = function(job, callback) {
}
}
// Create job model, populate, save
var JobModel = new Job(job, true);
var JobModel = new Job({
JobScheduleId: job._id,
Command: job.Command,
Parameters: job.Parameters
});
JobModel.Host = host.host;
JobModel.Port = host.port;
JobModel.save(function(err) {
Expand Down Expand Up @@ -165,6 +170,7 @@ var spawnJob = function(job, callback) {
});
res.on('end', function() {
if (runningJobs[JobModel._id]) delete runningJobs[JobModel._id];
console.log(process.memoryUsage());
JobModel.save(function(err) {
if (err) {
errorHandler(errorHandler.ERROR_CRITICAL, err);
Expand Down Expand Up @@ -266,11 +272,20 @@ http.createServer(function(request, response) {
var reqBody = JSON.parse(data);
switch (reqBody.requestType) {
case 'spawnJob':
// TODO: Only spawn if run now specified
spawnJob(reqBody.job, function(err, spawnJobResponse) {
var singleJobModel = new SingleJob(reqBody.job, true);
if (!singleJobModel.ScheduleDateTime) singleJobModel.ScheduleDateTime = Date.now();
singleJobModel.save(function(err) {
// TODO: If error
response.write(JSON.stringify(spawnJobResponse));
response.end();
if (reqBody.job.RunSync) {
spawnJob(reqBody.job, function(err, spawnJobResponse) {
// TODO: If error
response.write(JSON.stringify(spawnJobResponse));
response.end();
});
} else {
response.write(JSON.stringify(singleJobModel));
response.end();
}
});
break;
case 'killJob':
Expand Down
7 changes: 5 additions & 2 deletions lib/view/layout/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
<div id="inner-header">&nbsp;</div>
<div id="content">
<div id="messages">
{% for message in messages %}
<div class="{{ message.type }}">{{ message.message }}</div>
{% for messageTypes in messages %}
{% set myKey = forloop.key %}
{% for message in messageTypes %}
<div class="{{ myKey }}">{{ message }}</div>
{% endfor %}
{% endfor %}
</div>
{% block content %}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion lib/view/singlejob/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h2>Single Job Schedule</h2>
</div>
<div class="input-row">
<label>Run Job Now</label>
<input type="checkbox" name="Job[RunNow]" id="run-job-now" />
<input type="checkbox" name="Job[RunSync]" id="run-job-now" />
</div>
</div>
<div class="button-row">
Expand Down

0 comments on commit 5128da6

Please sign in to comment.