-
Notifications
You must be signed in to change notification settings - Fork 9
/
boinc2docker_runner.py
66 lines (44 loc) · 2 KB
/
boinc2docker_runner.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
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
BASICS
Reads the MySQL database and submits the jobs that have not been done yet to
the boinc2docker application
"""
import datetime
import mysql.connector as mysql_con
import os
import pytz
import subprocess as sp
# Returns the UTC datetime (UTC)
def timnow_dt():
return datetime.datetime.utcnow()
# Converts from timezone tz1 to timezone tz2
# Returns a datetime object
def convert_datetime_timezone(dt):
UTC_tz = pytz.timezone("UTC")
dt1 = UTC_tz.localize(dt)
dt1 = dt1.astimezone(pytz.timezone("America/Chicago"))
return dt1
# Finds all jobs that are waiting to be run
boinc_db = mysql_con.connect(host = os.environ['URL_BASE'].split('/')[-1], port = 3306, user = os.environ["MYSQL_USER"], password = os.environ["MYSQL_UPASS"], database = 'boincserver')
cursor = boinc_db.cursor(buffered=True)
find_not_run = ("SELECT job_id, Image, Command FROM boinc2docker_jobs WHERE status='Job submitted'")
cursor.execute(find_not_run)
left_to_run = []
for job_id, Image, Command in cursor:
left_to_run.append([job_id, Image, Command])
cursor.close()
boinc_db.close()
# Runs the job and updates the status
for a_job_id, an_image, several_commands in left_to_run:
prestime = convert_datetime_timezone(timnow_dt())
full_command = "/home/boincadm/project/bin/boinc2docker_create_work.py "+an_image+" "+several_commands
jobsub = sp.Popen(full_command, shell = True, stdout = sp.PIPE)
streaming = jobsub.communicate()[0].decode('UTF-8')
BOINC_output = streaming.replace("\n", "").split(' ')[-1]
# Updates date and error message
boinc_db = mysql_con.connect(host = os.environ['URL_BASE'].split('/')[-1], port = 3306, user = os.environ["MYSQL_USER"], password = os.environ["MYSQL_UPASS"], database = 'boincserver')
cursor = boinc_db.cursor(buffered=True)
cursor.execute("UPDATE boinc2docker_jobs SET date_run = %s, boinc_error = %s, status = 'Job run' WHERE job_id = %s", (prestime, BOINC_output, a_job_id))
boinc_db.commit()
cursor.close()
boinc_db.close()