44from utils .environment import ensure_environment_healthy
55
66
7- def create_command (client : Gitpod , environment_id : str , reference : str , name : str , description : str ) -> str :
7+ def create_command (client : Gitpod , environment_id : str , reference : str , name : str , description : str , command : str ) -> str :
88 """
99 Create a task in the given environment.
1010
@@ -20,7 +20,7 @@ def create_command(client: Gitpod, environment_id: str, reference: str, name: st
2020 """
2121 task = client .environments .automations .tasks .create (
2222 spec = {
23- "command" : "echo 'Hello, World!'" ,
23+ "command" : command ,
2424 },
2525 environment_id = environment_id ,
2626 metadata = {
@@ -32,8 +32,24 @@ def create_command(client: Gitpod, environment_id: str, reference: str, name: st
3232 print (f"\n Created task: { task .id } " )
3333 return task .id
3434
35+ def update_command (client : Gitpod , task_id : str , command : str ) -> None :
36+ """
37+ Update the command of an existing task.
38+
39+ Args:
40+ client (Gitpod): The Gitpod client instance.
41+ task_id (str): The task ID.
42+ new_command (str): The new command to set.
43+ """
44+ client .environments .automations .tasks .update (
45+ id = task_id ,
46+ spec = {
47+ "command" : command ,
48+ }
49+ )
50+ print (f"Updated task: { task_id } " )
3551
36- def run_command (client : Gitpod , task_id : str ) -> str :
52+ def start_command (client : Gitpod , task_id : str ) -> str :
3753 """
3854 Start a task execution.
3955
@@ -127,3 +143,25 @@ def stream_command_logs(client: Gitpod, environment_id: str, execution_id: str)
127143
128144 logsAccessToken = client .environments .create_logs_token (environment_id = environment_id ).access_token
129145 asyncio .run (stream_logs (log_url , logsAccessToken ))
146+
147+ def run_command (client : Gitpod , environment_id : str , task_id : str ) -> None :
148+ """
149+ Run a command, stream its logs, and check its status.
150+
151+ Args:
152+ client (Gitpod): The Gitpod client instance.
153+ environment_id (str): The environment ID.
154+ task_id (str): The task ID.
155+ """
156+ # Start command
157+ execution_id = start_command (client , task_id )
158+
159+ # Stream logs
160+ stream_command_logs (client , environment_id , execution_id )
161+
162+ # Check command status
163+ execution = client .environments .automations .tasks .executions .retrieve (id = execution_id ).task_execution
164+ print (f"\n Task execution status: { execution .status .phase } " )
165+ if execution .status .phase == "TASK_EXECUTION_PHASE_FAILED" :
166+ print (f"Task execution failed: { execution .status .failure_message } " )
167+
0 commit comments