Re: [web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
I ran one test and it did indeed stop the task. scheduler_run.status = 'STOPPED' scheduler_task.status = 'QUEUED' scheduler_worker.status = 'ACTIVE' return value from stop_task() was 1 So I got 'QUEUED' rather than 'FAILED' but that seems logical to me. My task function body was: def task_fabrun(cmdstring): while True: time.sleep(.5) # time in seconds return cmdstring Thanks. On Mon, Mar 11, 2013 at 6:16 PM, Niphlod niph...@gmail.com wrote: ps: docs pretty self-explanatory, however setting STOP_TASK on the scheduler_worker row will terminate the currently RUNNING task (if any) given myscheduler = Scheduler(db, ) in models, in your controller you can call actually_stopped = myscheduler.stop_task(15) that will terminate task with id 15, while with actually_stopped = myscheduler.stop_task('edeb8b54-dda8-4ff9-9585-2abb4a05c73a') will terminate task with uuid edeb8b54-dda8-4ff9-9585-2abb4a05c73a If the task is RUNNING it will be terminated -- execution will be set as FAILED by the worker as soon as the worker reads the STOP_TASK command (~3 secs), really_stopped will be 1 If the task is QUEUED, its stop_time will be set as to now, the enabled flag will be set to False, and the status will be set to STOPPED, really_stopped will be 1 If the task is on any other task status, even if the reference passed to stop_task() is legit, nothing will be done, really_stopped will be None -- --- You received this message because you are subscribed to a topic in the Google Groups web2py-users group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7-ZOS_In8IU/unsubscribe?hl=en. To unsubscribe from this group and all its topics, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
once the task is inserted you should not change it's values unless its in the QUEUED status (technically the ASSIGNED works too, but it's NOT recommended). there's no way for the scheduler to terminate a specific task once the task is started, unless you KILL the worker (setting the worker to TERMINATE will kill the worker as soon as the RUNNING task is finished). PS: if you need to execute a task n times, use the repeat argument. using time.sleep(something) in a task has the side-effect of NOT returning to the main loop to execute potentially new QUEUED tasks (every scheduler process is allowed to process a single task at a time). if you need to limit the time the task runs, use the timeout parameter. If something is not clear please ask. On Monday, March 11, 2013 8:04:52 PM UTC+1, dlypka wrote: I need a way to terminate a specific Scheduled Task while it is RUNNING. I tried using Admin Database Admin to update the scheduler_task.stop_time to a time close to now while it was running. But the task continued for several more minutes and COMPLETED its normal 5 minute run. The task calls time.sleep(300) to make it run for 5 minutes. I guess the Scheduler is not looking at the db values every 3 seconds. Is it just checking the in memory task object properties? Is there a way to update the in memory object properties of a task while it is running? Thanks. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
Thanks for the quick reply. I suppose a workaround is to have a separate worker for each task. The I can TERMINATE the worker. A suggestion: can you suggest some standard python scaffolding to include in each task function to make it listen for a kill signal / message? On Monday, March 11, 2013 3:05:21 PM UTC-5, Niphlod wrote: once the task is inserted you should not change it's values unless its in the QUEUED status (technically the ASSIGNED works too, but it's NOT recommended). there's no way for the scheduler to terminate a specific task once the task is started, unless you KILL the worker (setting the worker to TERMINATE will kill the worker as soon as the RUNNING task is finished). PS: if you need to execute a task n times, use the repeat argument. using time.sleep(something) in a task has the side-effect of NOT returning to the main loop to execute potentially new QUEUED tasks (every scheduler process is allowed to process a single task at a time). if you need to limit the time the task runs, use the timeout parameter. If something is not clear please ask. On Monday, March 11, 2013 8:04:52 PM UTC+1, dlypka wrote: I need a way to terminate a specific Scheduled Task while it is RUNNING. I tried using Admin Database Admin to update the scheduler_task.stop_time to a time close to now while it was running. But the task continued for several more minutes and COMPLETED its normal 5 minute run. The task calls time.sleep(300) to make it run for 5 minutes. I guess the Scheduler is not looking at the db values every 3 seconds. Is it just checking the in memory task object properties? Is there a way to update the in memory object properties of a task while it is running? Thanks. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
having a single worker for each task can be daunting (well, you could wrap web2py.py -K appname in a never-ending loop so it's restarted as soon as it gets killed) #!/bin/sh while true do web2py/web2py.py -K yourapp echo 'killed, restarting in a bit' sleep 2 done but I'm curious about your use-case. Why do you need to terminate a RUNNING task (that can't be accomplished using the timeout parameter)? On Monday, March 11, 2013 9:18:48 PM UTC+1, dlypka wrote: Thanks for the quick reply. I suppose a workaround is to have a separate worker for each task. The I can TERMINATE the worker. A suggestion: can you suggest some standard python scaffolding to include in each task function to make it listen for a kill signal / message? On Monday, March 11, 2013 3:05:21 PM UTC-5, Niphlod wrote: once the task is inserted you should not change it's values unless its in the QUEUED status (technically the ASSIGNED works too, but it's NOT recommended). there's no way for the scheduler to terminate a specific task once the task is started, unless you KILL the worker (setting the worker to TERMINATE will kill the worker as soon as the RUNNING task is finished). PS: if you need to execute a task n times, use the repeat argument. using time.sleep(something) in a task has the side-effect of NOT returning to the main loop to execute potentially new QUEUED tasks (every scheduler process is allowed to process a single task at a time). if you need to limit the time the task runs, use the timeout parameter. If something is not clear please ask. On Monday, March 11, 2013 8:04:52 PM UTC+1, dlypka wrote: I need a way to terminate a specific Scheduled Task while it is RUNNING. I tried using Admin Database Admin to update the scheduler_task.stop_time to a time close to now while it was running. But the task continued for several more minutes and COMPLETED its normal 5 minute run. The task calls time.sleep(300) to make it run for 5 minutes. I guess the Scheduler is not looking at the db values every 3 seconds. Is it just checking the in memory task object properties? Is there a way to update the in memory object properties of a task while it is running? Thanks. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
timeout does not handle the case where it is discovered that the task needs to be stopped ASAP due to a business condition. For example the remote server may have limited connections available so if a task runs into trouble, the process needs to be killed ASAP to release the precious remote connection. That is the case in my application. Even with a while loop, there will have to be a way get the win32 process id of the python task for a given worker so the right one can be killed. Looks like a better solution is for the task to have its own manager thread that can listen for kill requests. i.e. the scheduler tasks need to be written using a standard piece of scaffolding code to provide fine-grained task management. On Monday, March 11, 2013 3:27:35 PM UTC-5, Niphlod wrote: having a single worker for each task can be daunting (well, you could wrap web2py.py -K appname in a never-ending loop so it's restarted as soon as it gets killed) #!/bin/sh while true do web2py/web2py.py -K yourapp echo 'killed, restarting in a bit' sleep 2 done but I'm curious about your use-case. Why do you need to terminate a RUNNING task (that can't be accomplished using the timeout parameter)? On Monday, March 11, 2013 9:18:48 PM UTC+1, dlypka wrote: Thanks for the quick reply. I suppose a workaround is to have a separate worker for each task. The I can TERMINATE the worker. A suggestion: can you suggest some standard python scaffolding to include in each task function to make it listen for a kill signal / message? On Monday, March 11, 2013 3:05:21 PM UTC-5, Niphlod wrote: once the task is inserted you should not change it's values unless its in the QUEUED status (technically the ASSIGNED works too, but it's NOT recommended). there's no way for the scheduler to terminate a specific task once the task is started, unless you KILL the worker (setting the worker to TERMINATE will kill the worker as soon as the RUNNING task is finished). PS: if you need to execute a task n times, use the repeat argument. using time.sleep(something) in a task has the side-effect of NOT returning to the main loop to execute potentially new QUEUED tasks (every scheduler process is allowed to process a single task at a time). if you need to limit the time the task runs, use the timeout parameter. If something is not clear please ask. On Monday, March 11, 2013 8:04:52 PM UTC+1, dlypka wrote: I need a way to terminate a specific Scheduled Task while it is RUNNING. I tried using Admin Database Admin to update the scheduler_task.stop_time to a time close to now while it was running. But the task continued for several more minutes and COMPLETED its normal 5 minute run. The task calls time.sleep(300) to make it run for 5 minutes. I guess the Scheduler is not looking at the db values every 3 seconds. Is it just checking the in memory task object properties? Is there a way to update the in memory object properties of a task while it is running? Thanks. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
business condition like it seems a poor design to have a task, than watch it and if it hangs for some reason kill it abruptly not based on task started a while ago PS: are you on windows ? signal management on win poses a lot of limitations. On Monday, March 11, 2013 10:27:17 PM UTC+1, dlypka wrote: timeout does not handle the case where it is discovered that the task needs to be stopped ASAP due to a business condition. For example the remote server may have limited connections available so if a task runs into trouble, the process needs to be killed ASAP to release the precious remote connection. That is the case in my application. Even with a while loop, there will have to be a way get the win32 process id of the python task for a given worker so the right one can be killed. Looks like a better solution is for the task to have its own manager thread that can listen for kill requests. i.e. the scheduler tasks need to be written using a standard piece of scaffolding code to provide fine-grained task management. On Monday, March 11, 2013 3:27:35 PM UTC-5, Niphlod wrote: having a single worker for each task can be daunting (well, you could wrap web2py.py -K appname in a never-ending loop so it's restarted as soon as it gets killed) #!/bin/sh while true do web2py/web2py.py -K yourapp echo 'killed, restarting in a bit' sleep 2 done but I'm curious about your use-case. Why do you need to terminate a RUNNING task (that can't be accomplished using the timeout parameter)? On Monday, March 11, 2013 9:18:48 PM UTC+1, dlypka wrote: Thanks for the quick reply. I suppose a workaround is to have a separate worker for each task. The I can TERMINATE the worker. A suggestion: can you suggest some standard python scaffolding to include in each task function to make it listen for a kill signal / message? On Monday, March 11, 2013 3:05:21 PM UTC-5, Niphlod wrote: once the task is inserted you should not change it's values unless its in the QUEUED status (technically the ASSIGNED works too, but it's NOT recommended). there's no way for the scheduler to terminate a specific task once the task is started, unless you KILL the worker (setting the worker to TERMINATE will kill the worker as soon as the RUNNING task is finished). PS: if you need to execute a task n times, use the repeat argument. using time.sleep(something) in a task has the side-effect of NOT returning to the main loop to execute potentially new QUEUED tasks (every scheduler process is allowed to process a single task at a time). if you need to limit the time the task runs, use the timeout parameter. If something is not clear please ask. On Monday, March 11, 2013 8:04:52 PM UTC+1, dlypka wrote: I need a way to terminate a specific Scheduled Task while it is RUNNING. I tried using Admin Database Admin to update the scheduler_task.stop_time to a time close to now while it was running. But the task continued for several more minutes and COMPLETED its normal 5 minute run. The task calls time.sleep(300) to make it run for 5 minutes. I guess the Scheduler is not looking at the db values every 3 seconds. Is it just checking the in memory task object properties? Is there a way to update the in memory object properties of a task while it is running? Thanks. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
a supervsior may decide to kill a task started by one of his team members. On Mon, Mar 11, 2013 at 4:50 PM, Niphlod niph...@gmail.com wrote: business condition like it seems a poor design to have a task, than watch it and if it hangs for some reason kill it abruptly not based on task started a while ago PS: are you on windows ? signal management on win poses a lot of limitations. On Monday, March 11, 2013 10:27:17 PM UTC+1, dlypka wrote: timeout does not handle the case where it is discovered that the task needs to be stopped ASAP due to a business condition. For example the remote server may have limited connections available so if a task runs into trouble, the process needs to be killed ASAP to release the precious remote connection. That is the case in my application. Even with a while loop, there will have to be a way get the win32 process id of the python task for a given worker so the right one can be killed. Looks like a better solution is for the task to have its own manager thread that can listen for kill requests. i.e. the scheduler tasks need to be written using a standard piece of scaffolding code to provide fine-grained task management. On Monday, March 11, 2013 3:27:35 PM UTC-5, Niphlod wrote: having a single worker for each task can be daunting (well, you could wrap web2py.py -K appname in a never-ending loop so it's restarted as soon as it gets killed) #!/bin/sh while true do web2py/web2py.py -K yourapp echo 'killed, restarting in a bit' sleep 2 done but I'm curious about your use-case. Why do you need to terminate a RUNNING task (that can't be accomplished using the timeout parameter)? On Monday, March 11, 2013 9:18:48 PM UTC+1, dlypka wrote: Thanks for the quick reply. I suppose a workaround is to have a separate worker for each task. The I can TERMINATE the worker. A suggestion: can you suggest some standard python scaffolding to include in each task function to make it listen for a kill signal / message? On Monday, March 11, 2013 3:05:21 PM UTC-5, Niphlod wrote: once the task is inserted you should not change it's values unless its in the QUEUED status (technically the ASSIGNED works too, but it's NOT recommended). there's no way for the scheduler to terminate a specific task once the task is started, unless you KILL the worker (setting the worker to TERMINATE will kill the worker as soon as the RUNNING task is finished). PS: if you need to execute a task n times, use the repeat argument. using time.sleep(something) in a task has the side-effect of NOT returning to the main loop to execute potentially new QUEUED tasks (every scheduler process is allowed to process a single task at a time). if you need to limit the time the task runs, use the timeout parameter. If something is not clear please ask. On Monday, March 11, 2013 8:04:52 PM UTC+1, dlypka wrote: I need a way to terminate a specific Scheduled Task while it is RUNNING. I tried using Admin Database Admin to update the scheduler_task.stop_time to a time close to now while it was running. But the task continued for several more minutes and COMPLETED its normal 5 minute run. The task calls time.sleep(300) to make it run for 5 minutes. I guess the Scheduler is not looking at the db values every 3 seconds. Is it just checking the in memory task object properties? Is there a way to update the in memory object properties of a task while it is running? Thanks. -- --- You received this message because you are subscribed to a topic in the Google Groups web2py-users group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7-ZOS_In8IU/unsubscribe?hl=en. To unsubscribe from this group and all its topics, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
ok, seems more a goal of a workflow engine than a task queue, but I'll see what can be done. On Monday, March 11, 2013 10:54:10 PM UTC+1, dlypka wrote: a supervsior may decide to kill a task started by one of his team members. On Mon, Mar 11, 2013 at 4:50 PM, Niphlod nip...@gmail.com javascript:wrote: business condition like it seems a poor design to have a task, than watch it and if it hangs for some reason kill it abruptly not based on task started a while ago PS: are you on windows ? signal management on win poses a lot of limitations. On Monday, March 11, 2013 10:27:17 PM UTC+1, dlypka wrote: timeout does not handle the case where it is discovered that the task needs to be stopped ASAP due to a business condition. For example the remote server may have limited connections available so if a task runs into trouble, the process needs to be killed ASAP to release the precious remote connection. That is the case in my application. Even with a while loop, there will have to be a way get the win32 process id of the python task for a given worker so the right one can be killed. Looks like a better solution is for the task to have its own manager thread that can listen for kill requests. i.e. the scheduler tasks need to be written using a standard piece of scaffolding code to provide fine-grained task management. On Monday, March 11, 2013 3:27:35 PM UTC-5, Niphlod wrote: having a single worker for each task can be daunting (well, you could wrap web2py.py -K appname in a never-ending loop so it's restarted as soon as it gets killed) #!/bin/sh while true do web2py/web2py.py -K yourapp echo 'killed, restarting in a bit' sleep 2 done but I'm curious about your use-case. Why do you need to terminate a RUNNING task (that can't be accomplished using the timeout parameter)? On Monday, March 11, 2013 9:18:48 PM UTC+1, dlypka wrote: Thanks for the quick reply. I suppose a workaround is to have a separate worker for each task. The I can TERMINATE the worker. A suggestion: can you suggest some standard python scaffolding to include in each task function to make it listen for a kill signal / message? On Monday, March 11, 2013 3:05:21 PM UTC-5, Niphlod wrote: once the task is inserted you should not change it's values unless its in the QUEUED status (technically the ASSIGNED works too, but it's NOT recommended). there's no way for the scheduler to terminate a specific task once the task is started, unless you KILL the worker (setting the worker to TERMINATE will kill the worker as soon as the RUNNING task is finished). PS: if you need to execute a task n times, use the repeat argument. using time.sleep(something) in a task has the side-effect of NOT returning to the main loop to execute potentially new QUEUED tasks (every scheduler process is allowed to process a single task at a time). if you need to limit the time the task runs, use the timeout parameter. If something is not clear please ask. On Monday, March 11, 2013 8:04:52 PM UTC+1, dlypka wrote: I need a way to terminate a specific Scheduled Task while it is RUNNING. I tried using Admin Database Admin to update the scheduler_task.stop_time to a time close to now while it was running. But the task continued for several more minutes and COMPLETED its normal 5 minute run. The task calls time.sleep(300) to make it run for 5 minutes. I guess the Scheduler is not looking at the db values every 3 seconds. Is it just checking the in memory task object properties? Is there a way to update the in memory object properties of a task while it is running? Thanks. -- --- You received this message because you are subscribed to a topic in the Google Groups web2py-users group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7-ZOS_In8IU/unsubscribe?hl=en. To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
Well the functions to terminate will still have be manually initiated by an operator clicking a button. And no workflow type of suspending / resuming a long running task is needed. And no workflow designer and no workflow Activity classes such as State Activities needed. Managers just need to know the tasks can be terminated anytime. Meanwhile I am installing my Scheduler app on the corporate server tonight and the Manager will be pleased will what it does so far. Thanks. On Monday, March 11, 2013 4:58:38 PM UTC-5, Niphlod wrote: ok, seems more a goal of a workflow engine than a task queue, but I'll see what can be done. On Monday, March 11, 2013 10:54:10 PM UTC+1, dlypka wrote: a supervsior may decide to kill a task started by one of his team members. On Mon, Mar 11, 2013 at 4:50 PM, Niphlod nip...@gmail.com wrote: business condition like it seems a poor design to have a task, than watch it and if it hangs for some reason kill it abruptly not based on task started a while ago PS: are you on windows ? signal management on win poses a lot of limitations. On Monday, March 11, 2013 10:27:17 PM UTC+1, dlypka wrote: timeout does not handle the case where it is discovered that the task needs to be stopped ASAP due to a business condition. For example the remote server may have limited connections available so if a task runs into trouble, the process needs to be killed ASAP to release the precious remote connection. That is the case in my application. Even with a while loop, there will have to be a way get the win32 process id of the python task for a given worker so the right one can be killed. Looks like a better solution is for the task to have its own manager thread that can listen for kill requests. i.e. the scheduler tasks need to be written using a standard piece of scaffolding code to provide fine-grained task management. On Monday, March 11, 2013 3:27:35 PM UTC-5, Niphlod wrote: having a single worker for each task can be daunting (well, you could wrap web2py.py -K appname in a never-ending loop so it's restarted as soon as it gets killed) #!/bin/sh while true do web2py/web2py.py -K yourapp echo 'killed, restarting in a bit' sleep 2 done but I'm curious about your use-case. Why do you need to terminate a RUNNING task (that can't be accomplished using the timeout parameter)? On Monday, March 11, 2013 9:18:48 PM UTC+1, dlypka wrote: Thanks for the quick reply. I suppose a workaround is to have a separate worker for each task. The I can TERMINATE the worker. A suggestion: can you suggest some standard python scaffolding to include in each task function to make it listen for a kill signal / message? On Monday, March 11, 2013 3:05:21 PM UTC-5, Niphlod wrote: once the task is inserted you should not change it's values unless its in the QUEUED status (technically the ASSIGNED works too, but it's NOT recommended). there's no way for the scheduler to terminate a specific task once the task is started, unless you KILL the worker (setting the worker to TERMINATE will kill the worker as soon as the RUNNING task is finished). PS: if you need to execute a task n times, use the repeat argument. using time.sleep(something) in a task has the side-effect of NOT returning to the main loop to execute potentially new QUEUED tasks (every scheduler process is allowed to process a single task at a time). if you need to limit the time the task runs, use the timeout parameter. If something is not clear please ask. On Monday, March 11, 2013 8:04:52 PM UTC+1, dlypka wrote: I need a way to terminate a specific Scheduled Task while it is RUNNING. I tried using Admin Database Admin to update the scheduler_task.stop_time to a time close to now while it was running. But the task continued for several more minutes and COMPLETED its normal 5 minute run. The task calls time.sleep(300) to make it run for 5 minutes. I guess the Scheduler is not looking at the db values every 3 seconds. Is it just checking the in memory task object properties? Is there a way to update the in memory object properties of a task while it is running? Thanks. -- --- You received this message because you are subscribed to a topic in the Google Groups web2py-users group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7-ZOS_In8IU/unsubscribe?hl=en. To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
Wow. That will be nice. Thanks. On Mon, Mar 11, 2013 at 5:28 PM, Niphlod niph...@gmail.com wrote: PS: the task will end in FAILED status -- --- You received this message because you are subscribed to a topic in the Google Groups web2py-users group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7-ZOS_In8IU/unsubscribe?hl=en. To unsubscribe from this group and all its topics, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
please test it (trunk version). I'm sending a patch to Massimo to include it in trunk. On Monday, March 11, 2013 11:35:23 PM UTC+1, dlypka wrote: Wow. That will be nice. Thanks. On Mon, Mar 11, 2013 at 5:28 PM, Niphlod nip...@gmail.com javascript:wrote: PS: the task will end in FAILED status -- --- You received this message because you are subscribed to a topic in the Google Groups web2py-users group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7-ZOS_In8IU/unsubscribe?hl=en. To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. #!/usr/bin/env python # -*- coding: utf-8 -*- USAGE = ## Example For any existing app Create File: app/models/scheduler.py == from gluon.scheduler import Scheduler def demo1(*args,**vars): print 'you passed args=%s and vars=%s' % (args, vars) return 'done!' def demo2(): 1/0 scheduler = Scheduler(db,dict(demo1=demo1,demo2=demo2)) ## run worker nodes with: cd web2py python web2py.py -K myapp or python gluon/scheduler.py -u sqlite://storage.sqlite \ -f applications/myapp/databases/ \ -t mytasks.py (-h for info) python scheduler.py -h ## schedule jobs using http://127.0.0.1:8000/myapp/appadmin/insert/db/scheduler_task ## monitor scheduled jobs http://127.0.0.1:8000/myapp/appadmin/select/db?query=db.scheduler_task.id0 ## view completed jobs http://127.0.0.1:8000/myapp/appadmin/select/db?query=db.scheduler_run.id0 ## view workers http://127.0.0.1:8000/myapp/appadmin/select/db?query=db.scheduler_worker.id0 ## To install the scheduler as a permanent daemon on Linux (w/ Upstart), put ## the following into /etc/init/web2py-scheduler.conf: ## (This assumes your web2py instance is installed in user's home directory, ## running as user, with app myapp, on network interface eth0.) description web2py task scheduler start on (local-filesystems and net-device-up IFACE=eth0) stop on shutdown respawn limit 8 60 # Give up if restart occurs 8 times in 60 seconds. exec sudo -u user python /home/user/web2py/web2py.py -K myapp respawn ## You can then start/stop/restart/check status of the daemon with: sudo start web2py-scheduler sudo stop web2py-scheduler sudo restart web2py-scheduler sudo status web2py-scheduler import os import time import multiprocessing import sys import threading import traceback import signal import socket import datetime import logging import optparse import types import Queue if 'WEB2PY_PATH' in os.environ: sys.path.append(os.environ['WEB2PY_PATH']) else: os.environ['WEB2PY_PATH'] = os.getcwd() if not os.environ['WEB2PY_PATH'] in sys.path: sys.path.append(os.environ['WEB2PY_PATH']) try: from gluon.contrib.simplejson import loads, dumps except: from simplejson import loads, dumps IDENTIFIER = %s#%s % (socket.gethostname(),os.getpid()) logger = logging.getLogger('web2py.scheduler.%s' % IDENTIFIER) from gluon import DAL, Field, IS_NOT_EMPTY, IS_IN_SET, IS_NOT_IN_DB, IS_INT_IN_RANGE, IS_DATETIME from gluon.utils import web2py_uuid from gluon.storage import Storage QUEUED = 'QUEUED' ASSIGNED = 'ASSIGNED' RUNNING = 'RUNNING' COMPLETED = 'COMPLETED' FAILED = 'FAILED' TIMEOUT = 'TIMEOUT' STOPPED = 'STOPPED' ACTIVE = 'ACTIVE' TERMINATE = 'TERMINATE' DISABLED = 'DISABLED' KILL = 'KILL' PICK = 'PICK' STOP_TASK = 'STOP_TASK' EXPIRED = 'EXPIRED' SECONDS = 1 HEARTBEAT = 3 * SECONDS MAXHIBERNATION = 10 CLEAROUT = '!clear!' CALLABLETYPES = (types.LambdaType, types.FunctionType, types.BuiltinFunctionType, types.MethodType, types.BuiltinMethodType) class Task(object): def __init__(self, app, function, timeout, args='[]', vars='{}', **kwargs): logger.debug(' new task allocated: %s.%s', app, function) self.app = app self.function = function self.timeout = timeout self.args = args # json self.vars = vars # json self.__dict__.update(kwargs) def __str__(self): return 'Task: %s' % self.function class TaskReport(object): def __init__(self, status, result=None, output=None, tb=None): logger.debug('new task report: %s', status) if tb: logger.debug(' traceback: %s', tb) else: logger.debug(' result: %s', result) self.status = status self.result = result self.output = output self.tb = tb def __str__(self): return 'TaskReport: %s' % self.status def demo_function(*argv, **kwargs):
Re: [web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
ps: docs pretty self-explanatory, however setting STOP_TASK on the scheduler_worker row will terminate the currently RUNNING task (if any) given myscheduler = Scheduler(db, ) in models, in your controller you can call actually_stopped = myscheduler.stop_task(15) that will terminate task with id 15, while with actually_stopped = myscheduler.stop_task('edeb8b54-dda8-4ff9-9585-2abb4a05c73a') will terminate task with uuid edeb8b54-dda8-4ff9-9585-2abb4a05c73a If the task is RUNNING it will be terminated -- execution will be set as FAILED by the worker as soon as the worker reads the STOP_TASK command (~3 secs), really_stopped will be 1 If the task is QUEUED, its stop_time will be set as to now, the enabled flag will be set to False, and the status will be set to STOPPED, really_stopped will be 1 If the task is on any other task status, even if the reference passed to stop_task() is legit, nothing will be done, really_stopped will be None -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: How to TERMINATE a RUNNING Scheduler Task?
OK will test it later tonight. Thanks. On Mon, Mar 11, 2013 at 6:01 PM, Niphlod niph...@gmail.com wrote: please test it (trunk version). I'm sending a patch to Massimo to include it in trunk. On Monday, March 11, 2013 11:35:23 PM UTC+1, dlypka wrote: Wow. That will be nice. Thanks. On Mon, Mar 11, 2013 at 5:28 PM, Niphlod nip...@gmail.com wrote: PS: the task will end in FAILED status -- --- You received this message because you are subscribed to a topic in the Google Groups web2py-users group. To unsubscribe from this topic, visit https://groups.google.com/d/** topic/web2py/7-ZOS_In8IU/**unsubscribe?hl=enhttps://groups.google.com/d/topic/web2py/7-ZOS_In8IU/unsubscribe?hl=en . To unsubscribe from this group and all its topics, send an email to web2py+un...@**googlegroups.com. For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out . -- --- You received this message because you are subscribed to a topic in the Google Groups web2py-users group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7-ZOS_In8IU/unsubscribe?hl=en. To unsubscribe from this group and all its topics, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.