Skip to content

Commit 6999d18

Browse files
committed
fix:SCHEDULER_CONFIG as dict #273
1 parent 070fab7 commit 6999d18

File tree

5 files changed

+64
-9
lines changed

5 files changed

+64
-9
lines changed

docs/changelog.md

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

3+
## v4.0.4 🌈
4+
### 🐛 Bug Fixes
5+
- Issue when `SCHEDULER_CONFIG` is a `dict`
36
## v4.0.3 🌈
47

58
### 🐛 Bug Fixes

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.3"
7+
version = "4.0.4"
88
description = "An async job scheduler for django using redis/valkey brokers"
99
authors = [{ name = "Daniel Moran", email = "daniel@moransoftware.ca" }]
1010
requires-python = "~=3.10"

scheduler/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def conf_settings():
3535

3636
user_settings = getattr(settings, "SCHEDULER_CONFIG", {})
3737
if isinstance(user_settings, SchedulerConfiguration):
38+
SCHEDULER_CONFIG = user_settings # type: ignore
3839
return
3940
if not isinstance(user_settings, dict):
4041
raise ImproperlyConfigured("SCHEDULER_CONFIG should be a SchedulerConfiguration or dict")

scheduler/tests/test_settings.py

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
1+
import dataclasses
2+
13
from django.conf import settings
4+
from django.core.exceptions import ImproperlyConfigured
25

3-
from scheduler.settings import conf_settings, SCHEDULER_CONFIG
6+
from scheduler.settings import conf_settings
47
from scheduler.tests.testtools import SchedulerBaseCase
5-
from scheduler.types import Broker
8+
from scheduler.types import Broker, SchedulerConfiguration
69

710

811
class TestWorkerAdmin(SchedulerBaseCase):
912

1013
def test_scheduler_config_as_dict(self):
11-
self.assertEqual(SCHEDULER_CONFIG.EXECUTIONS_IN_PAGE, 20)
14+
from scheduler.settings import SCHEDULER_CONFIG
15+
1216
settings.SCHEDULER_CONFIG = dict(
17+
EXECUTIONS_IN_PAGE=SCHEDULER_CONFIG.EXECUTIONS_IN_PAGE + 1,
18+
SCHEDULER_INTERVAL=SCHEDULER_CONFIG.SCHEDULER_INTERVAL + 1,
19+
BROKER=Broker.REDIS,
20+
CALLBACK_TIMEOUT=SCHEDULER_CONFIG.SCHEDULER_INTERVAL + 1,
21+
22+
DEFAULT_SUCCESS_TTL=SCHEDULER_CONFIG.DEFAULT_SUCCESS_TTL + 1,
23+
DEFAULT_FAILURE_TTL=SCHEDULER_CONFIG.DEFAULT_FAILURE_TTL + 1,
24+
DEFAULT_JOB_TTL=SCHEDULER_CONFIG.DEFAULT_JOB_TTL + 1,
25+
DEFAULT_JOB_TIMEOUT=SCHEDULER_CONFIG.DEFAULT_JOB_TIMEOUT + 1,
26+
# General configuration values
27+
DEFAULT_WORKER_TTL=SCHEDULER_CONFIG.DEFAULT_WORKER_TTL + 1,
28+
DEFAULT_MAINTENANCE_TASK_INTERVAL=SCHEDULER_CONFIG.DEFAULT_MAINTENANCE_TASK_INTERVAL + 1,
29+
DEFAULT_JOB_MONITORING_INTERVAL=SCHEDULER_CONFIG.DEFAULT_JOB_MONITORING_INTERVAL + 1,
30+
SCHEDULER_FALLBACK_PERIOD_SECS=SCHEDULER_CONFIG.SCHEDULER_FALLBACK_PERIOD_SECS + 1,
31+
)
32+
conf_settings()
33+
from scheduler.settings import SCHEDULER_CONFIG
34+
for key, value in settings.SCHEDULER_CONFIG.items():
35+
self.assertEqual(getattr(SCHEDULER_CONFIG, key), value)
36+
37+
def test_scheduler_config_as_data_class(self):
38+
from scheduler.settings import SCHEDULER_CONFIG
39+
self.assertEqual(SCHEDULER_CONFIG.EXECUTIONS_IN_PAGE, 20)
40+
settings.SCHEDULER_CONFIG = SchedulerConfiguration(
1341
EXECUTIONS_IN_PAGE=1,
1442
SCHEDULER_INTERVAL=60,
1543
BROKER=Broker.REDIS,
@@ -26,5 +54,28 @@ def test_scheduler_config_as_dict(self):
2654
SCHEDULER_FALLBACK_PERIOD_SECS=1111,
2755
)
2856
conf_settings()
29-
for key, value in settings.SCHEDULER_CONFIG.items():
57+
from scheduler.settings import SCHEDULER_CONFIG
58+
for key, value in dataclasses.asdict(settings.SCHEDULER_CONFIG).items():
3059
self.assertEqual(getattr(SCHEDULER_CONFIG, key), value)
60+
61+
62+
def test_scheduler_config_as_dict_bad_param(self):
63+
64+
settings.SCHEDULER_CONFIG = dict(
65+
EXECUTIONS_IN_PAGE=1,
66+
SCHEDULER_INTERVAL=60,
67+
BROKER=Broker.REDIS,
68+
CALLBACK_TIMEOUT=1111,
69+
70+
DEFAULT_SUCCESS_TTL=1111,
71+
DEFAULT_FAILURE_TTL=111111,
72+
DEFAULT_JOB_TTL=1111,
73+
DEFAULT_JOB_TIMEOUT=11111,
74+
# General configuration values
75+
DEFAULT_WORKER_TTL=11111,
76+
DEFAULT_MAINTENANCE_TASK_INTERVAL=111,
77+
DEFAULT_JOB_MONITORING_INTERVAL=1111,
78+
SCHEDULER_FALLBACK_PERIOD_SECS=1111,
79+
BAD_PARAM='bad_value', # This should raise an error
80+
)
81+
self.assertRaises(ImproperlyConfigured, conf_settings)

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)