Returns Postgresql function with: -
Returns Postgresql function with: +
Adds a package with all the attributes for every function of the same name. -
For example, if you have two functions that could be called
- foo(a,b,c)
and foo(a,c,d)
,
- the package would be registered using:
-
-+ ad_proc qd_add_package {package args} { +- qd_add_package foo a b c d --
Adds a package with all the attributes for every function of the same name. +
For example, if you have two functions that could be called
+ foo(a,b,c)
and foo(a,c,d)
,
+ the package would be registered using:
+
+-} { + } { nsv_set qd_pg_packages $package $args set n 1 foreach attr $args { - nsv_set $package $attr $n - set n [expr $n * 2] + nsv_set $package $attr $n + set n [expr $n * 2] } -} + } -ad_proc qd_total_attributes {package attributes} { + ad_proc qd_total_attributes {package attributes} { -+ qd_add_package foo a b c d ++
Totals the attribute values. -} { +
Totals the attribute values. + } { upvar $package package_array upvar $attributes attrs set total 0 foreach attribute $attrs { - incr total $package_array($attribute) - ns_log Debug "Adding $package_array($attribute) $total" + incr total $package_array($attribute) + ns_log Debug "Adding $package_array($attribute) $total" } return $total -} + } -ad_proc qd_add_function {package args} { + ad_proc qd_add_function {package args} { -
Adds a single function, including defaults to a package. -
If one foo function has three attributes: a, b and c, where - a is required and b can be null and c default to 't', +
Adds a single function, including defaults to a package. +
If one foo function has three attributes: a, b and c, where + a is required and b can be null and c default to 't', the function would be - registered using: -
-+ registered using: +- qd_add_function foo a "" b "null" c "'t'" --
+-} { + } { # total up the function value. array set temp_package [nsv_array get $package] set i 1 foreach {attr default} $args { - lappend attr_list $attr + lappend attr_list $attr } set total [qd_total_attributes temp_package attr_list] nsv_set ${package}_functions $total $args -} + } -ad_proc qd_choose_function {package args} { + ad_proc qd_choose_function {package args} { -+ qd_add_function foo a "" b "null" c "'t'" ++
Used to choose a function based on passed in attributes. +
Used to choose a function based on passed in attributes. -} { + } { array set temp_package [nsv_array get $package] set total [qd_total_attributes temp_package args] - if {[nsv_exists ${package}_functions $total]} { - ns_log Debug "Found matching sig: '$total'" - return [nsv_get ${package}_functions $total] + if {[nsv_exists ${package}_functions $total]} { + ns_log Debug "Found matching sig: '$total'" + return [nsv_get ${package}_functions $total] } set functions [nsv_array names ${package}_functions] foreach sig $functions { - ns_log Debug "checking sig '$total' against '$sig'" - if {$total == [expr $sig & $total]} { - ns_log Debug "Found match '$total' in '$sig'" - return [nsv_get ${package}_functions $sig] - } + ns_log Debug "checking sig '$total' against '$sig'" + if {$total == [expr $sig & $total]} { + ns_log Debug "Found match '$total' in '$sig'" + return [nsv_get ${package}_functions $sig] + } } return "!NO MATCH: $total not in $functions" -} + } -proc qd_write_query {package args} { + proc qd_write_query {package args} { set query [list] set attrs_and_defaults [eval qd_choose_function $package $args] foreach {attr default_value} $attrs_and_defaults { - if {[lsearch $args $attr] < 0 } { - if {[string match "" $default_value]} { - ns_log Debug "Attempt to call $package with no value for $attr" - return -code error - } - lappend query $default_value - } else { - lappend query ":${attr}" - } + if {[lsearch $args $attr] < 0 } { + if {[string match "" $default_value]} { + ns_log Debug "Attempt to call $package with no value for $attr" + return -code error + } + lappend query $default_value + } else { + lappend query ":${attr}" + } } return [join $query ",\n"] -} + } -proc qd_write_query_upvar {package listvar} { + proc qd_write_query_upvar {package listvar} { set query [list] upvar $listvar args set attrs_and_defaults [eval qd_choose_function $package $args] if {[string match "!NO MATCH:*" $attrs_and_defaults ]} { - ns_log Debug "$attrs_and_defaults" - return -code error + ns_log Debug "$attrs_and_defaults" + return -code error } foreach {attr default_value} $attrs_and_defaults { - if {[lsearch $args $attr] < 0 } { - if {[string match "" $default_value]} { - ns_log Debug "Attempt to call $package with no value for $attr" - return -code error - } - lappend query $default_value - } else { - lappend query ":${attr}" - } + if {[lsearch $args $attr] < 0 } { + if {[string match "" $default_value]} { + ns_log Debug "Attempt to call $package with no value for $attr" + return -code error + } + lappend query $default_value + } else { + lappend query ":${attr}" + } } return [join $query ",\n"] -} + } - - - } qd_add_package cronjob__new cronjob_id user_id description approved_p disabled_p minute hr mon day dayofweek run_sql run_tcl email creation_user creation_ip context_id qd_add_function cronjob__new "cronjob_id" "null" "user_id" "" "description" "" "approved_p" "'f'" "disabled_p" "'f'" "minute" "'0'" "hr" "'0'" "mon" "'0'" "day" "'0'" "dayofweek" "'0'" "run_sql" "" "run_tcl" "" "email" "" "creation_user" "null" "creation_ip" "null" "context_id" "null" - qd_add_package cronjob__set_attrs "cronjob_id" "user_id" "description" "approved_p" "disabled_p" "minute" "hr" "mon" "day" "dayofweek" "run_sql" "run_tcl" "email" qd_add_function cronjob__set_attrs "cronjob_id" "" "user_id" "null" "description" "null" "approved_p" "null" "disabled_p" "'f'" "minute" "null" "hr" "null" "mon" "null" "day" "null" "dayofweek" "null" "run_sql" "null" "run_tcl" "null" "email" "null" Index: openacs-4/packages/cronjob/tcl/cronjob-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/cronjob/tcl/cronjob-procs.tcl,v diff -u -r1.4 -r1.4.2.1 --- openacs-4/packages/cronjob/tcl/cronjob-procs.tcl 12 Sep 2002 22:44:25 -0000 1.4 +++ openacs-4/packages/cronjob/tcl/cronjob-procs.tcl 9 Oct 2002 00:26:21 -0000 1.4.2.1 @@ -13,33 +13,18 @@ } { - # setup the vars - set time [ns_time] - set minute [ns_fmttime $time %M] - set hr [ns_fmttime $time %H] - set mon [ns_fmttime $time %m] + # setup the vars + set time [ns_time] + set minute [ns_fmttime $time %M] + set hr [ns_fmttime $time %H] + set mon [ns_fmttime $time %m] set day [ns_fmttime $time %d] set dayofweek [ns_fmttime $time %w] - set sql " -select - cronjob_id -from - cronjobs -where - disabled_p = 'f' AND - approved_p = 't' AND - ((minute = :minute) OR (minute = '*')) AND - ((hr = :hr ) OR (hr = '*')) AND - ((mon = :mon ) OR (mon = '*')) AND - ((day = :day ) OR (day = '*')) AND - ((dayofweek = :dayofweek ) OR (dayofweek = '*'))" - - db_foreach cronjob_sched_foreach $sql { + db_foreach cronjob_sched_foreach "" { + ad_schedule_proc -once t -thread t 1 cronjob_run $cronjob_id + } - ad_schedule_proc -once t -thread t 1 cronjob_run $cronjob_id - } - } @@ -48,57 +33,47 @@ Proc to run cronjobs } { - set table "No SQL" - set sql " -select - description, - run_sql, - run_tcl, - email -from - cronjobs -where - cronjob_id = :cronjob_id" - ns_log Notice "Cronjob_id is $cronjob_id" - db_1row "crontab_query" $sql - db_release_unused_handles - if {![string match "" $run_sql]} { - set table "
[ns_set key $sel $i] | " - } - } - append table "
---|
[ns_set value $sel $i] | " - } - append table "
[ns_set key $sel $i] | " + } } + append table "
---|
[ns_set value $sel $i] | " + } + append table "