RQScheduler是一个小型的Pytho包,用来给RQ添加作业调度功能。
安装:
pip istall rq-scheduler示例代码:
from redis import Redisfrom rq_scheduler import Schedulerfrom datetime import datetimescheduler = Scheduler(coectio=Redis()) # Get a scheduler for the "default" queue# Puts a job ito the scheduler. The API is similar to RQ except that it# takes a datetime object as first argumet. So for example to schedule a# job to ru o Ja 1st 2020 we do:scheduler.equeue_at(datetime(2020, 1, 1), fuc)# Here's aother example schedulig a job to ru at a specific date ad time (i UTC),# complete with args ad kwargs.scheduler.equeue_at(datetime(2020, 1, 1, 3, 4), fuc, foo, bar=baz)第二种方法:
from datetime import timedelta# Schedule a job to ru 10 miutes, 1 hour ad 1 day laterscheduler.equeue_i(timedelta(miutes=10), cout_retweets, tweet_id)scheduler.equeue_i(timedelta(hours=1), cout_retweets, tweet_id)scheduler.equeue_i(timedelta(days=1), cout_retweets, tweet_id)
评论