4
4
from utils .environment import ensure_environment_healthy
5
5
6
6
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 :
8
8
"""
9
9
Create a task in the given environment.
10
10
@@ -20,7 +20,7 @@ def create_command(client: Gitpod, environment_id: str, reference: str, name: st
20
20
"""
21
21
task = client .environments .automations .tasks .create (
22
22
spec = {
23
- "command" : "echo 'Hello, World!'" ,
23
+ "command" : command ,
24
24
},
25
25
environment_id = environment_id ,
26
26
metadata = {
@@ -32,8 +32,24 @@ def create_command(client: Gitpod, environment_id: str, reference: str, name: st
32
32
print (f"\n Created task: { task .id } " )
33
33
return task .id
34
34
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 } " )
35
51
36
- def run_command (client : Gitpod , task_id : str ) -> str :
52
+ def start_command (client : Gitpod , task_id : str ) -> str :
37
53
"""
38
54
Start a task execution.
39
55
@@ -127,3 +143,25 @@ def stream_command_logs(client: Gitpod, environment_id: str, execution_id: str)
127
143
128
144
logsAccessToken = client .environments .create_logs_token (environment_id = environment_id ).access_token
129
145
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