Index: openacs-4/packages/notifications/tcl/notification-email-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-email-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/notifications/tcl/notification-email-procs.tcl 29 Jun 2002 00:21:11 -0000 1.3 +++ openacs-4/packages/notifications/tcl/notification-email-procs.tcl 1 Jul 2002 19:35:30 -0000 1.4 @@ -26,7 +26,11 @@ {-object_id:required} {-type_id:required} } { - return "notification-$object_id-$type_id@[address_domain]" + if {[empty_string_p $object_id] || [empty_string_p $type_id]} { + return "notification" + } else { + return "notification-$object_id-$type_id@[address_domain]" + } } ad_proc -public parse_reply_address { Index: openacs-4/packages/notifications/tcl/notification-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-procs.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/notifications/tcl/notification-procs.xql 3 Jun 2002 22:27:00 -0000 1.4 +++ openacs-4/packages/notifications/tcl/notification-procs.xql 1 Jul 2002 19:35:30 -0000 1.5 @@ -21,7 +21,8 @@ select name, - interval_id + interval_id, + n_seconds from notification_intervals order by n_seconds Index: openacs-4/packages/notifications/tcl/sweep-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/sweep-init.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/notifications/tcl/sweep-init.tcl 29 May 2002 05:12:01 -0000 1.1 +++ openacs-4/packages/notifications/tcl/sweep-init.tcl 1 Jul 2002 19:35:30 -0000 1.2 @@ -13,5 +13,12 @@ ad_schedule_proc -thread t 60 notification::sweep::cleanup_notifications foreach interval [notification::get_all_intervals] { - ad_schedule_proc -thread t 120 notification::sweep::sweep_notifications -interval_id [lindex $interval 1] + set n_seconds [lindex $interval 2] + if {$n_seconds > 0} { + set batched_p 1 + } else { + set batched_p 0 + } + + ad_schedule_proc -thread t $n_seconds notification::sweep::sweep_notifications -interval_id [lindex $interval 1] -batched_p $batched_p } Index: openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/Attic/sweep-procs-oracle.xql,v diff -u -r1.7 -r1.8 --- openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql 29 Jun 2002 00:21:11 -0000 1.7 +++ openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql 1 Jul 2002 19:35:30 -0000 1.8 @@ -37,6 +37,9 @@ and notifications.object_id = notification_requests.object_id and notifications.notification_id = notification_user_map.notification_id(+) and sent_date is null + and notifications.notif_date <= + (sysdate - (select n_seconds / 3600 / 24 from notification_intervals where interval_id= :interval_id)) + order by notification_requests.user_id, notification_requests.type_id Index: openacs-4/packages/notifications/tcl/sweep-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/sweep-procs.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/notifications/tcl/sweep-procs.tcl 25 Jun 2002 18:58:06 -0000 1.6 +++ openacs-4/packages/notifications/tcl/sweep-procs.tcl 1 Jul 2002 19:35:30 -0000 1.7 @@ -39,28 +39,99 @@ # on the mapping table and a null check set notifications [db_list_of_ns_sets select_notifications {}] - foreach notif $notifications { - # If not batched, just send out and mark it - if {!$batched_p} { + if {$batched_p} { + set prev_user_id 0 + set prev_type_id 0 + set prev_deliv_method_id "" + set batched_content "" + set list_of_notification_ids [list] + + # Add a stop codon + lappend notifications STOP + + # Batched sending + foreach notif $notifications { + ns_log Notice "NOTIF-BATCHED: one notif $notif" + + if {$notif != "STOP"} { + ns_log Notice "NOTIF-BATCHED: NOT a stop codon" + set user_id [ns_set get $notif user_id] + set type_id [ns_set get $notif type_id] + } else { + ns_log Notice "NOTIF-BATCHED stop codon!" + set user_id "" + set type_id "" + } + + # Check if we have a new user_id and type_id + # if so, batch up previous stuff and send it + if {$notif == "STOP" || $user_id != $prev_user_id || $type_id != $prev_type_id} { + + ns_log Notice "NOTIF-BATCHED: batching things up for $prev_user_id" + + # If no content, keep going + if {![empty_string_p $batched_content]} { + ns_log Notice "NOTIF-BATCHED: content to send!" + db_transaction { + ns_log Notice "NOTIF-BATCHED: sending content" + notification::delivery::send -to_user_id $prev_user_id \ + -notification_type_id $prev_type_id \ + -subject "\[[ad_system_name] - Batched Notification\]" \ + -content $batched_content \ + -delivery_method_id $prev_deliv_method_id + + ns_log Notice "NOTIF-BATCHED: marking notifications" + foreach not_id $list_of_notification_ids { + # Mark it as sent + notification::mark_sent \ + -notification_id $not_id \ + -user_id $prev_user_id + } + } + + # Reset things + set list_of_notification_ids [list] + set batched_content "" + } else { + ns_log Notice "NOTIF-BATCHED: NO content to send!" + } + } + + if {$notif == "STOP"} { + continue + } + + + # append content to built-up content + ns_log Notice "NOTIF-BATCHED: appending one notif!" + append batched_content "SUBJECT: [ns_set get $notif object_name] - [ns_set get $notif notif_subject]\n[ns_set get $notif notif_text]\n=====================\n" + lappend list_of_notification_ids [ns_set get $notif notification_id] + + # Set the vars + set prev_user_id $user_id + set prev_type_id $type_id + set prev_deliv_method_id [ns_set get $notif delivery_method_id] + } + + } else { + # Unbatched + foreach notif $notifications { db_transaction { # Send it notification::delivery::send -to_user_id [ns_set get $notif user_id] \ - -notification_type_id [ns_set get $notif type_id] \ - -subject "\[[ad_system_name] - [ns_set get $notif object_name]\] [ns_set get $notif notif_subject]" \ - -content [ns_set get $notif notif_text] \ - -reply_object_id [ns_set get $notif response_id] \ - -delivery_method_id [ns_set get $notif delivery_method_id] - + -notification_type_id [ns_set get $notif type_id] \ + -subject "\[[ad_system_name] - [ns_set get $notif object_name]\] [ns_set get $notif notif_subject]" \ + -content [ns_set get $notif notif_text] \ + -reply_object_id [ns_set get $notif response_id] \ + -delivery_method_id [ns_set get $notif delivery_method_id] + # Markt it as sent notification::mark_sent \ - -notification_id [ns_set get $notif notification_id] \ - -user_id [ns_set get $notif user_id] + -notification_id [ns_set get $notif notification_id] \ + -user_id [ns_set get $notif user_id] } - } else { - # It's batched, we're not handling this one yet - ns_log Notice "Notifications: Batched Request not handled" } - } + } } }