Skip to content

Commit

Permalink
Test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomperez98 committed Jan 27, 2025
1 parent eb2f272 commit afb8f3c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
17 changes: 15 additions & 2 deletions src/resonate/resonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,28 @@ def register(
(func, Options(version=version, durable=True, retry_policy=retry_policy)),
)

def fn(
def __call__(
self,
name: str | None = None,
version: int = 1,
retry_policy: retry_policy.RetryPolicy | None = None,
) -> Callable[
[Callable[Concatenate[Context, P], Any]],
RegisteredFn[P, Any],
]: ...
]:
def wrapper(
func: Callable[Concatenate[Context, P], Any],
) -> RegisteredFn[P, Any]:
self._registry.add(
name or func.__name__,
(
func,
Options(version=version, durable=True, retry_policy=retry_policy),
),
)
return RegisteredFn(self._scheduler, func)

return wrapper

@overload
def run(
Expand Down
16 changes: 8 additions & 8 deletions tests/test_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def test_golden_device_rfi_and_lfc_with_decorator() -> None:
task_source=Poller("http://localhost:8002", group=group),
)

@resonate.fn()
@resonate()
def foo(ctx: Context, n: str) -> Generator[Yieldable, Any, str]:
v: str = yield ctx.lfc(bar, n).options(
id="bar",
Expand All @@ -472,7 +472,7 @@ def bar(ctx: Context, n: str) -> Generator[Yieldable, Any, str]:
v: str = yield p
return v

@resonate.fn()
@resonate()
def baz(ctx: Context, n: str) -> str: # noqa: ARG001
return n

Expand Down Expand Up @@ -611,7 +611,7 @@ def test_golden_device_rfc_and_lfc_with_decorator() -> None:
task_source=Poller("http://localhost:8002", group=group),
)

@resonate.fn()
@resonate()
def foo(ctx: Context, n: str) -> Generator[Yieldable, Any, str]:
v: str = yield ctx.lfc(bar, n).options(
id="bar",
Expand All @@ -623,7 +623,7 @@ def bar(ctx: Context, n: str) -> Generator[Yieldable, Any, str]:
v: str = yield ctx.rfc(baz, n).options(id="baz", send_to=poll(group))
return v

@resonate.fn()
@resonate()
def baz(ctx: Context, n: str) -> str: # noqa: ARG001
return n

Expand Down Expand Up @@ -734,7 +734,7 @@ def test_sleep() -> None:
store=store, task_source=Poller("http://localhost:8002", group=group)
)

@resonate.fn()
@resonate()
def foo_sleep(ctx: Context, n: int) -> Generator[Yieldable, Any, int]:
yield ctx.sleep(n)
return n
Expand Down Expand Up @@ -794,7 +794,7 @@ def test_golden_device_detached_with_registered() -> None:
task_source=Poller("http://localhost:8002", group=group),
)

@resonate.fn()
@resonate()
def foo_golden_device_detached_with_registered(
ctx: Context, n: str
) -> Generator[Yieldable, Any, str]:
Expand All @@ -807,11 +807,11 @@ def foo_golden_device_detached_with_registered(
v: str = yield p
return v

@resonate.fn()
@resonate()
def bar_golden_device_detached_with_registered(ctx: Context, n: str) -> str: # noqa: ARG001
return n

@resonate.fn()
@resonate()
def baz_golden_device_detached_with_registered(
ctx: Context, # noqa: ARG001
promise_id: str,
Expand Down

0 comments on commit afb8f3c

Please sign in to comment.