Skip to content

Commit 4803af6

Browse files
committed
add message arg on task run
1 parent 6fdd8b0 commit 4803af6

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

docs/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

waldiez_runner/routes/v1/task_jobs.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ async def trigger_run_task(
2323
storage: Storage,
2424
env_vars: dict[str, str],
2525
skip_deps: bool | None = None,
26+
message: str | None = None,
2627
) -> None:
2728
"""Trigger a task.
2829
@@ -38,6 +39,9 @@ async def trigger_run_task(
3839
The environment variables for the task
3940
skip_deps : bool, Optional
4041
Whether to skip installing dependencies before the task.
42+
message : str, Optional
43+
Optional initial message to pass to the task.
44+
4145
Raises
4246
------
4347
RuntimeError
@@ -55,6 +59,7 @@ async def trigger_run_task(
5559
storage=storage,
5660
redis_manager=app_state.redis,
5761
skip_deps=skip_deps,
62+
message=message,
5863
)
5964
)
6065
bg_task.add_done_callback(
@@ -66,7 +71,10 @@ async def trigger_run_task(
6671
)
6772
else:
6873
await run_task_job.kiq(
69-
task=task, env_vars=env_vars, skip_deps=skip_deps
74+
task=task,
75+
env_vars=env_vars,
76+
skip_deps=skip_deps,
77+
message=message,
7078
)
7179

7280

@@ -120,6 +128,7 @@ async def schedule_task(
120128
storage: Storage,
121129
env_vars: dict[str, str],
122130
skip_deps: bool | None = None,
131+
message: str | None = None,
123132
) -> None:
124133
"""Schedule a task.
125134
@@ -135,6 +144,8 @@ async def schedule_task(
135144
The environment variables for the task.
136145
skip_deps : bool, Optional
137146
Whether to skip installing dependencies before the task.
147+
message : str
148+
Optional initial message to pass to the task.
138149
139150
Raises
140151
------

waldiez_runner/routes/v1/task_router.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ async def create_task(
202202
),
203203
input_timeout: int = Form(180),
204204
skip_deps: bool | None = Form(None),
205+
message: str | None = Form(None),
205206
schedule_type: Literal["once", "cron"] | None = Form(None),
206207
scheduled_time: datetime | None = Form(None),
207208
cron_expression: str | None = Form(None),
@@ -234,6 +235,8 @@ async def create_task(
234235
The timeout for input requests, by default 180
235236
skip_deps : bool, optional
236237
Whether to skip installing dependencies before the task.
238+
message : str, optional
239+
Optional initial message to pass to the task.
237240
schedule_type : Optional[Literal["once", "cron"]], optional
238241
The type of schedule, by default None
239242
scheduled_time : Optional[datetime], optional
@@ -337,6 +340,7 @@ async def create_task(
337340
db_manager=db_manager,
338341
storage=storage,
339342
skip_deps=skip_deps,
343+
message=message,
340344
)
341345
if task.schedule_type is not None:
342346
await schedule_task(
@@ -345,6 +349,7 @@ async def create_task(
345349
storage=storage,
346350
env_vars=environment_vars,
347351
skip_deps=skip_deps,
352+
message=message,
348353
)
349354
return task_response
350355

waldiez_runner/tasks/runner.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# SPDX-License-Identifier: Apache-2.0.
22
# Copyright (c) 2024 - 2026 Waldiez and contributors.
33

4-
# pylint: disable=broad-exception-caught, unused-argument
4+
# pylint: disable=broad-exception-caught,unused-argument
5+
# pylint: disable=too-many-arguments,too-many-positional-arguments
6+
57
"""Handle running the task in a virtual environment."""
68

79
import asyncio
@@ -42,6 +44,7 @@ async def execute_task(
4244
debug: bool,
4345
max_duration: int,
4446
skip_deps: bool,
47+
message: str,
4548
) -> tuple[TaskStatus, dict[str, Any] | list[dict[str, Any]] | None]:
4649
"""Execute the task in a virtual environment.
4750
@@ -69,6 +72,8 @@ async def execute_task(
6972
The task's max duration.
7073
skip_deps : bool
7174
Whether to skip installing dependencies before the task.
75+
message : str
76+
Optional initial message to pass to the task.
7277
7378
Returns
7479
-------
@@ -90,6 +95,7 @@ async def execute_task(
9095
debug=debug,
9196
max_duration=max_duration,
9297
skip_deps=skip_deps,
98+
message=message,
9399
)
94100
LOG.info("Task %s exited with code %s", task.id, exit_code)
95101
return interpret_exit_code(exit_code)
@@ -266,6 +272,7 @@ async def run_app_in_venv(
266272
debug: bool,
267273
max_duration: int,
268274
skip_deps: bool,
275+
message: str,
269276
) -> int:
270277
"""Run the app in the venv.
271278
@@ -295,6 +302,8 @@ async def run_app_in_venv(
295302
The task's max duration.
296303
skip_deps : bool
297304
Whether to skip installing deps before the task.
305+
message : str
306+
Optional initial message to pass to the task.
298307
299308
Returns
300309
-------
@@ -317,6 +326,8 @@ async def run_app_in_venv(
317326
skip_arg,
318327
str(file_path),
319328
]
329+
if message:
330+
args.extend(["--message", message])
320331
if debug:
321332
args.append("--debug")
322333

waldiez_runner/tasks/running.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async def run_task(
3535
task: TaskResponse,
3636
env_vars: dict[str, str],
3737
skip_deps: bool | None = None,
38+
message: str | None = None,
3839
db_manager: DatabaseManager = TaskiqDepends(get_db_manager),
3940
storage: Storage = TaskiqDepends(get_storage),
4041
redis_manager: RedisManager = TaskiqDepends(get_redis_manager),
@@ -49,6 +50,8 @@ async def run_task(
4950
Environment variables for the task.
5051
skip_deps : bool, Optional
5152
Whether to skip installing dependencies before the task.
53+
message : str
54+
Optional initial message to pass to the task.
5255
db_manager : DatabaseManager
5356
Database session manager dependency.
5457
storage : Storage
@@ -99,6 +102,7 @@ async def run_task(
99102
debug=debug,
100103
max_duration=settings.max_task_duration,
101104
skip_deps=skip_deps is True,
105+
message=message or "",
102106
)
103107
LOG.info("Task %s finished with status %s", task.id, status.value)
104108
LOG.debug("Task %s finished with results %s", task.id, results)

0 commit comments

Comments
 (0)