Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit cb251eb

Browse files
committed
fix: lint
1 parent 495622c commit cb251eb

File tree

5 files changed

+58
-64
lines changed

5 files changed

+58
-64
lines changed

examples/api/async_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
async def main() -> None:
9-
workflow_list = await hatchet.rest.aio.workflow_list()
9+
workflow_list = await hatchet.rest.aio_list_workflows()
1010
rows = workflow_list.rows or []
1111

1212
for workflow in rows:

examples/api/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ async def test_list_workflows(hatchet: Hatchet, worker: Worker) -> None:
1717
@pytest.mark.parametrize("worker", ["concurrency_limit_rr"], indirect=True)
1818
@pytest.mark.asyncio(scope="session")
1919
async def test_async_list_workflows(aiohatchet: Hatchet, worker: Worker) -> None:
20-
workflows = await aiohatchet.rest.aio.workflow_list()
20+
workflows = await aiohatchet.rest.aio_list_workflows()
2121

2222
assert len(workflows.rows or []) != 0

hatchet_sdk/clients/rest_client.py

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
S = TypeVar("S")
8686

8787

88-
class AsyncRestApi:
88+
class RestApi:
8989
def __init__(self, host: str, api_key: str, tenant_id: str):
9090
self.tenant_id = tenant_id
9191

@@ -101,6 +101,13 @@ def __init__(self, host: str, api_key: str, tenant_id: str):
101101
self._event_api: EventApi | None = None
102102
self._log_api: LogApi | None = None
103103

104+
self._loop = asyncio.new_event_loop()
105+
self._thread = threading.Thread(target=self._run_event_loop, daemon=True)
106+
self._thread.start()
107+
108+
# Register the cleanup method to be called on exit
109+
atexit.register(self._cleanup)
110+
104111
@property
105112
def api_client(self) -> ApiClient:
106113
if self._api_client is None:
@@ -142,25 +149,25 @@ async def close(self) -> None:
142149
if self._api_client is not None:
143150
await self._api_client.close()
144151

145-
async def workflow_list(self) -> WorkflowList:
152+
async def aio_list_workflows(self) -> WorkflowList:
146153
return await self.workflow_api.workflow_list(
147154
tenant=self.tenant_id,
148155
)
149156

150-
async def workflow_get(self, workflow_id: str) -> Workflow:
157+
async def aio_get_workflow(self, workflow_id: str) -> Workflow:
151158
return await self.workflow_api.workflow_get(
152159
workflow=workflow_id,
153160
)
154161

