summaryrefslogtreecommitdiff
path: root/src/apscheduler/_structures.py
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2022-08-13 23:06:08 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2022-08-13 23:06:08 +0300
commita9141bb5663e0a22cc7c4da7d34834c925dbadea (patch)
tree533ee4126b22d0b30b6c74106d7b4d3b89328757 /src/apscheduler/_structures.py
parentffbbbbe0ee147bba08e0c95b3697136590997fb1 (diff)
downloadapscheduler-a9141bb5663e0a22cc7c4da7d34834c925dbadea.tar.gz
Added job expiration times
Scheduled jobs no longer retain their results. All job outcomes are now logged by the workers. Workers, rather than data stores, are now responsible for emitting the JobReleased event.
Diffstat (limited to 'src/apscheduler/_structures.py')
-rw-r--r--src/apscheduler/_structures.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/apscheduler/_structures.py b/src/apscheduler/_structures.py
index 6ceaaf6..ba3359b 100644
--- a/src/apscheduler/_structures.py
+++ b/src/apscheduler/_structures.py
@@ -158,6 +158,8 @@ class Job:
(if the job was derived from a schedule)
:param start_deadline: if the job is started in the worker after this time, it is
considered to be misfired and will be aborted
+ :param result_expiration_time: minimum amount of time to keep the result available
+ for fetching in the data store
:param tags: strings that can be used to categorize and filter the job
:param created_at: the time at which the job was created
:param started_at: the time at which the execution of the job was started
@@ -181,6 +183,9 @@ class Job:
eq=False, order=False, converter=as_timedelta, factory=timedelta
)
start_deadline: datetime | None = attrs.field(eq=False, order=False, default=None)
+ result_expiration_time: timedelta = attrs.field(
+ eq=False, order=False, converter=as_timedelta, default=timedelta()
+ )
tags: frozenset[str] = attrs.field(
eq=False, order=False, converter=frozenset, default=()
)
@@ -277,9 +282,31 @@ class JobResult:
finished_at: datetime = attrs.field(
eq=False, order=False, factory=partial(datetime.now, timezone.utc)
)
+ expires_at: datetime = attrs.field(eq=False, order=False)
exception: BaseException | None = attrs.field(eq=False, order=False, default=None)
return_value: Any = attrs.field(eq=False, order=False, default=None)
+ @classmethod
+ def from_job(
+ cls,
+ job: Job,
+ outcome: JobOutcome,
+ *,
+ finished_at: datetime | None = None,
+ exception: BaseException | None = None,
+ return_value: Any = None,
+ ) -> JobResult:
+ real_finished_at = finished_at or datetime.now(timezone.utc)
+ expires_at = real_finished_at + job.result_expiration_time
+ return cls(
+ job_id=job.id,
+ outcome=outcome,
+ finished_at=real_finished_at,
+ expires_at=expires_at,
+ exception=exception,
+ return_value=return_value,
+ )
+
def marshal(self, serializer: Serializer) -> dict[str, Any]:
marshalled = attrs.asdict(self, value_serializer=serialize)
if self.outcome is JobOutcome.error: