Commit bc3d82ca authored by Frank Bergmann's avatar Frank Bergmann

- Added Cron24 invocation type

- Delete the old optimization of not executing rules
  if the audit_value of an object didn't change
parent 494deffe
...@@ -312,6 +312,7 @@ SELECT im_category_new (85102, 'Email Rule', 'Intranet Rule Type'); ...@@ -312,6 +312,7 @@ SELECT im_category_new (85102, 'Email Rule', 'Intranet Rule Type');
-- Invocation Type -- Invocation Type
SELECT im_category_new (85200, 'After Update', 'Intranet Rule Invocation Type'); SELECT im_category_new (85200, 'After Update', 'Intranet Rule Invocation Type');
SELECT im_category_new (85202, 'After Creation', 'Intranet Rule Invocation Type'); SELECT im_category_new (85202, 'After Creation', 'Intranet Rule Invocation Type');
SELECT im_category_new (85204, 'Cron24', 'Intranet Rule Invocation Type');
......
...@@ -10,7 +10,11 @@ ad_library { ...@@ -10,7 +10,11 @@ ad_library {
# Initialize the search "semaphore" to 0. # Initialize the search "semaphore" to 0.
# There should be only one thread indexing files at a time... # There should be only one thread indexing files at a time...
nsv_set intranet_rule_engine sweeper_p 0 nsv_set intranet_rule_engine sweeper_p 0
nsv_set intranet_rule_engine cron24_p 0
# Check for changed files every X minutes # Check for changed files every X minutes
ad_schedule_proc -thread t [parameter::get_from_package_key -package_key intranet-rule-engine -parameter RuleEngineSweeperInterval -default 61] im_rule_engine_sweeper ad_schedule_proc -thread t [parameter::get_from_package_key -package_key intranet-rule-engine -parameter RuleEngineSweeperInterval -default 61] im_rule_engine_sweeper
# Run a sweeper once per day
ad_schedule_proc -thread t [expr 24*3600] im_rule_engine_cron24_sweeper
...@@ -22,6 +22,7 @@ ad_proc -public im_rule_type_email {} { return 85102 } ...@@ -22,6 +22,7 @@ ad_proc -public im_rule_type_email {} { return 85102 }
ad_proc -public im_rule_type_after_update {} { return 85200 } ad_proc -public im_rule_type_after_update {} { return 85200 }
ad_proc -public im_rule_type_after_create {} { return 85202 } ad_proc -public im_rule_type_after_create {} { return 85202 }
ad_proc -public im_rule_type_cron24 {} { return 85204 }
...@@ -157,7 +158,6 @@ ad_proc im_rule_callback { ...@@ -157,7 +158,6 @@ ad_proc im_rule_callback {
Check if the fields of the underlying object have changed since the last Check if the fields of the underlying object have changed since the last
call and apply the appropriate rule heads. call and apply the appropriate rule heads.
} { } {
if {$debug_p} { ns_log Notice "im_rule_callback: " } if {$debug_p} { ns_log Notice "im_rule_callback: " }
if {$debug_p} { ns_log Notice "im_rule_callback: -------------------------------------------------------------------" } if {$debug_p} { ns_log Notice "im_rule_callback: -------------------------------------------------------------------" }
if {$debug_p} { ns_log Notice "im_rule_callback: " } if {$debug_p} { ns_log Notice "im_rule_callback: " }
...@@ -166,12 +166,6 @@ ad_proc im_rule_callback { ...@@ -166,12 +166,6 @@ ad_proc im_rule_callback {
set old_value [db_string old_value "select rule_engine_old_value from im_biz_objects where object_id = :object_id" -default ""] set old_value [db_string old_value "select rule_engine_old_value from im_biz_objects where object_id = :object_id" -default ""]
set new_value [im_audit_object_value -object_id $object_id] set new_value [im_audit_object_value -object_id $object_id]
# Check for no changes
if {$old_value == $new_value} {
ns_log Notice "im_rule_callback: No change between old and new value - leaving"
return
}
# Update the old value, together with the update time # Update the old value, together with the update time
db_dml old_value_update " db_dml old_value_update "
update im_biz_objects set update im_biz_objects set
...@@ -180,8 +174,16 @@ ad_proc im_rule_callback { ...@@ -180,8 +174,16 @@ ad_proc im_rule_callback {
where object_id = :object_id where object_id = :object_id
" "
set actual_invocation_type_id [im_rule_type_after_update] # Determine the invocation type based on action
if {"" == $old_value} { switch $action {
after_update { set actual_invocation_type_id [im_rule_type_after_update] }
after_create { set actual_invocation_type_id [im_rule_type_after_create] }
cron24 { set actual_invocation_type_id [im_rule_type_cron24] }
default { set actual_invocation_type_id [im_rule_type_after_update] }
}
# Exception: If the object didn't exist before, then override by after_creation
if {"" eq $old_value && $actual_invocation_type_id eq [im_rule_type_after_update]} {
ns_log Notice "im_rule_callback: Didn't find old_value for object_id=$object_id: after_create invocation type" ns_log Notice "im_rule_callback: Didn't find old_value for object_id=$object_id: after_create invocation type"
set actual_invocation_type_id [im_rule_type_after_create] set actual_invocation_type_id [im_rule_type_after_create]
set old_value $new_value set old_value $new_value
...@@ -567,6 +569,61 @@ ad_proc -public im_rule_engine_sweeper_helper { ...@@ -567,6 +569,61 @@ ad_proc -public im_rule_engine_sweeper_helper {
} }
# ----------------------------------------------------------------------
# 24h "Cron"
# ---------------------------------------------------------------------
ad_proc -public im_rule_engine_cron24_sweeper {
} {
Runs once per day and executes rules for all objects in the system.
} {
ns_log Notice "im_rule_engine_cron24_sweeper: Entering sweeper"
set result ""
# Make sure that only one thread is working at a time
if {[nsv_incr intranet_rule_engine cron24_p] > 1} {
nsv_incr intranet_rule_engine cron24_p -1
set result "im_rule_engine_cron24_sweeper: Aborting. There is another process running"
ns_log Error $result
return
}
if {[catch {
set result [im_rule_engine_cron24_sweeper_helper]
ns_log Notice "im_rule_engine_cron24_sweeper: Result: $result"
} err_msg]} {
ns_log Error "im_rule_engine_cron24_sweeper: Error: $err_msg"
}
nsv_incr intranet_rule_engine cron24_p -1
ns_log Notice "im_rule_engine_cron24_sweeper: Leaving sweeper"
return $result
}
ad_proc -public im_rule_engine_cron24_sweeper_helper {
} {
Implementation of Rule Engine Cron24:
Executes rules for all objects in the system.
} {
# Projects - just go for parent projects
set pids [db_list projects "select project_id from im_projects where parent_id is null"]
set len_pids [llength $pids]
set cnt 1
foreach pid $pids {
ns_log Notice "im_rule_engine_cron24_sweeper: Sweeping object #$pid as $cnt of $len_pids"
im_rule_callback -object_id $pid -action cron24
ns_log Notice "im_rule_engine_cron24_sweeper: Finished sweeping object #$pid"
incr cnt
}
}
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Callback Interfaces # Callback Interfaces
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment