Skip to content

Commit 664170e

Browse files
Verify apscheduler config, forbid pool executors (#228)
1 parent 05fd802 commit 664170e

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Please use [this](https://docs.gitlab.com/ee/development/changelog.html) documen
77
### Fixed
88

99
* ci: Removed `black 21.12b0` dependency since bug in `datamodel-codegen-generator` is fixed.
10+
* config: Verify `advanced.scheduler` config for correctness unsupported features.
1011
* hasura: Fixed processing relation fields with missing `related_name`.
12+
* jobs: Fixed default `apscheduler` config.
1113

1214
## 4.2.2 - 2022-02-01
1315

src/dipdup/scheduler.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from contextlib import AsyncExitStack
23
from datetime import datetime
34
from functools import partial
@@ -18,22 +19,23 @@
1819
from dipdup.utils.database import in_global_transaction
1920

2021
DEFAULT_CONFIG = {
21-
'jobstores': {
22-
'default': {
23-
'class': 'apscheduler.jobstores.memory:MemoryJobStore',
24-
},
25-
},
26-
'executors': {
27-
'default': {
28-
'class': 'dipdup.executors.asyncio:AsyncIOExecutor',
29-
},
30-
},
31-
'timezone': 'UTC',
22+
'apscheduler.jobstores.default.class': 'apscheduler.jobstores.memory:MemoryJobStore',
23+
'apscheduler.executors.default.class': 'apscheduler.executors.asyncio:AsyncIOExecutor',
24+
'apscheduler.timezone': 'UTC',
3225
}
3326

3427

3528
def create_scheduler(config: Optional[Dict[str, Any]] = None) -> AsyncIOScheduler:
36-
return AsyncIOScheduler(config or DEFAULT_CONFIG)
29+
if not config:
30+
return AsyncIOScheduler(DEFAULT_CONFIG)
31+
32+
json_config = json.dumps(config)
33+
if 'apscheduler.executors.pool' in json_config:
34+
raise ConfigurationError('`apscheduler.executors.pool` is not supported. If needed, create a pool inside a regular hook.')
35+
for key in config:
36+
if not key.startswith('apscheduler.'):
37+
raise ConfigurationError('`advanced.scheduler` config keys must start with `apscheduler.`, see apscheduler library docs')
38+
return AsyncIOScheduler(config)
3739

3840

3941
def add_job(ctx: DipDupContext, scheduler: AsyncIOScheduler, job_config: JobConfig) -> None:

0 commit comments

Comments
 (0)