计划一个redis作业,该作业使用pythonrq计划另一个redis作业

计划一个redis作业,该作业使用pythonrq计划另一个redis作业,python,redis,python-rq,Python,Redis,Python Rq,我有两种作业:一种是串行运行,另一种是并行并发运行。但是,我希望并行作业以串行方式进行调度(如果您仍在跟踪)。即: 做A 等A,做B 等待B,同时执行2个以上版本的C 我认为它有两个redis队列,一个只有一个工人的串行队列。和一个并行队列,其中有多个工作队列 serial_queue.schedule( scheduled_time=datetime.utcnow(), func=job_a, ...) serial_queue.schedule( s

我有两种作业:一种是串行运行,另一种是并行并发运行。但是,我希望并行作业以串行方式进行调度(如果您仍在跟踪)。即:

  • 做A
  • 等A,做B
  • 等待B,同时执行2个以上版本的C
  • 我认为它有两个redis队列,一个只有一个工人的串行队列。和一个并行队列,其中有多个工作队列

    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,
         ...)
    
    但是当前的设置给出了一个错误
    属性错误:模块“\uuu main\uuuuuuuuu”没有属性“schedule\u fetch\u tweets”
    。如何为
    pythonrq
    正确打包此函数?

    解决方案需要一些技巧,因为您必须像导入外部模块一样导入当前脚本

    比如说。
    schedule\u twitter\u 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
       )