[FR] allow unregistering a scheduled task in the Scheduler Plugin

Skip to first unread message

Luís Martinho

Jun 3, 2011, 1:01:28 PM6/3/11
to colony...@googlegroups.com
AFAIK there is no support for unregistering a scheduled task in Scheduler Plugin (pt.hive.colony.plugins.misc.scheduler).

It would be awesome if I could unregister a scheduled task after I had registered it (through some kind of handle or identifier).

Why this means a lot to me: I have a plugin which registers a self-update task when it loads. Whenever I update the plugin and it reloads, it registers a new task.
After some time working on the plugin, I have a bunch of tasks doing the same thing and eating up CPU for no reason.

João Magalhães

Jun 3, 2011, 6:56:03 PM6/3/11
to colony...@googlegroups.com
I will take care of that.

João Magalhães

Jun 6, 2011, 8:23:08 AM6/6/11
to colony...@googlegroups.com
You can now (since commit 14605) cancel tasks by using unregister_task method from the facade of the pt.hive.colony.plugins.misc.scheduler plugin.
The first and only argument is the task structure.

Here goes a simple example of the unregister task usage.

import time

def task():
    print "Hello World"

scheduler_plugin = plugin_manager.get_plugin_by_id("pt.hive.colony.plugins.misc.scheduler")

current_time = time.time()
task_class = scheduler_plugin.get_task_class()

task_arguments = {}
task_arguments["method"] = task
task_arguments["method_arguments"] = []

build_automation_task = task_class("method_call", task_arguments)
scheduler_plugin.register_task_absolute(build_automation_task, current_time + 5)

Reply all
Reply to author
0 new messages