Skip to content

Commit d2ca31b

Browse files
refactor into task_executor api and runner facade
1 parent 26038ec commit d2ca31b

14 files changed

Lines changed: 417 additions & 367 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `tilebox-workflows`: Added worker runtime mode for executing registered tasks over the worker RPC service, backed by a
13+
shared task executor facade used by both worker and polling runners.
14+
1015
## [0.52.0]
1116

1217
### Added
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:24ff20b8b66a30cf11e5998477066b500830280160eaa5dd1e1c5895ea920a47
3-
size 9032
2+
oid sha256:ede65a3f196290e2aee71cddc45f67c9e9b2c6eb1374bf6beb0b8406f1f4d8c4
3+
size 8923
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:b8081ec6c43e20ee4ef13ff7ae89a24f695cd85e10c0346341d77a9fec5a285f
3-
size 6061
2+
oid sha256:54b3862b1e4c863f27e9f2e29958e3122ea8d197459fdb87e7b3d81ff0373f59
3+
size 5932
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:cac0cd1cd31ec5c62949704159a113d2f69a249c35997eac113a2ac695d196d5
3-
size 4430
2+
oid sha256:432d42a185a620843815a821a9c04617459b351dc873a2dc31101657639d13e0
3+
size 4325
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:3eee76fab8b6018fbba6e0332a8a5a193a1095ceab3e4a0b2e2b586a5d520f9b
3-
size 3526
2+
oid sha256:1260ba9f7798ef3b53a76beac7943ee4857f7c5035c10425702ff121dc64966d
3+
size 3413
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:432fe539191e3c122d88dfe9a9ad7ff4c797df7ab0390c1ab69f454ed8d80858
3-
size 4359
2+
oid sha256:e30083e0e53ed859997e01bf4abdd1c06d873ab3ac96f84497778e7d267d8481
3+
size 4258

tilebox-workflows/tilebox/workflows/client.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import os
33
import warnings
4-
from uuid import uuid4
4+
from uuid import UUID, uuid4
55

66
from _tilebox.grpc.channel import open_channel, parse_channel_info
77
from tilebox.workflows.automations.client import AutomationClient, AutomationService
@@ -21,6 +21,7 @@
2121
_create_tilebox_logger_provider,
2222
)
2323
from tilebox.workflows.observability.tracing import WorkflowTracer
24+
from tilebox.workflows.runner.executor import LazyStorageLocations
2425
from tilebox.workflows.runner.runner import Runner
2526
from tilebox.workflows.runner.task_runner import TaskRunner, _LeaseRenewer
2627
from tilebox.workflows.runner.task_service import TaskService
@@ -29,7 +30,12 @@
2930

3031
class Client:
3132
def __init__(
32-
self, *, url: str = "https://api.tilebox.com", token: str | None = None, name: str | None = None
33+
self,
34+
*,
35+
url: str = "https://api.tilebox.com",
36+
token: str | None = None,
37+
name: str | None = None,
38+
client_id: UUID | None = None,
3339
) -> None:
3440
"""
3541
Create a Tilebox workflows client.
@@ -40,13 +46,14 @@ def __init__(
4046
name: An optional name of the client, used as service.name for telemetry. If not set, defaults to
4147
the service name provided by `tilebox.workflows.observability.tracing.configure_otel_tracing`,
4248
or "tilebox-python" if no external tracer is configured.
49+
client_id: An optional stable id used to scope internal loggers. Defaults to a random id.
4350
"""
4451
token = _token_from_env(url, token)
4552
self._auth: dict[str, str] = {"token": token, "url": url}
4653
self._channel = open_channel(url, token)
4754

4855
# configure logging and tracing
49-
self._client_id = uuid4() # a random uuid to scope loggers to this client instance
56+
self._client_id = client_id or uuid4() # a random uuid to scope loggers to this client instance
5057
self._logger_provider = _create_tilebox_logger_provider(service=name, url=url, token=token)
5158

5259
# task logger is the logger available for users to emit logs from within a Task.execute method, via
@@ -134,18 +141,9 @@ def runner(
134141

135142
found_cluster = self.clusters().find(to_cluster_slug(cluster or ""))
136143

137-
try:
138-
storage_locations = self.automations().storage_locations()
139-
except: # noqa: E722
140-
# if fetching storage locations fails, we just disable this feature, and don't crash all runners
141-
# lets refactor this to a lazy loading mechanism in the future
142-
storage_locations = []
143-
144144
runner_context_type = runner_definition.context or RunnerContext
145-
runner_context = runner_context_type(
146-
self._tracer,
147-
storage_locations=storage_locations,
148-
)
145+
runner_context = runner_context_type(self._tracer)
146+
runner_context.storage_locations = LazyStorageLocations(self, runner_context)
149147

150148
task_runner = TaskRunner(
151149
TaskService(self._channel),

0 commit comments

Comments
 (0)