<s> """<STR_LIT>""" <EOL> import datetime <EOL> import urllib <EOL> from google . appengine . api import apiproxy_stub_map <EOL> from google . appengine . api . taskqueue import taskqueue_service_pb <EOL> from google . appengine . api . taskqueue import taskqueue_stub <EOL> from google . appengine . tools . devappserver2 . admin import admin_request_handler <EOL> from google . appengine . tools . devappserver2 . admin import taskqueue_utils <EOL> _TASKS_TO_LOAD = <NUM_LIT:1000> <EOL> class TaskQueueTasksHandler ( admin_request_handler . AdminRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def _get_tasks ( queue_name , <EOL> count , <EOL> start_task_name = None , <EOL> start_eta_usec = None ) : <EOL> request = taskqueue_service_pb . TaskQueueQueryTasksRequest ( ) <EOL> request . set_queue_name ( queue_name ) <EOL> request . set_max_rows ( count ) <EOL> if start_task_name is not None : <EOL> request . set_start_task_name ( start_task_name ) <EOL> if start_eta_usec is not None : <EOL> request . set_start_eta_usec ( start_eta_usec ) <EOL> response = taskqueue_service_pb . TaskQueueQueryTasksResponse ( ) <EOL> apiproxy_stub_map . MakeSyncCall ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> request , <EOL> response ) <EOL> now = datetime . datetime . utcnow ( ) <EOL> for task in response . task_list ( ) : <EOL> task . set_body ( '<STR_LIT>' ) <EOL> yield taskqueue_stub . QueryTasksResponseToDict ( queue_name , task , now ) <EOL> @ staticmethod <EOL> def _delete_task ( queue_name , task_name ) : <EOL> request = taskqueue_service_pb . TaskQueueDeleteRequest ( ) <EOL> request . set_queue_name ( queue_name ) <EOL> request . task_name_list ( ) . append ( task_name ) <EOL> response = taskqueue_service_pb . TaskQueueDeleteResponse ( ) <EOL> apiproxy_stub_map . MakeSyncCall ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> request , <EOL> response ) <EOL> return response . result ( <NUM_LIT:0> ) <EOL> @ staticmethod <EOL> def _run_task ( queue_name , task_name ) : <EOL> request = taskqueue_service_pb . TaskQueueForceRunRequest ( ) <EOL> request . set_queue_name ( queue_name ) <EOL> request . set_task_name ( task_name ) <EOL> response = taskqueue_service_pb . TaskQueueForceRunResponse ( ) <EOL> apiproxy_stub_map . MakeSyncCall ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> request , <EOL> response ) <EOL> return response . result ( ) <EOL> def get ( self , queue_name ) : <EOL> queue_info = taskqueue_utils . QueueInfo . get ( <EOL> queue_names = frozenset ( [ queue_name ] ) ) . next ( ) <EOL> tasks = list ( self . _get_tasks ( queue_name , count = _TASKS_TO_LOAD ) ) <EOL> self . response . write ( <EOL> self . render ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : <EOL> queue_info . mode == taskqueue_service_pb . TaskQueueMode . PUSH , <EOL> '<STR_LIT>' : self . request . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : queue_info , <EOL> '<STR_LIT>' : queue_name , <EOL> '<STR_LIT>' : tasks , <EOL> '<STR_LIT:error>' : self . request . get ( '<STR_LIT:message>' ) } ) ) <EOL> def post ( self , queue_name ) : <EOL> """<STR_LIT>""" <EOL> task_name = self . request . get ( '<STR_LIT>' ) <EOL> if self . request . get ( '<STR_LIT>' ) : <EOL> result = self . _delete_task ( queue_name , task_name ) <EOL> elif self . request . get ( '<STR_LIT>' ) : <EOL> result = self . _run_task ( queue_name , task_name ) <EOL> if result == taskqueue_service_pb . TaskQueueServiceError . UNKNOWN_QUEUE : <EOL> message = '<STR_LIT>' % queue_name <EOL> elif result == taskqueue_service_pb . TaskQueueServiceError . UNKNOWN_TASK : <EOL> message = '<STR_LIT>' % task_name <EOL> elif result != taskqueue_service_pb . TaskQueueServiceError . OK : <EOL> message = '<STR_LIT>' <EOL> else : <EOL> message = '<STR_LIT>' <EOL> self . redirect ( <EOL> '<STR_LIT>' % ( self . request . path_url , <EOL> urllib . urlencode ( { '<STR_LIT>' : self . request . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:message>' : message } ) ) ) </s>
