From 86db7176873b007313f25879779a7ff853e51298 Mon Sep 17 00:00:00 2001 From: Remington Steed Date: Mon, 5 Aug 2013 09:57:04 -0400 Subject: [PATCH] Allow action trigger events to be repeated Currently, there is no way to repeat an event (action/trigger) when a real-world event occurs more than once for the same target. This only matters for targets that are persistent (such as a library card) combined with events that can reoccur (such as expiration, if the expiration can be removed). To address this, we add a new field to the action_trigger.event_definition table that sets the amount of time after which the event is allowed to repeat. This commit adds the new field to the IDL, database schema and template files and also provides the simple db upgrade script. It is worth noting that we chose to base the repeatability on the start_time of the previous event, which is more predictable than complete_time (which could be null if the event fails). Signed-off-by: Remington Steed Signed-off-by: Mike Rylander --- Open-ILS/examples/fm_IDL.xml | 1 + Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger.pm | 5 +++++ Open-ILS/src/sql/Pg/400.schema.action_trigger.sql | 1 + .../XXXX.schema.action_trigger.event_definition.repeat_delay.sql | 8 ++++++++ .../templates/conify/global/action_trigger/event_definition.tt2 | 2 +- 5 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.action_trigger.event_definition.repeat_delay.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index ba8efaab93..861d10734b 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -1138,6 +1138,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger.pm index 24488e8c0f..ed83cbae1b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger.pm @@ -470,6 +470,11 @@ sub create_batch_events { filter => { event_def => $def->id } } }}; + if ($def->repeat_delay) { + $join->{'join'}{atev}{filter} = { start_time => { + '>' => DateTime->now->subtract( seconds => interval_to_seconds($def->repeat_delay) )->strftime( '%F %T%z' ) + } }; + } push @{ $filter->{'-and'} }, { '+atev' => { id => undef } }; diff --git a/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql b/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql index bf5e61be97..396cd7d210 100644 --- a/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql +++ b/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql @@ -183,6 +183,7 @@ CREATE TABLE action_trigger.event_definition ( cleanup_failure TEXT REFERENCES action_trigger.cleanup (module) DEFERRABLE INITIALLY DEFERRED, delay INTERVAL NOT NULL DEFAULT '5 minutes', max_delay INTERVAL, + repeat_delay INTERVAL, usr_field TEXT, opt_in_setting TEXT REFERENCES config.usr_setting_type (name) DEFERRABLE INITIALLY DEFERRED, delay_field TEXT, -- for instance, xact_start on a circ hook ... look for fields on hook.core_type where datatype=timestamp? If not set, delay from now() diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.action_trigger.event_definition.repeat_delay.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.action_trigger.event_definition.repeat_delay.sql new file mode 100644 index 0000000000..f07a4dcb22 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.action_trigger.event_definition.repeat_delay.sql @@ -0,0 +1,8 @@ +BEGIN; + +--- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +ALTER TABLE action_trigger.event_definition ADD COLUMN repeat_delay INTERVAL; + +COMMIT; + diff --git a/Open-ILS/src/templates/conify/global/action_trigger/event_definition.tt2 b/Open-ILS/src/templates/conify/global/action_trigger/event_definition.tt2 index 069a716aaf..5908cc9d77 100644 --- a/Open-ILS/src/templates/conify/global/action_trigger/event_definition.tt2 +++ b/Open-ILS/src/templates/conify/global/action_trigger/event_definition.tt2 @@ -29,7 +29,7 @@