Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/fluxqueue-worker/scripts/get_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from fluxqueue import Context


def get_registry(module_path: str, queue: str, module_dir: str | None = None):
def get_registry( # noqa: C901
module_path: str, queue: str, module_dir: str | None = None
):
if module_dir:
module_dir_path = Path(module_dir).resolve()
if str(module_dir_path) not in sys.path:
Expand Down
6 changes: 5 additions & 1 deletion crates/fluxqueue-worker/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ impl TaskRegistry {

pub fn get_registered_contexts(&self) -> Result<Vec<String>> {
let contexts = self.contexts.read().map_err(|e| anyhow!(e.to_string()))?;
let context_names: Vec<_> = contexts.iter().map(|t| t.0.to_string()).collect();
let context_names: Vec<_> = contexts
.iter()
.filter(|(name, _)| name.as_str() != "_Context")
.map(|(name, _)| name.to_string())
.collect();
Ok(context_names)
}

Expand Down
15 changes: 10 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ manifest-path = "crates/fluxqueue-core/Cargo.toml"

[tool.ruff]
line-length = 88
target-version = "py311"

[tool.ruff.lint]
select = [
Expand All @@ -73,9 +74,13 @@ select = [
"RUF", # ruff-specific rules
]
ignore = [
"E501", # line too long, handled by black
"B008", # do not perform function calls in argument defaults
"C901", # complexity
"N806", # variable in function should be lowercase (allows CamelCase for pydantic models)
"E501", # line too long
]
exclude = [".git", ".ruff_cache", ".venv"]

exclude = [
".git",
".ruff_cache",
".venv",
"dist",
"build",
]
7 changes: 3 additions & 4 deletions python/fluxqueue/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,14 @@ async def session_context(self):
await session.rollback()
raise


@fluxqueue.task_with_context()
async def create_user_task(ctx: DbContext, email: str, username: str):
async with ctx.session_context() as db_session:
user = User(
email=email,
username=username
)
user = User(email=email, username=username)
db_session.add(user)


await create_user_task
```
"""
Expand Down
10 changes: 8 additions & 2 deletions python/fluxqueue/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from datetime import datetime


@dataclass(slots=True)
Expand All @@ -13,5 +14,10 @@ class TaskMetadata:
"""Number of times this task has been retried."""
max_retries: int
"""Maximum number of retry attempts allowed before failure."""
enqueued_at: int
"""ISO 8601 timestamp of when the task was originally enqueued."""
_enqueued_at: int
"""Unix timestamp in seconds."""

@property
def enqueued_at(self):
"""ISO 8601 timestamp of when the task was originally enqueued."""
return datetime.fromtimestamp(self._enqueued_at)