我有两种类型的作业:一种是连续运行的,另一种是并行运行的。但是,我希望并行作业按顺序安排(如果您还在跟踪的话)。这就是:
我认为它有两个redis队列,一个只有一个工作人员的serial_queue。还有一个parallel_queue,上面有多个工作人员。
serial_queue.schedule(
scheduled_time=datetime.utcnow(),
func=job_a,
...)
serial_queue.schedule(
scheduled_time=datetime.utcnow(),
func=job_b,
...)
def parallel_c():
for task in range(args.n_tasks):
queue_concurrent.schedule(
scheduled_time=datetime.utcnow(),
func=job_c,
...)
serial_queue.schedule(
scheduled_time=datetime.utcnow(),
func=parallel_c,
...)但是目前这个设置给出了AttributeError: module '__main__' has no attribute 'schedule_fetch_tweets'的错误。如何为python-rq正确地打包此函数
发布于 2018-08-27 22:17:57
解决方案需要一些体操,因为您必须导入当前脚本,就好像它是一个外部模块一样。
举个例子。schedule_twitter_jobs.py的内容如下:
from redis import Redis
from rq_scheduler import Scheduler
import schedule_twitter_jobs
# we are importing the very module we are executing
def schedule_fetch_tweets(args, queue_name):
''' This is the child process to schedule'''
concurrent_queue = Scheduler(queue_name=queue_name+'_concurrent', connection=Redis())
# this scheduler is created based on a queue_name that will be passed in
for task in range(args.n_tasks):
scheduler_concurrent.schedule(
scheduled_time=datetime.utcnow(),
func=app.controller.fetch_twitter_tweets,
args=[args.statuses_backfill, fill_start_time])
serial_queue = Scheduler(queue_name='myqueue', connection=Redis())
serial_queue.schedule(
'''This is the first schedule.'''
scheduled_time=datetime.utcnow(),
func=schedule_twitter_jobs.schedule_fetch_tweets,
#now we have a fully-qualified reference to the function we need to schedule.
args=(args, ttl, timeout, queue_name)
#pass through the args to the child schedule
)https://stackoverflow.com/questions/52045496
复制相似问题