|
@@ -33,7 +33,7 @@ def load_tasks(): |
|
|
def load_class_from_file(f): |
|
|
def load_class_from_file(f): |
|
|
"""Look in a given file for the task class.""" |
|
|
"""Look in a given file for the task class.""" |
|
|
global task_list |
|
|
global task_list |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module = f[:-3] # strip .py from end |
|
|
module = f[:-3] # strip .py from end |
|
|
try: |
|
|
try: |
|
|
exec "from wiki.tasks import %s as m" % module |
|
|
exec "from wiki.tasks import %s as m" % module |
|
@@ -42,13 +42,13 @@ def load_class_from_file(f): |
|
|
traceback.print_exc() |
|
|
traceback.print_exc() |
|
|
return |
|
|
return |
|
|
try: |
|
|
try: |
|
|
task_class = m.Task() |
|
|
|
|
|
|
|
|
task_class = m.Task |
|
|
except: |
|
|
except: |
|
|
print "Couldn't find or get task class in file %s:" % f |
|
|
print "Couldn't find or get task class in file %s:" % f |
|
|
traceback.print_exc() |
|
|
traceback.print_exc() |
|
|
return |
|
|
return |
|
|
task_name = task_class.task_name |
|
|
task_name = task_class.task_name |
|
|
task_list[task_name] = task_class |
|
|
|
|
|
|
|
|
task_list[task_name] = task_class() |
|
|
print "Added task %s from wiki/tasks/%s..." % (task_name, f) |
|
|
print "Added task %s from wiki/tasks/%s..." % (task_name, f) |
|
|
|
|
|
|
|
|
def start_tasks(now=time.gmtime()): |
|
|
def start_tasks(now=time.gmtime()): |
|
@@ -70,13 +70,11 @@ def start_task(task_name, **kwargs): |
|
|
try: |
|
|
try: |
|
|
task = task_list[task_name] |
|
|
task = task_list[task_name] |
|
|
except KeyError: |
|
|
except KeyError: |
|
|
print ("Couldn't find task '{0}': wiki/tasks/{1}.py does not " + |
|
|
|
|
|
"exist.").format(task_name, task_name) |
|
|
|
|
|
|
|
|
print ("Couldn't find task '{0}': wiki/tasks/{0}.py does not exist.").format(task_name) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
task_thread = threading.Thread(target=lambda: task_wrapper(task, **kwargs)) |
|
|
|
|
|
task_thread.name = "{0} ({1})".format(task_name, time.strftime( |
|
|
|
|
|
"%b %d %H:%M:%S")) |
|
|
|
|
|
|
|
|
task_thread = threading.Thread(target=lambda: task_wrapper(task, **kwargs)) |
|
|
|
|
|
task_thread.name = "{0} ({1})".format(task_name, time.strftime("%b %d %H:%M:%S")) |
|
|
|
|
|
|
|
|
# stop bot task threads automagically if the main bot stops |
|
|
# stop bot task threads automagically if the main bot stops |
|
|
task_thread.daemon = True |
|
|
task_thread.daemon = True |
|
@@ -88,8 +86,7 @@ def task_wrapper(task, **kwargs): |
|
|
try: |
|
|
try: |
|
|
task.run(**kwargs) |
|
|
task.run(**kwargs) |
|
|
except: |
|
|
except: |
|
|
print "Task '{0}' raised an exception and had to stop:".format( |
|
|
|
|
|
task.task_name) |
|
|
|
|
|
|
|
|
print "Task '{0}' raised an exception and had to stop:".format(task.task_name) |
|
|
traceback.print_exc() |
|
|
traceback.print_exc() |
|
|
else: |
|
|
else: |
|
|
print "Task '{0}' finished without error.".format(task.task_name) |
|
|
print "Task '{0}' finished without error.".format(task.task_name) |