Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: with_worker_type #904

Merged
merged 1 commit into from
Feb 14, 2025
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: 2 additions & 2 deletions tests/unit/mazepa/maker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from zetta_utils.mazepa.tasks import _TaskableOperation


def make_test_task(fn, id_, worker_type=None, operation_name="DummyTask"): # TODO: type me
def make_test_task(fn, id_, operation_name="DummyTask"): # TODO: type me
return _TaskableOperation(
fn=fn, operation_name=operation_name, id_fn=get_literal_id_fn(id_), worker_type=worker_type
fn=fn, operation_name=operation_name, id_fn=get_literal_id_fn(id_)
).make_task()


Expand Down
6 changes: 3 additions & 3 deletions tests/unit/mazepa/test_task_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def test_push_tasks(mocker):
queue_a.name = "_type_a"
queue_b.name = "_type_b"
meq = TaskRouter([queue_a, queue_b])
task_a = make_test_task(lambda: None, id_="dummy", worker_type="type_a")
task_b = make_test_task(lambda: None, "dummy", worker_type="type_b")
task_bb = make_test_task(lambda: None, "dummy", worker_type="type_b")
task_a = make_test_task(lambda: None, id_="dummy").with_worker_type("type_a")
task_b = make_test_task(lambda: None, "dummy").with_worker_type("type_b")
task_bb = make_test_task(lambda: None, "dummy").with_worker_type("type_b")
meq.push([task_a, task_b, task_bb])
queue_a.push.assert_called_with([task_a])
queue_b.push.assert_called_with([task_b, task_bb])
Expand Down
5 changes: 3 additions & 2 deletions zetta_utils/mazepa/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def _set_up(self, *args: Iterable, **kwargs: dict):
self.args = args
self.kwargs = kwargs

def with_worker_type(self, worker_type: str | None) -> Task:
return attrs.evolve(self, worker_type=worker_type)

def _call_task_fn(self, debug: bool = True) -> R_co:
if debug or self.runtime_limit_sec is None:
return_value = self.fn(*self.args, **self.kwargs)
Expand Down Expand Up @@ -172,7 +175,6 @@ class _TaskableOperation(Generic[P, R_co]):
id_fn: Callable[[Callable, list, dict], str] = attrs.field(
default=functools.partial(id_generation.generate_invocation_id, prefix="task")
)
worker_type: str | None = None
runtime_limit_sec: float | None = None
upkeep_interval_sec: float = constants.DEFAULT_UPKEEP_INTERVAL

Expand All @@ -197,7 +199,6 @@ def make_task(
fn=self.fn,
operation_name=self.operation_name,
id_=id_,
worker_type=self.worker_type,
upkeep_settings=upkeep_settings,
runtime_limit_sec=self.runtime_limit_sec,
)
Expand Down
Loading