0

我有一个如下创建装饰器,

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')

在上面的代码中,如果我直接使用装饰器@periodic_task,那么当它到达指定的时间时,函数 delete_inactive_task() 会被正确触发,

但是当我使用 schedule_stop_dec 和 sc_status = True 然后在日志中我得到以下消息,好像它被触发但在实际日志中如果我检查'功能触发'消息不存在

[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)

请让我知道如何使用指定的标志控制 #periodic_task 装饰器。

我已经使用示例“如何在 python 2.6 中执行条件装饰器”尝试了上面的示例

4

0 回答 0