Skip to content

Commit

Permalink
Moved the scheduled workflows examples to core (#413)
Browse files Browse the repository at this point in the history
Signed-off-by: Ketan Umare <[email protected]>
  • Loading branch information
pmahindrakar-oss authored Sep 20, 2021
1 parent a48c81b commit 451e463
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
8 changes: 8 additions & 0 deletions cookbook/core/scheduled_workflows/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _scheduled_workflows:

Scheduling Workflows
--------------------

This module explains on how to create and launch scheduled workflows.
Flyte supports both cron based and fixed rate schedules.

Empty file.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""
Scheduling Workflows
--------------------
For background on launch plans, refer to :any:`launch_plans`.
Launch plans can be set to run automatically on a schedule if the Flyte platform is properly configured.
Launch plans can be set to run automatically on a schedule using the flyte native scheduler.
For workflows that depend on knowing the kick-off time, Flyte also supports passing in the scheduled time (not the actual time, which may be a few seconds off) as an argument to the workflow.
.. note::
Native scheduler doesn't support `AWS syntax <http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions>`_.
"""

# %%
Expand All @@ -32,8 +35,8 @@ def date_formatter_wf(kickoff_time: datetime):
# Cron Schedules
# ##############
#
# Cron expression strings use the `AWS syntax <http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions>`_.
# These are validated at launch plan registration time.
# Cron expression strings use the following `syntax <https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format>`_.
# An incorrect cron schedule expression would lead to failure in triggering the schedule
from flytekit import CronSchedule, LaunchPlan

# creates a launch plan that runs at 10am UTC every day.
Expand All @@ -42,7 +45,8 @@ def date_formatter_wf(kickoff_time: datetime):
workflow=date_formatter_wf,
schedule=CronSchedule(
# Note that kickoff_time_input_arg matches the workflow input we defined above: kickoff_time
cron_expression="0 10 * * ? *",
# But in case you are using the AWS scheme of schedules and not using the native scheduler then switch over the schedule parameter with cron_expression
schedule="*/1 * * * *", # Following schedule runs every min
kickoff_time_input_arg="kickoff_time",
),
)
Expand All @@ -55,7 +59,7 @@ def date_formatter_wf(kickoff_time: datetime):
# ####################
#
# If you prefer to use an interval rather than a cron scheduler to schedule your workflows, you can use the fixed-rate scheduler.
# A fixed-rate scheduler runs at the specified interval and is currently supported for Flyte deployments hosted on AWS.
# A fixed-rate scheduler runs at the specified interval.
#
# Here's an example:

Expand Down Expand Up @@ -143,10 +147,10 @@ def positive_wf(name: str):
# flytectl get launchplan -p flytesnacks -d development``

# %%
# Platform Configuration Changes
# ##############################
# Platform Configuration Changes For AWS Scheduler
# ################################################
#
# Scheduling features require additional infrastructure to run, so these will have to be created and configured.
# Scheduling feature can be run using the flyte native scheduler which comes with flyte but if you intend to use the AWS scheduler then it require additional infrastructure to run, so these will have to be created and configured.The following sections are only required if you use AWS scheme for the scheduler. You can even run the flyte native scheduler on AWS though
#
# Setting up Scheduled Workflows
# ==============================
Expand Down Expand Up @@ -207,7 +211,7 @@ def positive_wf(name: str):
# accountId: "{{ YOUR ACCOUNT ID }}"

# %%
# * **scheme**: in this case because AWS is the only cloud back-end supported for executing scheduled workflows, only ``"aws"`` is a valid value. By default, the no-op executor is used.
# * **scheme**: in this case because AWS is the only cloud back-end supported for executing scheduled workflows, only ``"aws"`` is a valid value. By default, the no-op executor is used and in case of sandbox we use ``"local"`` scheme which uses the flyte native scheduler.
# * **region**: this specifies which region AWS clients should will use when creating an SQS subscriber client
# * **scheduleQueueName**: this is the name of the SQS Queue you've allocated to scheduling workflows
# * **accountId**: Your AWS `account id <https://docs.aws.amazon.com/IAM/latest/UserGuide/console_account-alias.html#FindingYourAWSId>`_
4 changes: 3 additions & 1 deletion cookbook/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class CustomSorter(FileNameSortKey):
"typed_schema.py",
"custom_objects.py",
"enums.py",
"lp_schedules.py",
# Testing
"mocking.py",
# Containerization
Expand All @@ -74,7 +75,6 @@ class CustomSorter(FileNameSortKey):
# Deployment
## Workflow
"deploying_workflows.py",
"lp_schedules.py",
"customizing_resources.py",
"lp_notifications.py",
"fast_registration.py",
Expand Down Expand Up @@ -241,6 +241,7 @@ def __call__(self, filename):
examples_dirs = [
"../core/flyte_basics",
"../core/control_flow",
"../core/scheduled_workflows",
"../core/type_system",
"../case_studies/ml_training/pima_diabetes",
"../case_studies/ml_training/house_price_prediction",
Expand Down Expand Up @@ -270,6 +271,7 @@ def __call__(self, filename):
gallery_dirs = [
"auto/core/flyte_basics",
"auto/core/control_flow",
"auto/core/scheduled_workflows",
"auto/core/type_system",
"auto/case_studies/ml_training/pima_diabetes",
"auto/case_studies/ml_training/house_price_prediction",
Expand Down
9 changes: 9 additions & 0 deletions cookbook/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ Table of Contents

---

.. link-button:: auto/core/scheduled_workflows/index
:type: ref
:text: ⏱ Scheduled Workflows
:classes: btn-block stretched-link
^^^^^^^^^^^^
Learn about scheduled workflows.

---

.. link-button:: auto/testing/index
:type: ref
:text: ⚗️ Testing
Expand Down

0 comments on commit 451e463

Please sign in to comment.