Wiki
Clone wikiatlasboard / Jobs
Jobs Development
Creation
In the default package
#!atlasboard generate job myjob atlasboard generate widget mywidget
atlasboard generate dashboard mydashboard
In the "mycompany" package that you created for your board.
atlasboard generate job mycompany#myjob
atlasboard generate widget mycompany#mywidget
atlasboard generate dashboard mycompany#mydashboard
Job Argument
Whenever the scheduler executes, a Job, the following arguments will be passed:
config
: contains the job configuration (from the dashboard or global config files)dependencies
: object with the defined dependencies available to be used by the job. The following dependencies are available:request
: request module (https://github.com/mikeal/request)logger
: our internal logger facade- methods:
warn
,error
,log
- check
atlasboard/lib/logger.js
for the actual implementation
- methods:
job_callback
: callback that needs to be called on every job execution (node style, first argument is an optional error object, and second argument is the actual result data)
Job Examples
This is a basic "Hello World" job:
#!javascript module.exports = function(config, dependencies, job_callback) { var text = "Hello World!"; // first parameter is error (if any). Second parameter is the job result (if success) // you can use the following dependencies: // - dependencies.request : request module (https://github.com/mikeal/request) // - dependencies.logger : logger interface job_callback(null, {title: config.widgetTitle, text: text}); };
A little bit more complex example using request:
#!javascript var $ = require('cheerio'); module.exports = function(config, dependencies, job_callback) { var logger = dependencies.logger; var options = { url: config.freezeUrl, headers: { "authorization": "Basic " + new Buffer(config.globalAuth.pug.username + ":" + config.globalAuth.pug.password).toString("base64") } }; dependencies.request(options, function(err, response, body) { var result = []; if (err || !response || (response.statusCode != 200)) { var err_msg = (err || (response ? ("bad statusCode: " + response.statusCode) : "bad response")) + " from " + options.url; logger.error(err_msg); job_callback(err_msg); } else { var $page = $(body); $page.find('table tr').each(function(index, element) { var branch = $(element).find('td:nth-child(1)'); var frozen = $(element).find('td:nth-child(2)'); if (branch && frozen && (frozen.text().toLowerCase().indexOf('frozen') > -1)){ result.push(branch.text()); } }); job_callback(null, { branches: result }); } }); };
Updated