Skip to content

Commit

Permalink
Version 0.9.38
Browse files Browse the repository at this point in the history
- Added `chain_params` feature.
  • Loading branch information
jhuckaby committed Oct 24, 2023
1 parent 6dda68e commit 82a162a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/Plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lib/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
} );

Expand Down
4 changes: 4 additions & 0 deletions lib/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <jhuckaby@gmail.com>",
"homepage": "https://github.com/jhuckaby/Cronicle",
Expand Down

0 comments on commit 82a162a

Please sign in to comment.