Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Dec 3, 2023
1 parent 211ce1b commit 48638b2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/faq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# FAQ

- [Why Python](why-python.md)
- [Does Zrb has A Scheduler](does-zrb-has-a-scheduler.md)
- [Does Zrb have a scheduler](does-zrb-have-a-scheduler.md)
- [How to get data from other tasks](how-to-get-data-from-other-tasks.md)

🔖 [Table of Contents](../README.md)
20 changes: 0 additions & 20 deletions docs/faq/does-zrb-has-a-scheduler.md

This file was deleted.

20 changes: 20 additions & 0 deletions docs/faq/does-zrb-have-a-scheduler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🔖 [Table of Contents](../README.md) / [FAQ](README.md)


# Does Zrb Have a Scheduler?

No, but you can use `RecurringTask` and `TimeWatcher`


# How To Make A Scheduled Task?

There are some [tricks](../tutorials/running-task-by-schedule.md) you can use.

For example, you can use:

- RecurringTask
- Infinite loop
- Cronjob
- Orchestrator like Airflow.

🔖 [Table of Contents](../README.md) / [FAQ](README.md)
46 changes: 44 additions & 2 deletions docs/tutorials/running-task-by-schedule.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
🔖 [Table of Contents](../README.md) / [Tutorials](README.md)

# Run Task by Schedule
# Running Task by Schedule

Zrb doesn't have any built-in scheduler. However, there are some workarounds you can use:

- Using RecurringTask
- Creating an infinite loop
- Using Cronjob
- Using Airflow or other orchestrator

# Using RecurringTask

The best approach is by turning your task into a recurring task.

```python
from zrb import CmdTask, TimeWatcher, RecurringTask, runner

# Your original task
hello = CmdTask(
name='hello',
cmd='echo "hello world"'
)
runner.register(hello)


# Your recurring task
scheduled_hello = RecurringTask(
name='scheduled-hello',
inputs=[
StrInput(name='schedule', default='* * * * *')
],
triggers=[
TimeWatcher(schedule='{{input.schedule}}')
],
task=hello
)
runner.register(scheduled_hello)
```

Notice that `TimeWatcher`'s `schedule` is a [cron schedule expression](https://crontab.guru/).

The expression `* * * * *` means that the task will be executed every minute.

To execute `scheduled-hello`, you can invoke:

```bash
zrb scheduled-hello
```


# Creating an Infinite Loop

The simplest approach is by turning your task into a function, and call your function after some interval.
Another simple approach is by turning your task into a function, and call your function after some interval.

For example, you want to run `hello` task every 5 seconds. Then you can create the following Python script and run it.

Expand Down Expand Up @@ -38,6 +79,7 @@ while True:
python scheduled_hello.py
```


# Using CronJob


Expand Down

0 comments on commit 48638b2

Please sign in to comment.