コード例 #1
0
ファイル: job.py プロジェクト: ricklesauceur/Lazy-Hamilton
	def GET(self):
		arg = web.input()
		
		# check credential (session)
		ret = client.check_credential(["x"], "cookie")
		if(ret == None):
			return app.debug_string
		
		# check parameters
		if('id' not in arg or\
		'descriptor' not in arg):
			return app.debug_string
		
		# check credential (session)
		ret = client.check_credential(["x"], "cookie")
		if(ret == None):
			return app.debug_string
			
		# search range associated with this client
		entries = app.db.select('range', what="range_id, range_id_job", where="range_id=$id", vars={'id': arg['id']})
		
		# peek the first one
		temp = list(entries)
		if(bool(temp) == False):
			return app.debug_string
		r = temp[0]

		# security
		# do not erase result from a solved job
		entries = app.db.select('job', what="job_status", where="job_id=$id", vars={'id': r.range_id_job})
		
		temp = list(entries)
		
		if(bool(temp) == False):
			return app.debug_string
			
		j = temp[0]
		
		# avoid result poisoning
		# far from perfect
		if(j.job_status == "done"):
			return app.debug_string
			
		# udpate job	
		app.db.update('job', job_descriptor=arg['descriptor'], job_status="done", where="job_id=$id", vars={'id': r.range_id_job})

		# erase all range linked with this job
		app.db.delete('range', where="range_id_job=$id", vars={'id': r.range_id_job})
		
		return "donejob"
コード例 #2
0
ファイル: job.py プロジェクト: ricklesauceur/Lazy-Hamilton
	def GET(self):
		arg = web.input()

		# check parameters
		if( 'name' not in arg or \
			'task' not in arg or \
			'descriptor' not in arg or \
			'maxclient' not in arg):
			return app.debug_string
			
		# check credential (session)
		ret = client.check_credential(["w"], "cookie")
		if(ret == None):
			return app.debug_string
		
		# add job
		t = app.db.transaction()
		try:
			app.db.insert('job', job_maxclient=int(arg['maxclient']), job_name=arg['name'], \
				job_task=arg['task'], job_descriptor=arg['descriptor'], job_status="fresh", \
				job_client=0)
		except:
			t.rollback()
			return app.debug_string
		else:
			t.commit()
		
		return "addjob"
コード例 #3
0
ファイル: job.py プロジェクト: ricklesauceur/Lazy-Hamilton
	def GET(self):
		arg = web.input()
		
		# check credential (session)
		ret = client.check_credential(["w"], "cookie")
		if(ret == None):
			return app.debug_string
		
		app.db.update('job', job_status="fresh", where="job_id=$id", vars={'id':arg['id']})
		
		return "unpausejob"
コード例 #4
0
ファイル: job.py プロジェクト: ricklesauceur/Lazy-Hamilton
	def GET(self):
		arg = web.input()
		
		# check credential (session)
		ret = client.check_credential(["r"], "cookie")
		if(ret == None):
			return app.debug_string
		
		if('id' not in arg):
			# select everything
			entries = app.db.select('job', what="*", order="job_status")
			
			response = ""
			
			for entry in entries:
				response += "\n" + "-"*20 + "\n"
				response += str(entry)
				response += "\n" + "-"*20 + "\n"
			
			return response
			
		else:
			# select one job
			entries = app.db.select('job', what="*", where="job_id=$id", vars={'id': arg['id']})
			
			response = ""
			
			temp = list(entries)
		
			if(bool(temp) == False):
				return app.debug_string
			
			j = temp[0]
			
			response += "\n" + "-"*20 + "\n"
			response += str(j)
			response += "\n" + "-"*20 + "\n"
			
			# select all related range
			entries = app.db.select('range', what="*", where="range_id_job=$id", vars={'id': arg['id']})
		
			for entry in entries:
				response += "\n" + "-"*20 + "\n"
				response += str(entry)
				response += "\n" + "-"*20 + "\n"
			
			return response
コード例 #5
0
ファイル: job.py プロジェクト: ricklesauceur/Lazy-Hamilton
	def GET(self):
		arg = web.input()
		recycle = False
		# check credential (session)
		ret = client.check_credential(["x"], "cookie")
		if(ret == None):
			return app.debug_string
		
		# delete old task
		if('id' in arg):
			self.update_score(arg)
			
		# search if current task timeout
		entries = app.db.select('range', what="range_id, range_id_job, range_start, range_length", \
			where="LOCALTIMESTAMP - range_timestamp > interval '%s' " % (app.range_timeout), \
			order="range_timestamp", limit=1)
		
		temp = list(entries)
		# if timeout
		if(bool(temp) != False):
			id, length, task, charset, salt, start = self.recycling(temp[0])
		else:
			id, length, task, charset, salt, start = self.craft()
		
		# render xml response
		web.header('Content-Type', 'text/xml')
		
		response = "<range>\
			<id>%s</id>\
			<length>%s</length>\
			<task>%s</task>\
			<charset>%s</charset>\
			<salt>%s</salt>\
			<start>\"%s\"</start>\
			</range>" % (id, length, task, charset, salt, start)
		
		return response
コード例 #6
0
ファイル: job.py プロジェクト: ricklesauceur/Lazy-Hamilton
	def GET(self):
		arg = web.input()
		
		# check credential (session)
		ret = client.check_credential(["w"], "cookie")
		if(ret == None):
			return app.debug_string
		
		# do not pause job already done
		entries = app.db.select('job', what="job_status", where="job_id=$id", vars={'id':arg['id']})
		
		temp = list(entries)
		
		if(bool(temp) == False):
			return app.debug_string
			
		j = temp[0]	
			
		if(j.job_status == "done"):
			return app.debug_string
		
		app.db.update('job', job_status="paused", where="job_id=$id", vars={'id':arg['id']})
		
		return "pausejob"