예제 #1
0
def main():

    dbhost = mdlib.get_dbhost()
    dbname = "medusa"

    print '* starting mdscript_runner, host=%s dbname=%s' % (dbhost, dbname)

    while True:
        # check if there is a new request
        sqlstmt = "select cmd,medscript from CS_cmdqueue order by timestamp desc"
        con, cur = mdlib.get_raw_mysql_data(dbhost, dbname, sqlstmt)
        dat = cur.fetchone()

        i = 0
        while dat != None:
            #dat[0], dat[1]
            cmd = dat[0]
            taskpath = dat[1]

            if cmd == 'start':
                # fork and run medusa program.
                pid = os.fork()
                if pid == 0:
                    # child
                    mdserv.task_main(taskpath)
                    exit()
                else:
                    # parent
                    #mdlib.log('* created crowd-sensing task id={0}.'.format(pid))
                    print '* created crowd-sensing task id={0}.'.format(pid)

            elif cmd == 'stop':
                # for future use.
                os.system('./sig2daemon.sh {0}'.format(taskpath))

            dat = cur.fetchone()
        con.close()

        sqlstmt = "delete from CS_cmdqueue"
        mdlib.get_single_mysql_data(dbhost, dbname, sqlstmt)

        # polling interval: 3 seconds.
        time.sleep(3)

    #mdlib.log('* exits medusa task runner.')
    print '* exits medusa task runner.'
예제 #2
0
def main():

	dbhost = mdlib.get_dbhost()
	dbname = "medusa"
	
	print '* starting mdscript_runner, host=%s dbname=%s' % (dbhost, dbname)

	while True:
		# check if there is a new request
		sqlstmt = "select cmd,medscript from CS_cmdqueue order by timestamp desc"
		con, cur = mdlib.get_raw_mysql_data(dbhost, dbname, sqlstmt)
		dat = cur.fetchone()

		i = 0
		while dat != None:
			#dat[0], dat[1]
			cmd = dat[0]
			taskpath = dat[1]

			if cmd == 'start':
				# fork and run medusa program.
				pid = os.fork()
				if pid == 0:
					# child 
					mdserv.task_main(taskpath)
					exit()
				else:
					# parent
					#mdlib.log('* created crowd-sensing task id={0}.'.format(pid))
					print '* created crowd-sensing task id={0}.'.format(pid)

			elif cmd == 'stop':
				# for future use.
				os.system('./sig2daemon.sh {0}'.format(taskpath));

			dat = cur.fetchone()
		con.close()

		sqlstmt = "delete from CS_cmdqueue"
		mdlib.get_single_mysql_data(dbhost, dbname, sqlstmt)

		# polling interval: 3 seconds.
		time.sleep(3)
	
	#mdlib.log('* exits medusa task runner.')
	print '* exits medusa task runner.'
예제 #3
0
# Environment Variables.
ENV = dict()
ENV["R_RID"] = None  # should be provided by xml program.
ENV["R_RKEY"] = None  # should be provided by xml program.e
ENV["R_WID"] = None
ENV["R_C2DM_KEY"] = None
ENV["W_RID"] = None
ENV["W_RKEY"] = None
ENV["W_WID"] = "all"  # this will become mobile phone user's AMT Worker ID at recruit stage.
ENV["W_C2DM_KEY"] = None
ENV["APP_NAME"] = None
ENV["G_VAR"] = None

# Server configurations.
cs_dbhost = mdlib.get_dbhost()
cs_dbname = "medusa"

# for profiling
clock = StopWatch()

# by YJ
soc2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
soc2.connect(('127.0.0.1', SOC_PORT))
#soc2.send('WILL RECV') # telling server we will recieve data from here
SIZE = 128


def msend(conn, msg):
    conn.send(msg + '\n')
예제 #4
0
######################################################
# 	Program Start
#
option = parse_args()
if option == None:
	mdlib.log("! no options specified")
	display_usage()

clock1 = StopWatch()
mdlib.log("********************************")
mdlib.log("*       Reset Utility          *")
mdlib.log("********************************")

# set configurations.
vdict = mdlib.get_env_vars(mdlib.get_dbhost(), "medusa", "HIT-HOST,HIT-URI");
hit_host = vdict["HIT-HOST"];
hit_urlloc = vdict["HIT-URI"];

pid = 'all'
qid = 'all'

# send delete messages to HIT server
if option == 'all' or option == 'hit':
	params = {'action' : 'rmHIT', 'pid' : pid, 'qid' : qid, 'rid' : rid, 'rkey' : rkey, 'wid' : 'all'}
	resp = mdlib.httpsend(hit_host, hit_urlloc, params)

	if resp[0] == 200:
		mdlib.log('deleted')
	else:
		mdlib.log('! HITS err, data may not be deleted: code={0} msg={1}'.format(resp[0], resp[1]))
예제 #5
0
	
# Environment Variables.
ENV = dict()
ENV["R_RID"] = None		# should be provided by xml program.
ENV["R_RKEY"] = None	# should be provided by xml program.e
ENV["R_WID"] = None
ENV["R_C2DM_KEY"] = None
ENV["W_RID"] = None
ENV["W_RKEY"] = None
ENV["W_WID"] = "all"	# this will become mobile phone user's AMT Worker ID at recruit stage.
ENV["W_C2DM_KEY"] = None
ENV["APP_NAME"] = None
ENV["G_VAR"] = None

# Server configurations.
cs_dbhost = mdlib.get_dbhost()
cs_dbname = "medusa"

# for profiling
clock = StopWatch()

# by YJ
soc2 = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
soc2.connect(('127.0.0.1',SOC_PORT))
#soc2.send('WILL RECV') # telling server we will recieve data from here
SIZE = 128

def msend(conn,msg):
	conn.send(msg + '\n')

def mrecv(conn):