Skip to content

Commit

Permalink
if schedule file was not available, providing an empty schedule now. …
Browse files Browse the repository at this point in the history
…further updated to commander 2.2.0
  • Loading branch information
Manuel Alabor committed Jun 27, 2014
1 parent 1cc6b8d commit a5d7663
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
10 changes: 6 additions & 4 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ function executeList() {

schedule.load()
.then(function() {
console.log('Scheduled tasks:');
schedule.tasks.forEach(function(task) {
console.log(task);
});
if(schedule.tasks.length > 0) {
console.log('Scheduled tasks:');
schedule.tasks.forEach(console.log.bind());
} else {
console.log('No tasks scheduled.');
}
})
.fail(function(err) {
console.log('Could not list tasks (' + err + ')');
Expand Down
19 changes: 13 additions & 6 deletions lib/model/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,27 @@ Schedule.prototype.toJSON = function toJSON() {
};

/** Function: load
* Loads a persistet <Schedule> in the file which path is available in the
* Loads a persisted <Schedule> in the file which path is available in the
* file property of <Schedule>.
* If the file which backs the <Schedule> is not available, there is no error
* exposed. You will get an empty <Schedule> to work with.
*
* Returns:
* (Promise)
*/
Schedule.prototype.load = function load() {
debug('load');

var self = this;

self.tasks = [];
self.settings = {};

return q.nfcall(fs.readFile, this.file, { encoding: 'utf-8' })
.then(function(data) {
var deserialized;
self.tasks = [];
debug('found ' + self.file + '. populate schedule.');

deserialized = JSON.parse(data);
var deserialized = JSON.parse(data);
self.settings = deserialized.settings || {};

if(Array.isArray(deserialized.tasks)) {
Expand All @@ -252,8 +258,9 @@ Schedule.prototype.load = function load() {

return self;
})
.fail(function(err) {
console.log(err);
.fail(function() {
debug('did not found ' + self.file+'. working with an empty schedule.');
return self;
});
};

Expand Down
9 changes: 9 additions & 0 deletions lib/systemadapter/default.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/** File: DefaultSystemAdapter
* The <DefaultSystemAdapter> uses the tool adapters <at>, <cron> and <rtc> to
* schedule shutdowns and starts for a Ubuntu-alike systems.
*
* Implement your own adapters if you need other tools to schedule actions to
* your system.
*/


var q = require('q')
, at = require('../tooladapter/at')
, cron = require('../tooladapter/cron')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"url": "https://github.com/swissmanu/powerbuddy/issues"
},
"dependencies": {
"commander": "~2.0.0",
"commander": "~2.2.0",
"crontab": "~0.3.4",
"debug": "^0.8.1",
"moment": "^2.6.0",
Expand Down

0 comments on commit a5d7663

Please sign in to comment.