0

I have a create a decorator as below,

sc_status = True
class schedule_stop_dec(object):
    def __init__(self, dec, condition):
        self.decorator = dec
        self.condition = condition

    def __call__(self, func):
        if not self.condition:
            # Return the function unchanged, not decorated.
            return func
        return self.decorator(func) 

#@periodic_task(run_every=crontab(hour=7, minute=10, day_of_week=1)
@schedule_stop_dec(periodic_task(run_every=crontab(hour=7, minute=10, day_of_week=1)), sc_status)
def delete_inactive_task():
    logger.log('Function triggered')

In the above code If i directly use the decorator @periodic_task then when it reaches the specified time function delete_inactive_task() gets triggered properlly,

But When i use scheduled_stop_dec with sc_status = True then in log I get the below message as if it gets triggered but in actual log if i check 'Function triggered' message is not there

[2017-03-30 10:10:00,000: INFO/MainProcess] Scheduler: Sending due task octopus.tasks.schedule_stop.delete_inactive_task (octopus.tasks.schedule_stop.delet                               e_inactive_task)

Please let me know how can I control the #periodic_task decorator with specified flag.

I have tried above example using example "how to do a conditional decorator in python 2.6"

Community
  • 1
  • 1
Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59

0 Answers0