Exemplo n.º 1
0
def test_cron_schedule_offset():
    obj = _schedules.CronSchedule(schedule="days",
                                  offset="P1D",
                                  kickoff_time_input_arg="abc")
    assert obj.cron_schedule.schedule == "days"
    assert obj.cron_schedule.offset == "P1D"
    assert obj == _schedules.CronSchedule.from_flyte_idl(obj.to_flyte_idl())
Exemplo n.º 2
0
def test_schedule_pointing_to_datetime():
    workflow_to_test = _workflow.workflow(
        {},
        inputs={
            'required_input': _workflow.Input(_types.Types.Datetime),
            'default_input': _workflow.Input(_types.Types.Integer, default=5)
        })
    lp = workflow_to_test.create_launch_plan(schedule=_schedules.CronSchedule(
        "* * ? * * *", kickoff_time_input_arg='required_input'),
                                             role='what')
    assert lp.entity_metadata.schedule.kickoff_time_input_arg == 'required_input'
    assert lp.entity_metadata.schedule.cron_expression == "* * ? * * *"
Exemplo n.º 3
0
def test_annotations():
    workflow_to_test = _workflow.workflow(
        {},
        inputs={
            'required_input': _workflow.Input(_types.Types.Integer),
            'default_input': _workflow.Input(_types.Types.Integer, default=5)
        })
    lp = workflow_to_test.create_launch_plan(
        fixed_inputs={'required_input': 5},
        schedule=_schedules.CronSchedule("* * ? * * *"),
        role='what',
        annotations=_common_models.Annotations({"my": "annotation"}))
    assert lp.annotations.values == {"my": "annotation"}
Exemplo n.º 4
0
def test_schedule():
    workflow_to_test = _workflow.workflow(
        {},
        inputs={
            'required_input': _workflow.Input(_types.Types.Integer),
            'default_input': _workflow.Input(_types.Types.Integer, default=5)
        })
    lp = workflow_to_test.create_launch_plan(
        fixed_inputs={'required_input': 5},
        schedule=_schedules.CronSchedule("* * ? * * *"),
        role='what')
    assert lp.entity_metadata.schedule.kickoff_time_input_arg is None
    assert lp.entity_metadata.schedule.cron_expression == "* * ? * * *"
    assert lp.is_scheduled
Exemplo n.º 5
0
def test_labels():
    workflow_to_test = _workflow.workflow(
        {},
        inputs={
            "required_input": _workflow.Input(_types.Types.Integer),
            "default_input": _workflow.Input(_types.Types.Integer, default=5),
        },
    )
    lp = workflow_to_test.create_launch_plan(
        fixed_inputs={"required_input": 5},
        schedule=_schedules.CronSchedule("* * ? * * *"),
        role="what",
        labels=_common_models.Labels({"my": "label"}),
    )
    assert lp.labels.values == {"my": "label"}
Exemplo n.º 6
0
def test_promote_from_model():
    workflow_to_test = _workflow.workflow(
        {},
        inputs={
            'required_input': _workflow.Input(_types.Types.Integer),
            'default_input': _workflow.Input(_types.Types.Integer, default=5)
        })
    workflow_to_test._id = _identifier.Identifier(
        _identifier.ResourceType.WORKFLOW, "p", "d", "n", "v")
    lp = workflow_to_test.create_launch_plan(
        fixed_inputs={'required_input': 5},
        schedule=_schedules.CronSchedule("* * ? * * *"),
        role='what',
        labels=_common_models.Labels({"my": "label"}))

    with _pytest.raises(_user_exceptions.FlyteAssertion):
        _launch_plan.SdkRunnableLaunchPlan.from_flyte_idl(lp.to_flyte_idl())

    lp_from_spec = _launch_plan.SdkLaunchPlan.from_flyte_idl(lp.to_flyte_idl())
    assert not isinstance(lp_from_spec, _launch_plan.SdkRunnableLaunchPlan)
    assert isinstance(lp_from_spec, _launch_plan.SdkLaunchPlan)
    assert lp_from_spec == lp
Exemplo n.º 7
0
        inputs={
            "required_input": _workflow.Input(_types.Types.Integer),
            "default_input": _workflow.Input(_types.Types.Integer, default=5),
        },
    )
    lp = workflow_to_test.create_launch_plan()
    assert len(lp.fixed_inputs.literals) == 0
    assert lp.default_inputs.parameters[
        "default_input"].default.scalar.primitive.integer == 5
    assert lp.default_inputs.parameters["required_input"].required is True


