Example #1
0
def _mark_for_retry(colls, item, msg):
    retries = item.get('meta')
    if retries:
        retries = retries.get('times_failed')
    if retries and retries >= MAX_RETRIES:
        msg = ('Queue item {_id} has been tried {max_retries} '
               'times'.format(
                   _id=item['_id'],
                   max_retries=MAX_RETRIES,
               ))
        _mark_failed(colls, item, msg)
        return

    log.error('{msg}. Marking for retry.'.format(msg=msg, ))
    queue_coll = colls['kajabi-queue']
    kwargs = dict([
        (
            '$inc',
            dict([
                ('meta.times_failed', 1),
            ]),
        ),
        (
            '$set',
            dict([
                ('meta.last_failed_on', datetime.utcnow()),
                ('meta.last_failed_msg', msg),
            ]),
        ),
    ])
    mongo.safe_upsert(queue_coll, item['_id'], **kwargs)
Example #2
0
def _mark_successful(colls, item):
    queue_coll = colls['kajabi-queue']
    kwargs = dict([
        (
            '$set',
            dict([
                ('meta.succeeded_on', datetime.utcnow()),
            ]),
        ),
    ])
    mongo.safe_upsert(queue_coll, item['_id'], **kwargs)
Example #3
0
def _mark_failed(colls, item, msg):
    log.error('{msg}. Marking as failed.'.format(msg=msg, ))
    queue_coll = colls['kajabi-queue']
    kwargs = dict([
        (
            '$set',
            dict([
                ('meta.gave_up_msg', msg),
                ('meta.gave_up_on', datetime.utcnow()),
            ]),
        ),
    ])
    mongo.safe_upsert(queue_coll, item['_id'], **kwargs)
Example #4
0
def _mark_successful(colls, item):
    queue_coll = colls['kajabi-queue']
    kwargs = dict([
        ('$set', dict([
            ('meta.succeeded_on', datetime.utcnow()),
        ]),
     ),
    ])
    mongo.safe_upsert(
        queue_coll,
        item['_id'],
        **kwargs
    )
Example #5
0
def _mark_failed(colls, item, msg):
    log.error(
        '{msg}. Marking as failed.'.format(
            msg=msg,
        )
    )
    queue_coll = colls['kajabi-queue']
    kwargs = dict([
        ('$set', dict([
            ('meta.gave_up_msg', msg),
            ('meta.gave_up_on', datetime.utcnow()),
        ]),
     ),
    ])
    mongo.safe_upsert(
        queue_coll,
        item['_id'],
        **kwargs
    )
Example #6
0
def _mark_for_retry(colls, item, msg):
    retries = item.get('meta')
    if retries:
        retries = retries.get('times_failed')
    if retries and retries >= MAX_RETRIES:
        msg = (
            'Queue item {_id} has been tried {max_retries} '
            'times'.format(
                _id=item['_id'],
                max_retries=MAX_RETRIES,
            )
        )
        _mark_failed(colls, item, msg)
        return

    log.error(
        '{msg}. Marking for retry.'.format(
            msg=msg,
        )
    )
    queue_coll = colls['kajabi-queue']
    kwargs = dict([
        ('$inc', dict([
            ('meta.times_failed', 1),
        ]),
     ),
        ('$set', dict([
            ('meta.last_failed_on', datetime.utcnow()),
            ('meta.last_failed_msg', msg),
        ]),
     ),
    ])
    mongo.safe_upsert(
        queue_coll,
        item['_id'],
        **kwargs
    )