django celery位置参数celerybeat调度错误

时间:2018-05-04 01:41:55

标签: python django celery celerybeat

由于位置参数,我无法让celerybeat安排我的功能。

阅读文档我不明白为什么有些功能是指一个数字而有些功能不是。我试图像我的函数一样添加args但是我得到以下错误

check_arguments(*(args or ()), **(kwargs or {}))
celery.beat.SchedulingError: Couldn't apply scheduled task 
list_market_catalogue: list_market_catalogue() takes 1 positional 
argument but 3 were given

有人能指出我正确的方向吗?

tasks.py

ET_TENNIS = 2
@shared_task(bind=True)
def list_market_catalogue(self):
    logger.warning('+' * 80)
    trading = get_betfair_client()
    time_ago = timezone.now() + datetime.timedelta(minutes=1000)
    time_fwd = timezone.now() + datetime.timedelta(minutes=6000)
    mfilter = market_filter(
        event_type_ids=[ET_TENNIS] ,
        market_start_time=time_range(
             from_=time_ago.strftime('%Y-%m-%dT%H:%I:%S.000Z') ,
             to=time_fwd.strftime('%Y-%m-%dT%H:%I:%S.000Z')
             )
       )
    res = trading.betting.list_market_catalogue(
         mfilter ,
         market_projection=[
            'EVENT' ,
            'MARKET_START_TIME' ,
          # 'MARKET_DESCRIPTION',
          # 'RUNNER_METADATA',
        ] ,
        sort='FIRST_TO_START' ,
        max_results=100 ,
        lightweight=True)
    if not len(res):
        logger.error('Market catalogue listing is empty')
        trading.session_token = None
        raise self.retry(countdown=5 , max_retries=12)

    for cat in res:
        if 'venue' not in cat['event']:
        logger.error(f'No event venue in {cat}')
        continue
    try:
        event = parse_event(cat['event'])
        market = parse_market(event , cat)
        runners = parse_runners(market , cat['runners'])
    except:
        logger.warning(cat)
        raise
        logger.warning(f'BETFAIR: Scraped {len(res)} from market 
        catalogue')

@shared_task
def parse_runners(market , items):
    """Parses runners from MarketCatalogue object"""
    runners = []
    for runner_item in items:
        num = runner_item['metadata'].get('CLOTH_NUMBER')
        if not num:
            matches = re.match(r'^(\d+)' , runner_item['runnerName'])
            if matches:
                num = matches.groups(0)[0]
            else:
                logger.error(f'Could not match number for 
                {runner_item}')
        runner , created = Runner.objects.update_or_create(
            selection_id=runner_item['selectionId'] ,
            defaults={
                'market': market ,
                # default
                'name': runner_item['runnerName'].upper() ,
                'sort_priority': runner_item['sortPriority'] ,
                'handicap': runner_item['handicap'] ,
                # metadata
                'cloth_number': num ,
                'stall_draw': 
                runner_item['metadata'].get('STALL_DRAW') ,
                'runner_id': runner_item['metadata']['runnerId'] ,
            }
        )
        if created:
            logger.info(f'Created {runner}')
        else:
            logger.debug(f'Updated {runner}')
        runners.append(runner)
    return runners

settings.py

CELERY_BEAT_SCHEDULE = {
'list_market_catalogue': {
    'task': 'trader.tasks.list_market_catalogue',
    'schedule': timedelta(seconds=5),
    'args': (['self'],)
},
'parse_runners': {
    'task': 'trader.tasks.parse_runners' ,
    'schedule': timedelta(seconds=5) ,
    'args': (['market'],['items'])
},

0 个答案:

没有答案