def test_mark_completed_when_attempt_unknown():
    time_stamp1 = datetime(year=2018,
                           month=8,
                           day=13,
                           hour=5,
                           minute=10,
                           second=5,
                           microsecond=100222)
    tq = SimpleTaskQueue(LOGGER)
    t1 = Task(1,
              "run command example",
              time_stamp1,
              name="example run",
              desc="this is a bologna command that does nothing",
              duration=100,
              max_attempts=2)
    tq.add_task(t1)
    tm = TaskManager(LOGGER)
    tm._todo_queue = tq

    completed_time_stamp = datetime(year=2018,
                                    month=8,
                                    day=13,
                                    hour=5,
                                    minute=10,
                                    second=44,
                                    microsecond=100222)
    assert tm.complete_attempt(t1.task_id(), "some_random_unknown_attempt_id",
                               completed_time_stamp) is False
Esempio n. 2
0
def test_task_to_retry_first_started_retry():
    time_stamp = datetime(year=2018,
                          month=8,
                          day=13,
                          hour=5,
                          minute=10,
                          second=5,
                          microsecond=100222)

    t1 = Task(1,
              "run command example",
              time_stamp,
              name="example run",
              desc="this is a bologna command that does nothing",
              duration=100,
              max_attempts=3)
    start_time_stamp = datetime(year=2018,
                                month=8,
                                day=13,
                                hour=5,
                                minute=10,
                                second=6,
                                microsecond=100222)
    t1.attempt_task("runner", start_time_stamp)

    t2 = Task(2,
              "run command example 2",
              time_stamp,
              name="example run 2",
              desc="this is a bologna command that does nothing",
              duration=820,
              max_attempts=3)
    start_time_stamp = datetime(year=2018,
                                month=8,
                                day=13,
                                hour=5,
                                minute=10,
                                second=6,
                                microsecond=100222)
    t2.attempt_task("runner", start_time_stamp)

    ot = OpenTasks(LOGGER)
    ot.add_task(t1)
    ot.add_task(t2)
    current_time = datetime(year=2018,
                            month=8,
                            day=13,
                            hour=5,
                            minute=12,
                            second=8,
                            microsecond=100222)
    task, failed_tasks = ot.task_to_retry(current_time)
    # should be no failed tasks
    assert task.task_id() == t1.task_id()
    assert task == t1
    assert len(failed_tasks) == 0