events
events promises describe events for cf-reactor to react to: the event to watch for, with the when body, and the bundles to run when it happens, with the then attribute.
events promises can only be made in reactor bundles.
bundle agent create_file(file)
{
files:
"$(file)" create => "true";
}
body when deleted(file)
{
file_deleted => "$(file)";
}
bundle reactor main
{
events:
"Keep /tmp/a"
when => deleted("/tmp/a"),
then => create_file("/tmp/a");
}History: Introduced in 3.29.0.
Attributes
Common attributes
Common attributes are available to all promise types. Full details for common attributes can be found in the Common promise attributes section of the [Promise types] page. The common attributes are as follows:
action
classes
comment
depends_on
handle
if
unless
meta
with
then
Description: The bundle, or the list of bundles, to run in order when the event happens.
bundle agent report_deletion(file)
{
reports:
"$(file) was deleted, restoring it";
}
bundle agent create_file(file)
{
files:
"$(file)" create => "true";
}
bundle agent report_restored(file)
{
reports:
"$(file) was restored";
}
bundle reactor main
{
events:
"Keep /tmp/a"
when => deleted("/tmp/a"),
then => {
report_deletion("/tmp/a"),
create_file("/tmp/a"),
report_restored("/tmp/a"),
};
}All promise types within agent bundles behave like in cf-agent when executed in response to events.
Notes:
- variables and classes created in a bundle run on reaction to an event are destroyed right after the execution. The only exception are persistent classes.
Type: bundle agent or bundle common, or a list of them
when
Description: The event to watch for.
Type: body when
See also: Common body attributes
All event types are mutually exclusive in a when body.
body when deleted(file)
{
file_deleted => "$(file)";
interval => 1;
}
bundle reactor main
{
events:
"Report deletion of /tmp/a"
when => deleted("/tmp/a"),
then => report_deletion("/tmp/a");
}interval
Description: How often, in seconds, cf-reactor checks whether this event has happened.
Each event has its own interval. A lower value means the event is noticed sooner but checked more often. For how polling works, see Under the hood.
body when deleted_slow(file)
{
file_deleted => "$(file)";
interval => 60;
}Type: int
Allowed input range: 1,99999999999
Default value: 1
File event type
File deleted
Description: Creates an event when the file at the given path is deleted.
The event fires when the path existed at one check and is gone at the next one. It fires once per deletion: the file has to be created again before another deletion is detected.
body when deleted(file)
{
file_deleted => "$(file)";
}Type: string
Allowed input range: (arbitrary string)