Skip to content

Commit 1d12dea

Browse files
committed
Merge branch 'release/0.10.4'
2 parents 6441c59 + b155391 commit 1d12dea

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,18 @@ jobs:
99
deploy_docs:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
13-
14-
- name: Install pnpm
12+
- uses: actions/checkout@v4
13+
- name: Setup pnpm
1514
uses: pnpm/action-setup@v2
16-
with:
17-
version: 7
18-
run_install: true
19-
2015
- name: Setup Node.js
2116
uses: actions/setup-node@v3
2217
with:
2318
node-version: 18
2419
cache: pnpm
25-
26-
- name: Build docs
27-
run: |-
28-
pnpm docs:build -d docs_dist
20+
- name: Install deps
21+
run: pnpm install
22+
- name: Build
23+
run: pnpm docs:build -d docs_dist
2924

3025
- name: Setup git
3126
run: |

docs/guide/scheduling-tasks.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ For the `time` field of `ScheduledTask` we use timezone information from datetim
8080

8181
For `cron` tasks, we have an additional field called `cron_offset` that can be used to specify
8282
an offset of the cron task. An offset can be a string like `Europe/Berlin` or an instance of the `timedelta` class.
83+
84+
## Skipping first run
85+
86+
By default, when you start the scheduler it will get all tasks from the schedule source and check whether they should have been executed in this minute. If tasks should have been executed, they will be executed.
87+
88+
This behaviour might be not convinient for some developers. For example, if you have a task that should be executed on every minute, it will be executed once you start the scheduler, even if it was executed a few seconds ago.
89+
90+
To avoid this behaviour, you can pass the `--skip-first-run` flag to the `taskiq scheduler` command. In this case, the scheduler will wait until the start of the next minute and then start executing tasks.
91+
92+
```bash:no-line-numbers
93+
taskiq scheduler module:scheduler --skip-first-run
94+
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "taskiq"
3-
version = "0.10.3"
3+
version = "0.10.4"
44
description = "Distributed task queue with full async support"
55
authors = ["Pavel Kirilin <[email protected]>"]
66
maintainers = ["Pavel Kirilin <[email protected]>"]

taskiq/cli/scheduler/args.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SchedulerArgs:
1616
configure_logging: bool = True
1717
fs_discover: bool = False
1818
tasks_pattern: str = "tasks.py"
19+
skip_first_run: bool = False
1920

2021
@classmethod
2122
def from_cli(cls, args: Optional[Sequence[str]] = None) -> "SchedulerArgs":
@@ -66,4 +67,13 @@ def from_cli(cls, args: Optional[Sequence[str]] = None) -> "SchedulerArgs":
6667
dest="configure_logging",
6768
help="Use this parameter if your application configures custom logging.",
6869
)
70+
parser.add_argument(
71+
"--skip-first-run",
72+
action="store_true",
73+
dest="skip_first_run",
74+
help=(
75+
"Skip first run of scheduler. "
76+
"This option skips running tasks immediately after scheduler start."
77+
),
78+
)
6979
return cls(**parser.parse_args(args).__dict__)

taskiq/cli/scheduler/run.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,15 @@ async def run_scheduler(args: SchedulerArgs) -> None:
206206
logger.info("Starting scheduler.")
207207
await scheduler.startup()
208208
logger.info("Startup completed.")
209-
209+
if args.skip_first_run:
210+
next_minute = datetime.utcnow().replace(second=0, microsecond=0) + timedelta(
211+
minutes=1,
212+
)
213+
delay = next_minute - datetime.utcnow()
214+
delay_secs = int(delay.total_seconds())
215+
logger.info(f"Skipping first run. Waiting {delay_secs} seconds.")
216+
await asyncio.sleep(delay.total_seconds())
217+
logger.info("First run skipped. The scheduler is now running.")
210218
try:
211219
await run_scheduler_loop(scheduler)
212220
except asyncio.CancelledError:

0 commit comments

Comments
 (0)