Index: openacs-4/packages/xowf/tcl/atjob-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowf/tcl/atjob-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/xowf/tcl/atjob-procs.tcl 27 Apr 2015 15:28:22 -0000 1.3 +++ openacs-4/packages/xowf/tcl/atjob-procs.tcl 7 Aug 2017 23:48:30 -0000 1.4 @@ -4,14 +4,19 @@ # # - # define a simple acs-type for at jobs + # Define a simple Class for atjobs. In future versions, this is a + # good candidate to be turned into a nx class. # + # Priority: yshould be a value between 0 and 9, where 9 is the + # hightest priority; default is 5 + # Class create ::xowf::atjob -slots { ::xo::Attribute create owner_id ::xo::Attribute create party_id ::xo::Attribute create cmd ::xo::Attribute create time ::xo::Attribute create object + ::xo::Attribute create priority -default 5 } atjob proc sql_timestamp {tcltime} { @@ -37,27 +42,28 @@ # drop table xowf_atjob; atjob instproc persist {} { - my instvar party_id cmd - set class [self class] - set owner_id [[my object] item_id] - set package_id [[my object] package_id] + set owner_id [${:object} item_id] + set package_id [${:object} package_id] set ansi_time [$class ansi_time [clock scan [my time]]] - if {![info exists party_id]} {my party_id [::xo::cc set untrusted_user_id]} + if {![info exists :party_id]} { + set :party_id [::xo::cc set untrusted_user_id] + } - set form_id [$class form_id -package_id $package_id -parent_id [[my object] parent_id]] + set form_id [$class form_id -package_id $package_id -parent_id [${:object} parent_id]] if {$form_id != 0} { ::xo::db::CrClass get_instance_from_db -item_id $form_id - set instance_attributes [dict merge [$form_id default_instance_attributes] [list cmd $cmd]] + set instance_attributes [dict merge [$form_id default_instance_attributes] [list cmd ${:cmd}]] set name [::xowiki::autoname new -name [$form_id name] -parent_id $owner_id] set f [::xowiki::FormPage new -destroy_on_cleanup \ -package_id $package_id \ -parent_id $owner_id \ -name $name \ + -title ${:priority} \ -nls_language [$form_id nls_language] \ -publish_status "production" \ -publish_date $ansi_time \ - -creation_user $party_id \ + -creation_user ${:party_id} \ -instance_attributes $instance_attributes \ -page_template $form_id] $f save_new -use_given_publish_date true @@ -81,13 +87,14 @@ atjob proc run_jobs {item_ids} { #my log "---run xowf jobs START" + set sql "select package_id, item_id, name, parent_id, publish_status, creation_user, + revision_id, page_template, instance_attributes + from xowiki_form_instance_item_view + where item_id in ([join $item_ids ,])" + set items [::xowiki::FormPage instantiate_objects \ -object_class ::xowiki::FormPage \ - -sql "select i.item_id, i.name, i.parent_id, i.publish_status, o.creation_user, - i.live_revision as revision_id, page_template, instance_attributes - from cr_items i, xowiki_page_instance t, acs_objects o - where i.item_id in ([join $item_ids ,]) and - i.live_revision = t.page_instance_id and o.object_id = i.item_id"] + -sql $sql] if {[llength [$items children]] > 0} { @@ -117,10 +124,11 @@ my log "--at executing atjob $cmd" if {[catch {eval $owner_id $cmd} errorMsg]} { - ns_log error "\n*** atjob $owner_id $cmd lead to error ***\n$errorMsg" + ns_log error "\n*** atjob $owner_id $cmd lead to error ***\n$errorMsg\n$::errorInfo" } else { $item set_live_revision -revision_id [$item revision_id] -publish_status "expired" } + ns_set cleanup } my log "---run xowf jobs END" } @@ -146,18 +154,23 @@ # To make sure we are not fetching pages from unmounted instances # we check for package_id not null. # - set item_ids [::xo::dc list get_due_atjobs " - select i.item_id - from cr_items i, cr_items i2, cr_revisions r, xowiki_page_instance t, acs_objects o - where i.item_id = r.item_id and i.live_revision = r.revision_id - and r.revision_id = t.page_instance_id and o.object_id = i.item_id - and i2.item_id = t.page_template and i2.content_type = '::xowiki::Form' - and i2.name = 'en:atjob-form' - and r.publish_date $op to_timestamp(:ansi_time,'YYYY-MM-DD HH24:MI') - and i.publish_status = 'production' - and o.package_id is not null - " ] - + # The retrieved items are sorted first by title (priority, should + # be a value between 0 and 9, where 9 is the hightest priority; + # default is 5) and then by item_id (earlier created items have a + # lower item_id). + # + set sql "select xi.item_id + from xowiki_form_instance_item_index xi, cr_items i2, cr_items i1, cr_revisions cr + where i2.item_id = xi.page_template and i2.content_type = '::xowiki::Form' and i2.name = 'en:atjob-form' + and cr.publish_date $op to_timestamp(:ansi_time,'YYYY-MM-DD HH24:MI') + and i1.item_id = xi.item_id + and cr.revision_id = i1.live_revision + and xi.publish_status = 'production' + and xi.package_id is not null + order by cr.title desc, xi.item_id asc " + + set item_ids [::xo::dc list get_due_atjobs $sql] + if {[llength $item_ids] > 0} { my log "--at we got [llength $item_ids] scheduled items"