diff --git a/docs/Plugins.md b/docs/Plugins.md index e1a0141e..c05a0797 100644 --- a/docs/Plugins.md +++ b/docs/Plugins.md @@ -13,6 +13,7 @@ - [Changing Notification Settings](#changing-notification-settings) - [Chain Reaction Control](#chain-reaction-control) * [Chain Data](#chain-data) + * [Chain Params](#chain-params) - [Custom Data Tables](#custom-data-tables) - [Custom HTML Content](#custom-html-content) - [Updating The Event](#updating-the-event) @@ -226,6 +227,16 @@ You can pass custom JSON data to the next event in the chain, when using a [Chai So in this case when the event `e29bf12db` runs, it will be passed your `chain_data` object as part of the JSON sent to it when the job starts. The Plugin code running the chained event can access the data by parsing the JSON and grabbing the `chain_data` property. +##### Chain Params + +In addition to passing `chain_data` to chained events (see above), you can also override some or all the *parameters* of the chained event (the key/value pairs normally populated by the Plugin). To do this, specify a JSON property called `chain_params` in your JSON output, and pass in an object containing param keys. This will be merged with the default event Plugin parameters when the chained job is executed. Example: + +```js +{ "chain": "e29bf12db", "chain_params": { "custom_key": "foobar", "value": 42 } } +``` + +Note that the contents of the `chain_params` object will be *shallow-merged* into the event's default Plugin params, so your object can be sparsely populated. This is done so that you can replace any keys that you want, or even add new ones, and you do not need to specify all the params the event is expecting. + #### Custom Data Tables If your Plugin produces statistics or other tabular data at the end of a run, you can have Cronicle render this into a table on the Job Details page. Simply print a JSON object with a property named `table`, containing the following keys: diff --git a/lib/job.js b/lib/job.js index 797366fd..d24f2a0f 100644 --- a/lib/job.js +++ b/lib/job.js @@ -696,7 +696,7 @@ module.exports = Class.create({ } // only pull in properties we recognize - ['progress', 'complete', 'code', 'description', 'perf', 'update_event', 'table', 'html', 'chain', 'chain_data', 'chain_error', 'notify_success', 'notify_fail'].forEach( function(key) { + ['progress', 'complete', 'code', 'description', 'perf', 'update_event', 'table', 'html', 'chain', 'chain_data', 'chain_params', 'chain_error', 'notify_success', 'notify_fail'].forEach( function(key) { if (key in data) job[key] = data[key]; } ); diff --git a/lib/scheduler.js b/lib/scheduler.js index 7a81fdac..8d0d51f7 100644 --- a/lib/scheduler.js +++ b/lib/scheduler.js @@ -313,6 +313,10 @@ module.exports = Class.create({ source_event: old_job.event } ); + // merge in chain_params if applicable + if (!job.params) job.params = {}; + if (old_job.chain_params) Tools.mergeHashInto(job.params, old_job.chain_params); + self.logDebug(6, "Running event via chain reaction: " + job.title, job); self.launchOrQueueJob( job, function(err, jobs_launched) { diff --git a/package.json b/package.json index 5000dc66..c8263af0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Cronicle", - "version": "0.9.37", + "version": "0.9.38", "description": "A simple, distributed task scheduler and runner with a web based UI.", "author": "Joseph Huckaby ", "homepage": "https://github.com/jhuckaby/Cronicle",