Exemplo n.º 1
0
def jobs() -> List[Job]:
    wait = (EventTrigger("wait"), timedelta(seconds=30))
    return [
        Job(TaskDescriptorId("id1"), ExecuteCommand("echo hello"),
            timedelta(seconds=10), EventTrigger("run_job")),
        Job(TaskDescriptorId("id2"), ExecuteCommand("sleep 10"),
            timedelta(seconds=10), EventTrigger("run_job"), wait),
    ]
Exemplo n.º 2
0
def test_eq() -> None:
    s1 = Step("a", PerformAction("a"), timedelta())
    s2 = Step("a", WaitForEvent("a", {"foo": "bla"}), timedelta())
    s3 = Step("a", EmitEvent(Event("a", {"a": "b"})), timedelta())
    s4 = Step("a", ExecuteCommand("echo hello"), timedelta())
    assert s1 == Step("a", PerformAction("a"), timedelta())
    assert s2 == Step("a", WaitForEvent("a", {"foo": "bla"}), timedelta())
    assert s3 == Step("a", EmitEvent(Event("a", {"a": "b"})), timedelta())
    assert s4 == Step("a", ExecuteCommand("echo hello"), timedelta())
    trigger = [EventTrigger("start me up")]
    assert Workflow("a", "a", [s1, s2, s3, s4],
                    trigger) == Workflow("a", "a", [s1, s2, s3, s4], trigger)
Exemplo n.º 3
0
 def evaluate(step: Step) -> Step:
     if isinstance(step.action, ExecuteCommand):
         update = copy(step)
         update.action = ExecuteCommand(self.cli.replace_placeholder(step.action.command, **env))
         return update
     else:
         return step
Exemplo n.º 4
0
def test_marshalling_job() -> None:
    j = Job("id", ExecuteCommand("echo hello"), timedelta(seconds=10),
            EventTrigger("run_job"))
    roundtrip(j)
    roundtrip(
        Job(j.id, j.command, j.timeout, j.trigger,
            (EventTrigger("test"), timedelta(hours=2))))
Exemplo n.º 5
0
 async def parse_event() -> Job:
     event, command = re.split("\\s*:\\s*", stripped, 1)
     command = strip_quotes(command, "'")
     await self.cli.evaluate_cli_command(command,
                                         ctx,
                                         replace_place_holder=False)
     uid = uuid_str(f"{command}{event}")[0:8]
     return Job(uid, ExecuteCommand(command), timeout,
                EventTrigger(event), None, ctx.env, mutable)
Exemplo n.º 6
0
async def test_handle_failing_task_command(task_handler: TaskHandlerService, caplog: LogCaptureFixture) -> None:
    caplog.set_level(logging.WARN)
    # This job will fail. Take a very long timeout - to avoid a timeout
    job = Job(TaskDescriptorId("fail"), ExecuteCommand("non_existing_command"), timedelta(hours=4))
    task_handler.task_descriptions = [job]
    assert len(await task_handler.running_tasks()) == 0
    await task_handler.start_task(job, "test fail")
    assert len(await task_handler.running_tasks()) == 1
    # The task is executed async - let's wait here directly
    update_task = (next(iter(task_handler.tasks.values()))).update_task
    assert update_task
    await update_task
    await task_handler.check_overdue_tasks()
    assert len(await task_handler.running_tasks()) == 0
    # One warning has been emitted
    assert len(caplog.records) == 1
    assert "Command non_existing_command failed with error" in caplog.records[0].message
Exemplo n.º 7
0
 async def parse_with_cron() -> Job:
     parts = re.split("\\s+", stripped, 5)
     if len(parts) != 6:
         raise ValueError(f"Invalid job {stripped}")
     wait: Optional[Tuple[EventTrigger, timedelta]] = None
     trigger = TimeTrigger(" ".join(parts[0:5]))
     command = strip_quotes(parts[5], "'")
     # check if we also need to wait for an event: name_of_event : command
     if self.event_re.match(command):
         event, command = re.split("\\s*:\\s*", command, 1)
         command = strip_quotes(command, "'")
         wait = EventTrigger(event), wait_timeout
     await self.cli.evaluate_cli_command(command,
                                         ctx,
                                         replace_place_holder=False)
     uid = uuid_str(f"{command}{trigger}{wait}")[0:8]
     return Job(uid, ExecuteCommand(command), timeout, trigger, wait,
                ctx.env, mutable)
def test_marshalling_step_action() -> None:
    roundtrip(PerformAction("test"))
    roundtrip(EmitEvent(Event("test", {"foo": "hello"})))
    roundtrip(WaitForEvent("test", {"foo": "hello"}))
    roundtrip(ExecuteCommand("help"))