Skip to content

Commit f9eb244

Browse files
committed
fix:scheduler_worker command argument
1 parent 5dbc97e commit f9eb244

File tree

6 files changed

+124
-87
lines changed

6 files changed

+124
-87
lines changed

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v4.0.3 🌈
4+
5+
### 🐛 Bug Fixes
6+
7+
- Updated `scheduler_worker` management command argument to `--without-scheduler` since the worker has a scheduler by
8+
default.
9+
310
## v4.0.2 🌈
411

512
### 🐛 Bug Fixes

docs/commands.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ If no queues are specified, will run on default queue only.
88
All queues must have the same redis settings on `SCHEDULER_QUEUES`.
99

1010
```shell
11-
usage: manage.py scheduler_worker [-h] [--pid PIDFILE] [--name NAME] [--worker-ttl WORKER_TTL] [--fork-job-execution FORK_JOB_EXECUTION] [--sentry-dsn SENTRY_DSN] [--sentry-debug] [--sentry-ca-certs SENTRY_CA_CERTS] [--burst]
12-
[--max-jobs MAX_JOBS] [--max-idle-time MAX_IDLE_TIME] [--with-scheduler] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]
11+
usage: manage.py scheduler_worker [-h] [--pid PIDFILE] [--name NAME] [--worker-ttl WORKER_TTL]
12+
[--fork-job-execution FORK_JOB_EXECUTION] [--sentry-dsn SENTRY_DSN] [--sentry-debug]
13+
[--sentry-ca-certs SENTRY_CA_CERTS] [--burst] [--max-jobs MAX_JOBS]
14+
[--max-idle-time MAX_IDLE_TIME] [--without-scheduler] [--version] [-v {0,1,2,3}]
15+
[--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]
1316
[--skip-checks]
1417
[queues ...]
1518

@@ -33,14 +36,15 @@ options:
3336
--max-jobs MAX_JOBS Maximum number of jobs to execute before terminating worker
3437
--max-idle-time MAX_IDLE_TIME
3538
Maximum number of seconds to wait for new job before terminating worker
36-
--with-scheduler Run worker with scheduler, default to True
39+
--without-scheduler Run worker without scheduler, default to with scheduler
3740
--version Show program's version number and exit.
38-
-v {0,1,2,3}, --verbosity {0,1,2,3}
41+
-v, --verbosity {0,1,2,3}
3942
Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output
40-
--settings SETTINGS The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used.
43+
--settings SETTINGS The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the
44+
DJANGO_SETTINGS_MODULE environment variable will be used.
4145
--pythonpath PYTHONPATH
4246
A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".
43-
--traceback Raise on CommandError exceptions.
47+
--traceback Display a full stack trace on CommandError exceptions.
4448
--no-color Don't colorize the command output.
4549
--force-color Force colorization of the command output.
4650
--skip-checks Skip system checks.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "django-tasks-scheduler"
7-
version = "4.0.2"
7+
version = "4.0.3"
88
description = "An async job scheduler for django using redis/valkey brokers"
99
authors = [{ name = "Daniel Moran", email = "[email protected]" }]
1010
requires-python = "~=3.10"

scheduler/management/commands/scheduler_worker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ def _add_work_args(self, parser):
8383
help="Maximum number of seconds to wait for new job before terminating worker",
8484
)
8585
parser.add_argument(
86-
"--with-scheduler",
87-
action="store_true",
86+
"--without-scheduler",
87+
action="store_false",
8888
default=True,
8989
dest="with_scheduler",
90-
help="Run worker with scheduler, default to True",
90+
help="Run worker without scheduler, default to with scheduler",
9191
)
9292

9393
def add_arguments(self, parser):

scheduler/tests/test_mgmt_commands/test_scheduler_worker.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from unittest import mock
2+
13
from django.core.management import call_command
24
from django.test import TestCase
35

@@ -28,6 +30,26 @@ def test_scheduler_worker__no_queues_params(self):
2830
self.assertTrue(job.is_failed)
2931
SCHEDULER_CONFIG.SCHEDULER_INTERVAL = 10
3032

33+
@mock.patch("scheduler.worker.create_worker")
34+
def test_scheduler_worker__without_scheduler(self, mock_create_worker):
35+
queue = get_queue("default")
36+
37+
# Create a worker to execute these jobs
38+
call_command("scheduler_worker", "default", "--without-scheduler")
39+
mock_create_worker.assert_called_once_with(
40+
'default', name=None, fork_job_execution=True, burst=False, with_scheduler=False,
41+
)
42+
43+
@mock.patch("scheduler.worker.create_worker")
44+
def test_scheduler_worker__with_scheduler(self, mock_create_worker):
45+
queue = get_queue("default")
46+
47+
# Create a worker to execute these jobs
48+
call_command("scheduler_worker", "default")
49+
mock_create_worker.assert_called_once_with(
50+
'default', name=None, fork_job_execution=True, burst=False, with_scheduler=True,
51+
)
52+
3153
def test_scheduler_worker__run_jobs(self):
3254
SCHEDULER_CONFIG.SCHEDULER_INTERVAL = 1
3355
queue = get_queue("default")

0 commit comments

Comments
 (0)