2

我在让 Heroku 上的 APScheduler 进程与 Django 环境一起工作时遇到问题。

我所做的是创建一个管理命令,以便我的 apscheduler 作业可以访问我的 Django 环境。

应用程序名称/管理/命令/scheduler.py

class Command(BaseCommand):
  """
  Management command for APScheduler
  """

  def handle(self, *args, **kwargs):
    sched = Scheduler()

    @sched.cron_schedule(day_of_week='mon-sun', hour=0, minute=0)
    def a_weekly_job():
      run_some_code()

    sched.start()
    print "Scheduler started"

    while True:
      pass

我将我的 Procfile 设置为以下(用于调度程序进程)

scheduler: python manage.py scheduler

但是,当我使用调度程序进程部署我的应用程序时,我收到以下警告消息并且我的作业没有运行:

WARNING:apscheduler.scheduler:Run time of job "a_weekly_job" (trigger: cron[day_of_week='mon-sun', hour='23', minute='25'], next run at: 2013-09-24 23:25:00)" was missed by 0:00:07.261174

我如何让工作运行?

4

2 回答 2

0

添加clock.py文件:

sched = Scheduler()

@sched.cron_schedule(day_of_week='mon-sun', hour=0, minute=0)
def a_weekly_job():
  run_some_code()

sched.start()
print "Scheduler started"

while __name__ == '__main__':
  pass

档案:

web: ...
clock: python clock.py --loglevel=INFO
于 2013-09-26T11:14:44.580 回答
-1

使用子进程运行“python manage.py scheduler”:

import subprocess
from apscheduler.schedulers.blocking import BlockingScheduler

sched = BlockingScheduler()

@sched.scheduled_job('cron', day_of_week='mon-sun', hour=0, minute=0)
def scheduler_sample():
    subprocess.call('python manage.py scheduler'), shell=True, close_fds=True)

sched.start()
于 2015-10-06T21:45:47.367 回答