-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo_job_status.py
53 lines (40 loc) · 1.59 KB
/
demo_job_status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
ProActive Job Submission and Monitoring Script
This script demonstrates the end-to-end process of job submission and monitoring using the ProActive Python SDK.
It covers creating a ProActive job, adding a Python task, submitting the job to the ProActive Scheduler, and monitoring the job status until completion.
The script concludes by retrieving and displaying the job's output.
"""
import time
from proactive import getProActiveGateway
gateway = getProActiveGateway()
# Create and configure a ProActive job and task
print("Creating a proactive job...")
job = gateway.createJob("demo_job_status")
print("Creating a proactive task...")
task = gateway.createPythonTask("demo_job_status_task")
task.setTaskImplementation('print("Execution completed")')
print("Adding proactive task to the proactive job...")
job.addTask(task)
# Submit the job to the ProActive scheduler
print("Submitting the job to the proactive scheduler...")
job_id = gateway.submitJob(job)
print(f"Job submitted with ID: {job_id}")
# Monitor job status
is_finished = False
while not is_finished:
# Get the current state of the job
job_status = gateway.getJobStatus(job_id)
# Print the current job status
print(f"Current job status: {job_status}")
# Check if the job has finished
if job_status.upper() in ["FINISHED", "CANCELED", "FAILED"]:
is_finished = True
else:
# Wait for a few seconds before checking again
time.sleep(.5)
# Retrieve and print job results
print("Job output:")
print(gateway.getJobOutput(job_id))
# Cleanup
gateway.close()
print("Disconnected and finished.")