Skip to content

Commit

Permalink
Merge branch 'release/0.10.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Dec 3, 2023
2 parents 6441c59 + b155391 commit 1d12dea
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@ jobs:
deploy_docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install pnpm
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm

- name: Build docs
run: |-
pnpm docs:build -d docs_dist
- name: Install deps
run: pnpm install
- name: Build
run: pnpm docs:build -d docs_dist

- name: Setup git
run: |
Expand Down
12 changes: 12 additions & 0 deletions docs/guide/scheduling-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,15 @@ For the `time` field of `ScheduledTask` we use timezone information from datetim

For `cron` tasks, we have an additional field called `cron_offset` that can be used to specify
an offset of the cron task. An offset can be a string like `Europe/Berlin` or an instance of the `timedelta` class.

## Skipping first run

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.

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.

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.

```bash:no-line-numbers
taskiq scheduler module:scheduler --skip-first-run
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "taskiq"
version = "0.10.3"
version = "0.10.4"
description = "Distributed task queue with full async support"
authors = ["Pavel Kirilin <[email protected]>"]
maintainers = ["Pavel Kirilin <[email protected]>"]
Expand Down
10 changes: 10 additions & 0 deletions taskiq/cli/scheduler/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SchedulerArgs:
configure_logging: bool = True
fs_discover: bool = False
tasks_pattern: str = "tasks.py"
skip_first_run: bool = False

@classmethod
def from_cli(cls, args: Optional[Sequence[str]] = None) -> "SchedulerArgs":
Expand Down Expand Up @@ -66,4 +67,13 @@ def from_cli(cls, args: Optional[Sequence[str]] = None) -> "SchedulerArgs":
dest="configure_logging",
help="Use this parameter if your application configures custom logging.",
)
parser.add_argument(
"--skip-first-run",
action="store_true",
dest="skip_first_run",
help=(
"Skip first run of scheduler. "
"This option skips running tasks immediately after scheduler start."
),
)
return cls(**parser.parse_args(args).__dict__)
10 changes: 9 additions & 1 deletion taskiq/cli/scheduler/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,15 @@ async def run_scheduler(args: SchedulerArgs) -> None:
logger.info("Starting scheduler.")
await scheduler.startup()
logger.info("Startup completed.")

if args.skip_first_run:
next_minute = datetime.utcnow().replace(second=0, microsecond=0) + timedelta(
minutes=1,
)
delay = next_minute - datetime.utcnow()
delay_secs = int(delay.total_seconds())
logger.info(f"Skipping first run. Waiting {delay_secs} seconds.")
await asyncio.sleep(delay.total_seconds())
logger.info("First run skipped. The scheduler is now running.")
try:
await run_scheduler_loop(scheduler)
except asyncio.CancelledError:
Expand Down

0 comments on commit 1d12dea

Please sign in to comment.