155-
async def workflow_version_get(
162+
async def aio_get_workflow_version(
156163
self, workflow_id: str, version: str | None = None
157164
) -> WorkflowVersion:
158165
return await self.workflow_api.workflow_version_get(
159166
workflow=workflow_id,
160167
version=version,
161168
)
162169

163-
async def workflow_run_list(
170+
async def aio_list_workflow_runs(
164171
self,
165172
workflow_id: str | None = None,
166173
offset: int | None = None,
@@ -189,13 +196,13 @@ async def workflow_run_list(
189196
order_by_direction=order_by_direction,
190197
)
191198

192-
async def workflow_run_get(self, workflow_run_id: str) -> WorkflowRun:
199+
async def aio_get_workflow_run(self, workflow_run_id: str) -> WorkflowRun:
193200
return await self.workflow_api.workflow_run_get(
194201
tenant=self.tenant_id,
195202
workflow_run=workflow_run_id,
196203
)
197204

198-
async def workflow_run_replay(
205+
async def aio_replay_workflow_run(
199206
self, workflow_run_ids: list[str]
200207
) -> ReplayWorkflowRunsResponse:
201208
return await self.workflow_run_api.workflow_run_update_replay(
@@ -205,7 +212,7 @@ async def workflow_run_replay(
205212
),
206213
)
207214

208-
async def workflow_run_cancel(
215+
async def aio_cancel_workflow_run(
209216
self, workflow_run_id: str
210217
) -> EventUpdateCancel200Response:
211218
return await self.workflow_run_api.workflow_run_cancel(
@@ -215,7 +222,7 @@ async def workflow_run_cancel(
215222
),
216223
)
217224

218-
async def workflow_run_bulk_cancel(
225+
async def aio_bulk_cancel_workflow_runs(
219226
self, workflow_run_ids: list[str]
220227
) -> EventUpdateCancel200Response:
221228
return await self.workflow_run_api.workflow_run_cancel(
@@ -225,7 +232,7 @@ async def workflow_run_bulk_cancel(
225232
),
226233
)
227234

228-
async def workflow_run_create(
235+
async def aio_create_workflow_run(
229236
self,
230237
workflow_id: str,
231238
input: JSONSerializableDict,
@@ -241,7 +248,7 @@ async def workflow_run_create(
241248
),
242249
)
243250

244-
async def cron_create(
251+
async def aio_create_cron(
245252
self,
246253
workflow_name: str,
247254
cron_name: str,
@@ -260,13 +267,13 @@ async def cron_create(
260267
),
261268
)
262269

263-
async def cron_delete(self, cron_trigger_id: str) -> None:
270+
async def aio_delete_cron(self, cron_trigger_id: str) -> None:
264271
await self.workflow_api.workflow_cron_delete(
265272
tenant=self.tenant_id,
266273
cron_workflow=cron_trigger_id,
267274
)
268275

269-
async def cron_list(
276+
async def aio_list_crons(
270277
self,
271278
offset: StrictInt | None = None,
272279
limit: StrictInt | None = None,
@@ -285,13 +292,13 @@ async def cron_list(
285292
order_by_direction=order_by_direction,
286293
)
287294

288-
async def cron_get(self, cron_trigger_id: str) -> CronWorkflows:
295+
async def aio_get_cron(self, cron_trigger_id: str) -> CronWorkflows:
289296
return await self.workflow_api.workflow_cron_get(
290297
tenant=self.tenant_id,
291298
cron_workflow=cron_trigger_id,
292299
)
293300

294-
async def schedule_create(
301+
async def aio_create_schedule(
295302
self,
296303
name: str,
297304
trigger_at: datetime.datetime,
@@ -308,13 +315,13 @@ async def schedule_create(
308315
),
309316
)
310317

311-
async def schedule_delete(self, scheduled_trigger_id: str) -> None:
318+
async def aio_delete_schedule(self, scheduled_trigger_id: str) -> None:
312319
await self.workflow_api.workflow_scheduled_delete(
313320
tenant=self.tenant_id,
314321
scheduled_workflow_run=scheduled_trigger_id,
315322
)
316323

317-
async def schedule_list(
324+
async def aio_list_schedule(
318325
self,
319326
offset: StrictInt | None = None,
320327
limit: StrictInt | None = None,
@@ -337,13 +344,13 @@ async def schedule_list(
337344
order_by_direction=order_by_direction,
338345
)
339346

340-
async def schedule_get(self, scheduled_trigger_id: str) -> ScheduledWorkflows:
347+
async def aio_get_schedule(self, scheduled_trigger_id: str) -> ScheduledWorkflows:
341348
return await self.workflow_api.workflow_scheduled_get(
342349
tenant=self.tenant_id,
343350
scheduled_workflow_run=scheduled_trigger_id,
344351
)
345352

346-
async def list_logs(
353+
async def aio_list_logs(
347354
self,
348355
step_run_id: str,
349356
offset: int | None = None,
@@ -363,7 +370,7 @@ async def list_logs(
363370
order_by_direction=order_by_direction,
364371
)
365372

366-
async def events_list(
373+
async def aio_list_events(
367374
self,
368375
offset: int | None = None,
369376
limit: int | None = None,
@@ -388,7 +395,7 @@ async def events_list(
388395
additional_metadata=additional_metadata,
389396
)
390397

391-
async def events_replay(self, event_ids: list[str] | EventList) -> EventList:
398+
async def aio_replay_events(self, event_ids: list[str] | EventList) -> EventList:
392399
if isinstance(event_ids, EventList):
393400
rows = event_ids.rows or []
394401
event_ids = [r.metadata.id for r in rows]
@@ -398,24 +405,11 @@ async def events_replay(self, event_ids: list[str] | EventList) -> EventList:
398405
replay_event_request=ReplayEventRequest(eventIds=event_ids),
399406
)
400407

401-
402-
class RestApi:
403-
def __init__(self, host: str, api_key: str, tenant_id: str):
404-
self._loop = asyncio.new_event_loop()
405-
self._thread = threading.Thread(target=self._run_event_loop, daemon=True)
406-
self._thread.start()
407-
408-
# Initialize AsyncRestApi inside the event loop to ensure an active loop
409-
self.aio = AsyncRestApi(host, api_key, tenant_id)
410-
411-
# Register the cleanup method to be called on exit
412-
atexit.register(self._cleanup)
413-
414408
def _cleanup(self) -> None:
415409
"""
416410
Stop the running thread and clean up the event loop.
417411
"""
418-
self._run_coroutine(self.aio.close())
412+
self._run_coroutine(self.close())
419413
self._loop.call_soon_threadsafe(self._loop.stop)
420414
self._thread.join()
421415

@@ -434,15 +428,15 @@ def _run_coroutine(self, coro: Coroutine[Y, S, R]) -> R:
434428
return future.result()
435429

436430
def workflow_list(self) -> WorkflowList:
437-
return self._run_coroutine(self.aio.workflow_list())
431+
return self._run_coroutine(self.aio_list_workflows())
438432

439433
def workflow_get(self, workflow_id: str) -> Workflow:
440-
return self._run_coroutine(self.aio.workflow_get(workflow_id))
434+
return self._run_coroutine(self.aio_get_workflow(workflow_id))
441435

442436
def workflow_version_get(
443437
self, workflow_id: str, version: str | None = None
444438
) -> WorkflowVersion:
445-
return self._run_coroutine(self.aio.workflow_version_get(workflow_id, version))
439+
return self._run_coroutine(self.aio_get_workflow_version(workflow_id, version))
446440

447441
def workflow_run_list(
448442
self,
@@ -459,7 +453,7 @@ def workflow_run_list(
459453
order_by_direction: WorkflowRunOrderByDirection | None = None,
460454
) -> WorkflowRunList:
461455
return self._run_coroutine(
462-
self.aio.workflow_run_list(
456+
self.aio_list_workflow_runs(
463457
workflow_id=workflow_id,
464458
offset=offset,
465459
limit=limit,
@@ -475,15 +469,15 @@ def workflow_run_list(
475469
)
476470

477471
def workflow_run_get(self, workflow_run_id: str) -> WorkflowRun:
478-
return self._run_coroutine(self.aio.workflow_run_get(workflow_run_id))
472+
return self._run_coroutine(self.aio_get_workflow_run(workflow_run_id))
479473

480474
def workflow_run_cancel(self, workflow_run_id: str) -> EventUpdateCancel200Response:
481-
return self._run_coroutine(self.aio.workflow_run_cancel(workflow_run_id))
475+
return self._run_coroutine(self.aio_cancel_workflow_run(workflow_run_id))
482476

483477
def workflow_run_bulk_cancel(
484478
self, workflow_run_ids: list[str]
485479
) -> EventUpdateCancel200Response:
486-
return self._run_coroutine(self.aio.workflow_run_bulk_cancel(workflow_run_ids))
480+
return self._run_coroutine(self.aio_bulk_cancel_workflow_runs(workflow_run_ids))
487481

488482
def workflow_run_create(
489483
self,
@@ -493,7 +487,7 @@ def workflow_run_create(
493487
additional_metadata: JSONSerializableDict = {},
494488
) -> WorkflowRun:
495489
return self._run_coroutine(
496-
self.aio.workflow_run_create(
490+
self.aio_create_workflow_run(
497491
workflow_id, input, version, additional_metadata
498492
)
499493
)
@@ -507,13 +501,13 @@ def cron_create(
507501
additional_metadata: JSONSerializableDict,
508502
) -> CronWorkflows:
509503
return self._run_coroutine(
510-
self.aio.cron_create(
504+
self.aio_create_cron(
511505
workflow_name, cron_name, expression, input, additional_metadata
512506
)
513507
)
514508

515509
def cron_delete(self, cron_trigger_id: str) -> None:
516-
self._run_coroutine(self.aio.cron_delete(cron_trigger_id))
510+
self._run_coroutine(self.aio_delete_cron(cron_trigger_id))
517511

518512
def cron_list(
519513
self,
@@ -525,7 +519,7 @@ def cron_list(
525519
order_by_direction: WorkflowRunOrderByDirection | None = None,
526520
) -> CronWorkflowsList:
527521
return self._run_coroutine(
528-
self.aio.cron_list(
522+
self.aio_list_crons(
529523
offset,
530524
limit,
531525
workflow_id,
@@ -536,7 +530,7 @@ def cron_list(
536530
)
537531

538532
def cron_get(self, cron_trigger_id: str) -> CronWorkflows:
539-
return self._run_coroutine(self.aio.cron_get(cron_trigger_id))
533+
return self._run_coroutine(self.aio_get_cron(cron_trigger_id))
540534

541535
def schedule_create(
542536
self,
@@ -546,13 +540,13 @@ def schedule_create(
546540
additional_metadata: JSONSerializableDict,
547541
) -> ScheduledWorkflows:
548542
return self._run_coroutine(
549-
self.aio.schedule_create(
543+
self.aio_create_schedule(
550544
workflow_name, trigger_at, input, additional_metadata
551545
)
552546
)
553547

554548
def schedule_delete(self, scheduled_trigger_id: str) -> None:
555-
self._run_coroutine(self.aio.schedule_delete(scheduled_trigger_id))
549+
self._run_coroutine(self.aio_delete_schedule(scheduled_trigger_id))
556550

557551
def schedule_list(
558552
self,
@@ -564,7 +558,7 @@ def schedule_list(
564558
order_by_direction: WorkflowRunOrderByDirection | None = None,
565559
) -> ScheduledWorkflowsList:
566560
return self._run_coroutine(
567-
self.aio.schedule_list(
561+
self.aio_list_schedule(
568562
offset,
569563
limit,
570564
workflow_id,
@@ -575,7 +569,7 @@ def schedule_list(
575569
)
576570

577571
def schedule_get(self, scheduled_trigger_id: str) -> ScheduledWorkflows:
578-
return self._run_coroutine(self.aio.schedule_get(scheduled_trigger_id))
572+
return self._run_coroutine(self.aio_get_schedule(scheduled_trigger_id))
579573

580574
def list_logs(
581575
self,
@@ -588,7 +582,7 @@ def list_logs(
588582
order_by_direction: LogLineOrderByDirection | None = None,
589583
) -> LogLineList:
590584
return self._run_coroutine(
591-
self.aio.list_logs(
585+
self.aio_list_logs(
592586
step_run_id=step_run_id,
593587
offset=offset,
594588
limit=limit,
@@ -612,7 +606,7 @@ def events_list(
612606
additional_metadata: list[str] | None = None,
613607
) -> EventList:
614608
return self._run_coroutine(
615-
self.aio.events_list(
609+
self.aio_list_events(
616610
offset=offset,
617611
limit=limit,
618612
keys=keys,
@@ -626,4 +620,4 @@ def events_list(
626620
)
627621

628622
def events_replay(self, event_ids: list[str] | EventList) -> EventList:
629-
return self._run_coroutine(self.aio.events_replay(event_ids))
623+
return self._run_coroutine(self.aio_replay_events(event_ids))

0 commit comments

Comments
 (0)