Ejemplo n.º 1
0
def fireTaskWorker(task_name,task_inputs_key):

	print "Starting task request..."

	# get job_package and burn it
	job_package = pickle.loads(redisHandles.r_job_handle.get(task_inputs_key))
	redisHandles.r_job_handle.delete(task_inputs_key)

	# check if task in available tasks, else abort
	try:
		task_handle = getattr(actions, task_name)
	except:		 
		return utilities.applicationError("Task not found, or user not authorized to perform.  Return to <a href='/userPage'>user page</a>.")		
	
	# get username from session (will pull from user auth session later)
	username = session['username']	

	# get user-selectedd objects	
	stime = time.time()
	userSelectedPIDs = models.user_pids.query.filter_by(username=username,status=True)	
	PIDlist = [PID.PID for PID in userSelectedPIDs]	
	etime = time.time()
	ttime = (etime - stime) * 1000
	print "Took this long to create list from SQL query",ttime,"ms"	

	# instantiate job number
	''' pulling from incrementing redis counter, considering MySQL '''
	job_num = jobs.jobStart()		
	
	# begin job and set estimated tasks
	print "Antipcating",userSelectedPIDs.count(),"tasks...."	
	redisHandles.r_job_handle.set("job_{job_num}_est_count".format(job_num=job_num),userSelectedPIDs.count())	

	# augment job_package
	job_package['job_num'] = job_num

	# send to celeryTaskFactory in actions.py
	'''
	iterates through PIDs and creates secondary async tasks for each
	passing username, task_name, and job_package containing all the update handles	
	'celery_task_id' below contains celery task key, that contains all eventual children objects
	'''
	celery_task_id = actions.celeryTaskFactory.delay(job_num=job_num,task_name=task_name,job_package=job_package,PIDlist=PIDlist)	

	# send job to user_jobs SQL table
	db.session.add(models.user_jobs(job_num, username, celery_task_id, "init", task_name))	
	db.session.commit() 

	print "Started job #",job_num,"Celery task #",celery_task_id	
	return redirect("/userJobs")
Ejemplo n.º 2
0
def objPreview(PIDnum):	

	object_package = {}

	# GET CURRENT OBJECTS	
	PIDlet = jobs.genPIDlet(int(PIDnum))
	if PIDlet == False:
		return utilities.applicationError("PIDnum is out of range or invalid.  Object-at-a-Glance is displeased.")
	PIDlet['pURL'] = "/objPreview/"+str(int(PIDnum)-1)
	PIDlet['nURL'] = "/objPreview/"+str(int(PIDnum)+1)	

	# WSUDOR handle
	obj_handle = WSUDOR_ContentTypes.WSUDOR_Object(PIDlet['cPID'])
	
	# General Metadata
	solr_params = {'q':utilities.escapeSolrArg(PIDlet['cPID']), 'rows':1}
	solr_results = solr_handle.search(**solr_params)
	solr_package = solr_results.documents[0]
	object_package['solr_package'] = solr_package

	# COMPONENTS
	object_package['components_package'] = []
	riquery = fedora_handle.risearch.spo_search(subject=None, predicate="info:fedora/fedora-system:def/relations-external#isMemberOf", object="info:fedora/"+PIDlet['cPID'])
	for s,p,o in riquery:
		object_package['components_package'].append(s.encode('utf-8'))
	if len(object_package['components_package']) == 0:
		object_package.pop('components_package')		


	# RDF RELATIONSHIPS
	riquery = fedora_handle.risearch.spo_search(subject="info:fedora/"+PIDlet['cPID'], predicate=None, object=None)
	
	# parse
	riquery_filtered = []
	for s,p,o in riquery:	
		riquery_filtered.append((p,o))
	riquery_filtered.sort()
	object_package['rdf_package'] = riquery_filtered

	
	# DATASTREAMS		
	ds_list = obj_handle.ohandle.ds_list
	object_package['datastream_package'] = ds_list

	# Object size of datastreams
	size_dict = obj_handle.objSizeDict
	object_package['size_dict'] = size_dict
	object_package['size_dict_json'] = json.dumps(size_dict)
	
	# OAI
	OAI_dict = {}	
	#identifer
	try:
		riquery = fedora_handle.risearch.spo_search(subject="info:fedora/"+PIDlet['cPID'], predicate="http://www.openarchives.org/OAI/2.0/itemID", object=None)
		OAI_ID = riquery.objects().next().encode('utf-8')
		OAI_dict['ID'] = OAI_ID
	except:
		print "No OAI Identifier found."
	
	# sets
	OAI_dict['sets'] = []
	try:
		riquery = fedora_handle.risearch.spo_search(subject="info:fedora/"+PIDlet['cPID'], predicate="http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/isMemberOfOAISet", object=None)
		for each in riquery.objects():
			OAI_dict['sets'].append(each)					
	except:
		print "No OAI sets found."

	object_package['OAI_package'] = OAI_dict
	print object_package['OAI_package']

	# RENDER
	return render_template("objPreview.html",PIDnum=(int(PIDnum)+1),PIDlet=PIDlet,object_package=object_package,localConfig=localConfig)