@_pytest.mark.parametrize(
    "schedule,cron_expression,cron_schedule",
    [
        (_schedules.CronSchedule("* * ? * * *"), "* * ? * * *", None),
        (_schedules.CronSchedule(cron_expression="* * ? * * *"), "* * ? * * *",
         None),
        (_schedules.CronSchedule(cron_expression="0/15 * * * ? *"),
         "0/15 * * * ? *", None),
        (_schedules.CronSchedule(schedule="* * * * *"), None,
         _schedule.Schedule.CronSchedule("* * * * *", None)),
        (
            _schedules.CronSchedule(schedule="* * * * *", offset="P1D"),
            None,
            _schedule.Schedule.CronSchedule("* * * * *", "P1D"),
        ),
    ],
)
def test_schedule(schedule, cron_expression, cron_schedule):
    workflow_to_test = _workflow.workflow(
Exemplo n.º 8
0
from recipes.workflows import workflows
from flytekit.common import schedules as _schedules, notifications as _notifications
from flytekit.models.core import execution as _execution
from flytekit.models.common import Labels, Annotations
from datetime import timedelta
from recipes.multi_schedules.scheduled_workflow import ScheduledWorkflow

# A Workflow can have multiple schedules. One per launch plan

# Example 1 show cron schedule
scale_rotate_cronscheduled_launchplan = workflows.ScaleAndRotateWorkflow.create_launch_plan(
    schedule=_schedules.CronSchedule("0/30 * * * ? *"),
    labels=Labels({
        'flyte.org/managed': 'true',
    }),
    annotations=Annotations({
        'flyte.org/secret-inject': 'required',
    }),
    notifications=[
        _notifications.Slack(
            [
                _execution.WorkflowExecutionPhase.SUCCEEDED,
                _execution.WorkflowExecutionPhase.FAILED,
                _execution.WorkflowExecutionPhase.TIMED_OUT,
                _execution.WorkflowExecutionPhase.ABORTED,
            ],
            ['*****@*****.**'],
        ),
    ],
)
Exemplo n.º 9
0
def test_cron():
    obj = _schedules.CronSchedule("* * ? * * *", kickoff_time_input_arg="abc")
    assert obj.kickoff_time_input_arg == "abc"
    assert obj.cron_expression == "* * ? * * *"
    assert obj == _schedules.CronSchedule.from_flyte_idl(obj.to_flyte_idl())
Exemplo n.º 10
0
def test_cron_validation():
    with _pytest.raises(_user_exceptions.FlyteAssertion):
        _schedules.CronSchedule("* * * * * *", kickoff_time_input_arg="abc")

    with _pytest.raises(_user_exceptions.FlyteAssertion):
        _schedules.CronSchedule("* * ? * *", kickoff_time_input_arg="abc")
Exemplo n.º 11
0
from recipes.workflows import workflows
from flytekit.common import schedules as _schedules, notifications as _notifications
from flytekit.models.core import execution as _execution
from flytekit.models.common import Labels, Annotations
from datetime import timedelta

# A Workflow can have multiple schedules. One per launch plan

# Example 1 show cron schedule
scale_rotate_cronscheduled_launchplan = workflows.ScaleAndRotateWorkflow.create_launch_plan(
    schedule=_schedules.CronSchedule("0/30 * * * ? *"),
    labels=Labels({
        'flyte.org/managed': 'true',
    }),
    annotations=Annotations({
        'flyte.org/secret-inject':
            'required',
    }),
    notifications=[
        _notifications.Slack(
            [
                _execution.WorkflowExecutionPhase.SUCCEEDED,
                _execution.WorkflowExecutionPhase.FAILED,
                _execution.WorkflowExecutionPhase.TIMED_OUT,
                _execution.WorkflowExecutionPhase.ABORTED,
            ],
            ['*****@*****.**'],
        ),
    ],
)
Exemplo n.º 12
0
def test_cron_schedule_schedule_validation(schedule):
    obj = _schedules.CronSchedule(schedule=schedule,
                                  kickoff_time_input_arg="abc")
    assert obj.cron_schedule.schedule == schedule
Exemplo n.º 13
0
def test_cron_expression_and_cron_schedule_offset():
    with _pytest.raises(_user_exceptions.FlyteAssertion):
        _schedules.CronSchedule(cron_expression="* * ? * * *",
                                offset="foo",
                                kickoff_time_input_arg="abc")
Exemplo n.º 14
0
def test_cron_schedule_offset_validation_invalid():
    with _pytest.raises(_user_exceptions.FlyteAssertion):
        _schedules.CronSchedule(schedule="days",
                                offset="foo",
                                kickoff_time_input_arg="abc")
Exemplo n.º 15
0
def test_cron_schedule_schedule_validation_invalid(schedule):
    with _pytest.raises(_user_exceptions.FlyteAssertion):
        _schedules.CronSchedule(schedule=schedule,
                                kickoff_time_input_arg="abc")