Skip to content
Closed
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
14 changes: 13 additions & 1 deletion src/cashet/_client_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import os
from collections.abc import Callable
from collections.abc import Callable, Mapping
from datetime import timedelta
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -55,6 +55,18 @@ def resolve_task_config(
return raw_func, cache, tags, retries, force, timeout, ttl


def resolve_submit_options(
data: Mapping[str, Any],
) -> tuple[bool, dict[str, str], int, bool, Any, Any]:
cache = data.get("cache", True)
tags = data.get("tags", {})
retries = data.get("retries", 0)
force = data.get("force", False)
timeout = data.get("timeout")
ttl = data.get("ttl")
return cache, tags, retries, force, timeout, ttl


def set_task_metadata(
func: Callable[..., Any],
task_name: str,
Expand Down
15 changes: 3 additions & 12 deletions src/cashet/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from starlette.responses import JSONResponse
from starlette.routing import Route

from cashet._client_base import resolve_submit_options
from cashet.async_client import AsyncClient
from cashet.client import Client

Expand Down Expand Up @@ -198,12 +199,7 @@ async def _async_submit(request: Request) -> JSONResponse:
if error is not None:
return error

cache = data.get("cache", True)
tags = data.get("tags", {})
retries = data.get("retries", 0)
force = data.get("force", False)
timeout = data.get("timeout")
ttl = data.get("ttl")
cache, tags, retries, force, timeout, ttl = resolve_submit_options(data)

start = time.perf_counter()
try:
Expand Down Expand Up @@ -404,12 +400,7 @@ async def _submit(request: Request) -> JSONResponse:
if error is not None:
return error

cache = data.get("cache", True)
tags = data.get("tags", {})
retries = data.get("retries", 0)
force = data.get("force", False)
timeout = data.get("timeout")
ttl = data.get("ttl")
cache, tags, retries, force, timeout, ttl = resolve_submit_options(data)

start = time.perf_counter()

Expand Down
9 changes: 9 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ def test_submit_internal_error_is_generic(self, tmp_path: Path) -> None:
assert response.json()["error"] == "Internal server error"
assert "secret internal path" not in response.text

def test_submit_cache_false_creates_new_commit(self, server_client: TestClient) -> None:
payload = {"task": "add", "args": [3, 4], "cache": False}
first = server_client.post("/submit", json=payload)
second = server_client.post("/submit", json=payload)

assert first.status_code == 200
assert second.status_code == 200
assert first.json()["commit_hash"] != second.json()["commit_hash"]


class TestAsyncServerSubmit:
async def test_async_submit_registered_task_with_sqlite(self, tmp_path: Path) -> None:
Expand Down
Loading