APScheduler 作业未按计划执行

时间:2020-12-22 09:39:08

标签: python django gunicorn supervisord apscheduler

我正在尝试使用 gunicorn 和 supervisord 运行 apscheduler。没有 gunicorn,apscheduler 可以工作,但有时使用 gunicorn,apscheduler 不起作用。除了apscheduler,其他项目正在运行。 我正在使用以下命令使用 gunicorn 运行

/home/ubuntu/project/project_folder/venv/bin/gunicorn project.wsgi:application --timeout 120 --workers 2 --threads=3 --bind=0.0.0.0:2732

在 settings.py 文件中

from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.redis import RedisJobStore
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor

logging.basicConfig(filename='logs/scheduler', level=logging.DEBUG,format='[%(asctime)s]: %(levelname)s : %(message)s')
logging.getLogger('apscheduler').setLevel(logging.DEBUG)

# scheduler = BackgroundScheduler(misfire_grace_time=20, executors=executors)

scheduler = BackgroundScheduler({'apscheduler.timezone': 'Asia/Calcutta'},job_defaults={'misfire_grace_time': None})
scheduler.add_jobstore(RedisJobStore(jobs_key='dev-jobs', run_times_key='dev_all_run_times'), 'redis')
scheduler.start()

并将views.py文件中的作业设置为

start_date_of_job = model_object.start_date
start_time = dates.strptime(model_object.start_time, '%I.%M %p').time()
start_datetime_of_job = dates.combine(start_date_of_job, start_time)
settings.scheduler.add_job(function_to_run, 'date', jobstore='redis', replace_existing=True,
    run_date=start_datetime_of_job, misfire_grace_time=None,
    id="start-" + str(model_object.id),
    args=[args list])

有时有效,有时无效。

0 个答案:

没有答案
相关问题