Forum OpenACS Development: Modify function and parameters called by .init function

Good evening.

I'm sorry if the question is easy but I loss a week to find a solution and my script continue to don't work correctly.

In a package I defined a parameter with a value and I insert in the .init file a function (function A) that I need to be executed every day. This function read from database the elements of a table and then call one other function (function B).

The function A execute regularly its task every day. After the first day I found one error in the function B so I modified it and I add this function to watch files. But the function A continue to execute the previous version. I tried to change also the parameter but also in this situation the function continue to see the old value.

Today I tried to call the function B by a normal page and it execute correctly what I'd like but when the function A call it it's ever the first version that it's executed.

I tried to re-start AOL server and the PC but I continue to see the same problem.

Can you please help me? how I can clean this "cache" and execute the real function B with the correct parameter?

Thank you a lot for any help.

Best regards,

Andrea Tosoni

Andrea Tosoni,

In addition to new parameters in the .info file, I believe the init procedures are only re-loaded on install or upgrade. Scheduled procedures have a similar requirement (bug. See https://openacs.org/forums/message-view?message_id=324185 ).

Try increasing the package version in the .info file and upgrading it (followed by restart).

cheers,

Torben

Collapse
Posted by Jim Lynch on
Probably it would be good to see the def of A and B and show how you're scheculing the once-a-day thing.

Main question I have, is, is the code for the old B in any file? Are the parameters the new B and the old B take are unchanged?

Collapse
Posted by Jim Lynch on
Oh, and, are these functions tcl, xotcl, pl/sql or somethinhg else?
Hello.

Yesterday I tried to change the version of package and then restart the server but all continue to work as before.

This what I add to -init.tcl function to repeat a task:

ad_schedule_proc \
-schedule_proc ns_schedule_daily \
[list 0 0] im_daily_repetitive_task

The im_daily_repetitive_task function is:

set comando "select id_delay, script, document_id
from im_delayed_tasks, im_categories
where category='Daily' and
category_id=period;"

set toDel [list]
db_foreach del_task $comando {

set aggiorna "${script} -id ${document_id}"
set cancella [eval $aggiorna]
if {$cancella == 1} {
lappend toDel $id_delay
}
}

foreach elem $toDel {

db_dml delElement \
"delete from im_delayed_tasks
where id_delay=${elem};"
}

This function is a -proc.tcl that I inserted in the watch. It take from database all elements in a table and call the function (script) the the element (document_id).

This is the function called:

set numMaxDays [ad_parameter -package_id \
[im_package_invoices_id] \
MaxDelayOfBillFromPO "" 0]

if {$numMaxDays == 0} {
return 0
}

set comando \
"select date_part('day', now() - effective_date) as curDelay
from im_costs
where cost_id=${id};"
set curDays [db_string calcCurDelay $comando -default 0]

set comando "select id_bill from im_link_orders_bills where id_order=${id};"
set id_bill [db_string findBill $comando -default ""]

if {$id_bill == ""} {

if {$numMaxDays < $curDays} {

set comando \
"update im_link_orders_bills set overlimit='t'
where id_order=${id};"
db_dml modOrder $comando

return 1

} else {

return 0
}

} else {

return 1
}

This function is a -proc.tcl file of one other package. I tested this function and it execute how I like but the previous function continue to see the old version of this function where (for example) I forgot "where id_order=${id}" clause.

How you see all code is tcl. Only the name of first function is in the database (but just the name, not the body). The parameter is a parameter of package.

I thought to put all (code and parameter) in the database so the command that I add in the -init.tcl file read directly what it have to execute. Maybe so can execute what I like.

Thank you very much for your help.

Best regards,

Andrea

Collapse
Posted by Dave Bauer on
Using "reload" or "watch" from the APM will not reload the procedure in any scheduled procedure threads.

To reload the definition of a tcl procedure you must restart the AOLserver.

Alternatively you can re-source the file using ns_eval using the developer support shell something like this

ns_eval {source [acs_root_dir]/packages/package-key/tcl/my-procs.tcl}

(Someone should really fix the reload procedures to use this, I am pretty sure this works reliably for the last few years.)

If you have restarted the AOLserver make sure you stop the AOLserver process and restart it. If you do not, the second AOLserver will not be able to bind to the IP address and will exit. Watch the error log to make sure AOLserver stops and restarts.

Thank you!

I reloaded the two -proc.tcl scripts and now it execute correctly the my code.

Exists-it a similar way to re-load the parameters?

Thank you again.

Best regards,

Andrea