diff --git a/webnotes/utils/scheduler.py b/webnotes/utils/scheduler.py index c99b81c3bb..7a00334692 100644 --- a/webnotes/utils/scheduler.py +++ b/webnotes/utils/scheduler.py @@ -52,14 +52,19 @@ def execute(): out = [] - # if first task of the day execute daily tasks nowtime = webnotes.utils.now_datetime() last = webnotes.conn.get_global('scheduler_last_event') + + # set scheduler last event + webnotes.conn.begin() + webnotes.conn.set_global('scheduler_last_event', nowtime.strftime(format)) + webnotes.conn.commit() + if last: last = datetime.strptime(last, format) if nowtime.day != last.day: - + # if first task of the day execute daily tasks out.append('daily:' + trigger('execute_daily')) if nowtime.month != last.month: @@ -73,10 +78,6 @@ def execute(): out.append('all:' + trigger('execute_all')) - webnotes.conn.begin() - webnotes.conn.set_global('scheduler_last_event', nowtime.strftime(format)) - webnotes.conn.commit() - return '\n'.join(out) def trigger(method): @@ -90,7 +91,7 @@ def trigger(method): webnotes.conn.commit() return 'ok' - except Exception, e: + except Exception: return log(method) def log(method):