-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtrigger.py
More file actions
38 lines (30 loc) · 1.2 KB
/
trigger.py
File metadata and controls
38 lines (30 loc) · 1.2 KB
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
# Trigger function in AMA3D. Call this file to invoke and create a new triggering condition that can be processed by AMA3D
#!/usr/bin/python
import MySQLdb
import sys
import traceback
import AMA_globals as G
def connect_db(host, user, password, dbname):
try:
G.DB = MySQLdb.connect(host=host, user=user, passwd=password, db=dbname)
print "Database Connected!"
return 0
except Exception, err:
print traceback.format_exc()
# Rollback in case there is any error
G.DB.rollback()
return 1
if len(sys.argv) != 4:
print "trigger Usage: python trigger parameter idTaskResource isLast"
print "Create a new TriggeringCondition so that some Agent can pick up"
print "See documentation for more info."
else:
file = open("Account", "r")
parsed = file.readline().split()
if connect_db(parsed[0], parsed[1], parsed[2], parsed[3])==0:
DB = G.DB
cursor = DB.cursor()
cursor.execute( "INSERT INTO TriggeringCondition(Parameters ,idTaskResource, isLast, Status) VALUES (\"%s\", %d, %d, 0)"%(sys.argv[1], int(sys.argv[2]), int(sys.argv[3])) )
DB.commit()
else:
print "Fail to create a trigger"