-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Give
riverqueue.Job
fully defined properties + timestamps as UTC (#26)
Previously, the internal sqlc `RiverJob` row was fully typed by virtue of being generated by sqlc, but the `riverqueue.Job` type was undefined, with typechecks working by using a `cast`. Here, give `riverqueue.Job` a full set of defined properties. This is better for things like conveying type information and autocomplete, but has a few other side benefits: * Make sure to return all timestamps as UTC. Previously, they'd be in whatever your local timezone is. * Give some fields like `args`, `metadata`, and `state` better types (the first two were previously `Any`). Lastly, modify `InsertResult` somewhat to make `job` non-optional since it's always returned, even if insert was skipped, because if it was we look it up via select query.
- Loading branch information
Showing
6 changed files
with
113 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Optional | ||
import datetime | ||
from enum import Enum | ||
from typing import Any, Optional | ||
|
||
|
||
class JobState(str, Enum): | ||
AVAILABLE = "available" | ||
CANCELLED = "cancelled" | ||
COMPLETED = "completed" | ||
DISCARDED = "discarded" | ||
PENDING = "pending" | ||
RETRYABLE = "retryable" | ||
RUNNING = "running" | ||
SCHEDULED = "scheduled" | ||
|
||
|
||
@dataclass | ||
class InsertResult: | ||
job: Optional["Job"] = field(default=None) | ||
job: "Job" | ||
unique_skipped_as_duplicated: bool = field(default=False) | ||
|
||
|
||
@dataclass | ||
class Job: | ||
pass | ||
id: int | ||
args: dict[str, Any] | ||
attempt: int | ||
attempted_at: Optional[datetime.datetime] | ||
attempted_by: Optional[list[str]] | ||
created_at: datetime.datetime | ||
errors: Optional[list[Any]] | ||
finalized_at: Optional[datetime.datetime] | ||
kind: str | ||
max_attempts: int | ||
metadata: dict[str, Any] | ||
priority: int | ||
queue: str | ||
state: JobState | ||
scheduled_at: datetime.datetime | ||
tags: list[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters