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)
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)
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)
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 )
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 )
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 )