示例#1
0
文件: base.py 项目: HonzaKral/celery
    def __init__(self):
        if not hasattr(self, "run_every"):
            raise NotImplementedError(
                    "Periodic tasks must have a run_every attribute")

        # If run_every is a integer, convert it to timedelta seconds.
        # Operate on the original class attribute so anyone accessing
        # it directly gets the right value.
        if isinstance(self.__class__.run_every, int):
            self.__class__.run_every = timedelta(seconds=self.run_every)

        # Convert timedelta to instance of schedule.
        if isinstance(self.__class__.run_every, timedelta):
            self.__class__.run_every = schedule(self.__class__.run_every,
                                                self.relative)

        super(PeriodicTask, self).__init__()
    def __init__(self):
        if not hasattr(self, "run_every"):
            raise NotImplementedError(
                "Periodic tasks must have a run_every attribute")

        # If run_every is a integer, convert it to timedelta seconds.
        # Operate on the original class attribute so anyone accessing
        # it directly gets the right value.
        if isinstance(self.__class__.run_every, int):
            self.__class__.run_every = timedelta(seconds=self.run_every)

        # Convert timedelta to instance of schedule.
        if isinstance(self.__class__.run_every, timedelta):
            self.__class__.run_every = schedule(self.__class__.run_every,
                                                self.relative)

        super(PeriodicTask, self).__init__()
示例#3
0
from celery.decorators import task, periodic_task
from celery.task.schedules import crontab, schedule

from desio.utils import binder, adobe
from datetime import datetime, timedelta

import os.path, subprocess

@periodic_task(run_every=schedule(timedelta(seconds=60)))
def export_fireworks():
    from pylons import config
    conf = config.get
    
    uname = conf('extractor.username')
    pw = conf('extractor.password')
    host = conf('extractor.host')
    port = conf('extractor.port')
    
    print uname, pw, host, port
    
    ext = binder.FireworksExtractor(uname, pw, host=host, port=port)
    ext.run()

@periodic_task(run_every=schedule(timedelta(seconds=120)))
def check_fireworks():
    
    pid = adobe.Fireworks.get_pid()
    if not pid:
        print 'Not running, restarting...'
        adobe.Fireworks.restart()