def api_vacuum(http_context, queue_in = None, config = None, sessions = None, commands = None): set_logger_name("administration") worker = b'vacuum' # Get a new logger. logger = get_logger(config) try: check_sessionid(http_context['headers'], sessions) post = http_context['post'] # Check POST parameters. validate_parameters(post, [ ('database', T_OBJECTNAME, False), ('table', T_OBJECTNAME, False), ('mode', T_VACUUMMODE, False) ]) # Serialize parameters. parameters = base64.b64encode( pickle.dumps({ 'database': post['database'], 'table': post['table'], 'mode': post['mode'] })).decode('utf-8') except (Exception, HTTPError) as e: logger.traceback(get_tb()) logger.error(str(e)) if isinstance(e, HTTPError): raise e else: raise HTTPError(500, "Internal error.") # Check command uniqueness. try: commands.check_uniqueness(worker, parameters) except SharedItem_exists as e: logger.traceback(get_tb()) logger.error(str(e)) raise HTTPError(402, "Vaccum '%s' already running on table '%s'." % (post['mode'], post['table'])) cid = hash_id(worker + b'-' + parameters.encode('utf-8')) command = Command( cid.encode('utf-8'), time.time(), 0, worker, parameters, 0, u'') try: commands.add(command) # Put the Command in the command queue queue_in.put(command) return {"cid": cid} except SharedItem_no_free_slot_left as e: logger.traceback(get_tb()) logger.error(str(e)) raise HTTPError(500, "Internal error.")
def schedule_worker(queue_in, config, commands, worker, parameters=''): # Check command uniqueness. try: commands.check_uniqueness(worker, parameters) except SharedItem_exists: return cid = hash_id(worker) command = Command(cid.encode('utf-8'), time.time(), 0, worker, parameters, 0, u'') try: commands.add(command) # Put the Command in the command queue queue_in.put(command) return except SharedItem_no_free_slot_left: return