diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-09-23 01:21:34 +0300 |
---|---|---|
committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-09-23 01:21:34 +0300 |
commit | e9c560fa24abcc64c6b426181ec76d6d6cdeb490 (patch) | |
tree | e9b6916ca2c3b63dd132e544f4dacfe39309347e | |
parent | 310652119957194d3c8cac91bf6bf171b647a103 (diff) | |
download | apscheduler-e9c560fa24abcc64c6b426181ec76d6d6cdeb490.tar.gz |
Fixed a couple of bugs in the SQLAlchemy data stores
-rw-r--r-- | src/apscheduler/datastores/async_sqlalchemy.py | 2 | ||||
-rw-r--r-- | src/apscheduler/datastores/sqlalchemy.py | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/apscheduler/datastores/async_sqlalchemy.py b/src/apscheduler/datastores/async_sqlalchemy.py index 92ba02b..989fa25 100644 --- a/src/apscheduler/datastores/async_sqlalchemy.py +++ b/src/apscheduler/datastores/async_sqlalchemy.py @@ -281,7 +281,7 @@ class AsyncSQLAlchemyDataStore(_BaseSQLAlchemyDataStore, AsyncDataStore): await self._events.publish(ScheduleRemoved(schedule_id=schedule_id)) async def get_next_schedule_run_time(self) -> Optional[datetime]: - statenent = select(self.t_schedules.c.id).\ + statenent = select(self.t_schedules.c.next_fire_time).\ where(self.t_schedules.c.next_fire_time.isnot(None)).\ order_by(self.t_schedules.c.next_fire_time).\ limit(1) diff --git a/src/apscheduler/datastores/sqlalchemy.py b/src/apscheduler/datastores/sqlalchemy.py index 0bfc211..4eb8ad1 100644 --- a/src/apscheduler/datastores/sqlalchemy.py +++ b/src/apscheduler/datastores/sqlalchemy.py @@ -284,9 +284,6 @@ class SQLAlchemyDataStore(_BaseSQLAlchemyDataStore, DataStore): try: with self.engine.begin() as conn: conn.execute(insert) - event = ScheduleAdded(schedule_id=schedule.id, - next_fire_time=schedule.next_fire_time) - self._events.publish(event) except IntegrityError: if conflict_policy is ConflictPolicy.exception: raise ConflictingIdError(schedule.id) from None @@ -301,6 +298,10 @@ class SQLAlchemyDataStore(_BaseSQLAlchemyDataStore, DataStore): event = ScheduleUpdated(schedule_id=schedule.id, next_fire_time=schedule.next_fire_time) self._events.publish(event) + else: + event = ScheduleAdded(schedule_id=schedule.id, + next_fire_time=schedule.next_fire_time) + self._events.publish(event) def remove_schedules(self, ids: Iterable[str]) -> None: with self.engine.begin() as conn: @@ -413,7 +414,7 @@ class SQLAlchemyDataStore(_BaseSQLAlchemyDataStore, DataStore): self._events.publish(ScheduleRemoved(schedule_id=schedule_id)) def get_next_schedule_run_time(self) -> Optional[datetime]: - query = select(self.t_schedules.c.id).\ + query = select(self.t_schedules.c.next_fire_time).\ where(self.t_schedules.c.next_fire_time.isnot(None)).\ order_by(self.t_schedules.c.next_fire_time).\ limit(1) |