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 に答える