forked from RickyArthurs/Carbon-Aware-Big-Data-Job-Scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobSubmissionTool.py
71 lines (62 loc) · 2.14 KB
/
jobSubmissionTool.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
67
68
69
70
71
import sqlite3
import pandas as pd
# example inputs
# 15 passengers.py 1,9 4
# 15 passengers.py 1,9 12
# 30 passengers.py 1,9 24
def main():
# unique identifier for each job initialized
id = 0
# connection established to database
conn = sqlite3.connect("test.db")
cursor = conn.cursor()
# reset the table each time the program is ran
cursor.execute("DROP TABLE IF EXISTS `jobs`;")
# create table statement with corresponding data types for each job
create_statement = """CREATE TABLE jobs (
submissionTime,
id int,
runtime int,
filename varchar(255),
args varchar(255),
deadline int
);"""
cursor.execute(create_statement)
# loop such that program continually prompts user for submissions
while True:
try:
runtime, filename, args, noHours = input(
"Ready for job submission, enter the following parameters with spaces inbetween: (runtime filename args deadline) \n"
).split(" ")
except ValueError as ve:
print("Incorrect input detected: \n")
print(ve)
continue
# deadline calculated from number of hours allowed for shifting
try:
deadLine = pd.Timestamp.today() + pd.Timedelta(hours=int(noHours))
except ValueError as ve:
print("Format inputted for deadline incorrect i.e. not a number")
print(ve)
continue
# insert values into table, validating their data types if insertion successful
try:
cursor.execute(
"""INSERT INTO jobs VALUES (?, ?, ?, ?, ?, ?)""",
(
pd.Timestamp.today().isoformat(),
id,
runtime,
filename,
args,
deadLine.isoformat(),
),
)
conn.commit()
except sqlite3.Error as error:
print("Error while inserting the data to the table", error)
continue
print("Job submitted at {} \n".format(pd.Timestamp.today()))
id += 1
if __name__ == "__main__":
main()