summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2022-07-30 17:19:01 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2022-07-30 17:19:01 +0300
commit886009e8310762eefc58fd54f5eba2a5172b7b11 (patch)
treeb7ad41274550c5a0f87e47402662cfcbbe8fcd96 /src
parent214b8add6e12c9c54a6d3e34ced0f009250c3bc0 (diff)
downloadapscheduler-886009e8310762eefc58fd54f5eba2a5172b7b11.tar.gz
Changed get_schedule() to raise ScheduleLookupError when the target schedule isn't found
Diffstat (limited to 'src')
-rw-r--r--src/apscheduler/schedulers/async_.py12
-rw-r--r--src/apscheduler/schedulers/sync.py12
2 files changed, 20 insertions, 4 deletions
diff --git a/src/apscheduler/schedulers/async_.py b/src/apscheduler/schedulers/async_.py
index bc90c05..4ad15ac 100644
--- a/src/apscheduler/schedulers/async_.py
+++ b/src/apscheduler/schedulers/async_.py
@@ -28,7 +28,12 @@ from ..events import (
SchedulerStopped,
ScheduleUpdated,
)
-from ..exceptions import JobCancelled, JobDeadlineMissed, JobLookupError
+from ..exceptions import (
+ JobCancelled,
+ JobDeadlineMissed,
+ JobLookupError,
+ ScheduleLookupError,
+)
from ..marshalling import callable_to_ref
from ..structures import JobResult, Task
from ..workers.async_ import AsyncWorker
@@ -168,7 +173,10 @@ class AsyncScheduler:
"""
schedules = await self.data_store.get_schedules({id})
- return schedules[0]
+ if schedules:
+ return schedules[0]
+ else:
+ raise ScheduleLookupError(id)
async def remove_schedule(self, id: str) -> None:
"""
diff --git a/src/apscheduler/schedulers/sync.py b/src/apscheduler/schedulers/sync.py
index 3f59b3f..356608e 100644
--- a/src/apscheduler/schedulers/sync.py
+++ b/src/apscheduler/schedulers/sync.py
@@ -28,7 +28,12 @@ from ..events import (
SchedulerStopped,
ScheduleUpdated,
)
-from ..exceptions import JobCancelled, JobDeadlineMissed, JobLookupError
+from ..exceptions import (
+ JobCancelled,
+ JobDeadlineMissed,
+ JobLookupError,
+ ScheduleLookupError,
+)
from ..marshalling import callable_to_ref
from ..structures import Job, JobResult, Schedule, Task
from ..workers.sync import Worker
@@ -198,7 +203,10 @@ class Scheduler:
"""
self._ensure_services_ready()
schedules = self.data_store.get_schedules({id})
- return schedules[0]
+ if schedules:
+ return schedules[0]
+ else:
+ raise ScheduleLookupError(id)
def remove_schedule(self, id: str) -> None:
"""