예제 #1
0
def start_task() -> None:
    task_definition = get_next_task()
    if task_definition:
        job = get_existing_job_status(task_definition)
        if job and job.status.active:
            _log.warning("Throwing away task because job already exists")
            redis.lpop_sync(PENDING_TASK_KEY)
            return
        if job and (job.status.succeeded or job.status.failed):
            delete_existing_job(task_definition)
        attempt_job_launch(task_definition)
        redis.lpop_sync(PENDING_TASK_KEY)
예제 #2
0
def get_next_item() -> Optional[Any]:
    """Get and json.loads the next item from the queue"""
    item = cast(bytes, redis.rpoplpush_sync(INCOMING_TX_KEY, PROCESSING_TX_KEY, decode=False))
    if item is not None:
        if LEVEL != "1":
            if item_is_expired(item):
                redis.lpop_sync(PROCESSING_TX_KEY, decode=False)
                return get_next_item()

        next_item = json.loads(item)
        _log.info(f"Next item: {next_item}")
        return next_item

    return None
예제 #3
0
def get_next_task() -> Optional[dict]:
    """Pop the next task off of the job queue
    Returns:
        The next task. Blocks until a job is found.
    """
    _log.info("Awaiting contract task...")
    pop_result = redis.brpoplpush_sync(CONTRACT_TASK_KEY,
                                       PENDING_TASK_KEY,
                                       0,
                                       decode=False)
    if pop_result is None:
        return None
    _log.debug(f"received task: {pop_result}")
    try:
        event = json.loads(pop_result)
        _validate_sc_build_task(event)
    except Exception:
        _log.exception("Error processing task, skipping")
        redis.lpop_sync(PENDING_TASK_KEY)
        return None
    _log.info(f"New task request received: {event}")
    return event
예제 #4
0
 def test_lpop(self):
     redis.lpop_sync("banana")
     redis.redis_client.lpop.assert_called_once_with("banana")