def push_msg(data,queue_name="push"): #Creates a random file inside the /Requests subdirectory within a Queue, #the PushServer will process these files file_id = get_random_str(100) + '.msg' return general.atomic_write_to_file(general.INCOMING_QUEUE_TO_DIR_MAPPING[queue_name], file_id, data)
def pull_msg(data,queue_name="pull"): #Creates a random file inside the /Requests subdirectory within a Queue, #the PullServer will process these files and then this file will wait for the response as #skip_if_locked is false file_id = get_random_str(100) + '.msg' try: general.atomic_write_to_file(general.INCOMING_QUEUE_TO_DIR_MAPPING[queue_name], file_id, data) result = general.atomic_read_from_file(general.OUTGOING_QUEUE_TO_DIR_MAPPING[queue_name], file_id,False) os.remove(general.OUTGOING_QUEUE_TO_DIR_MAPPING[queue_name]+"/"+file_id) return result except KeyboardInterrupt: raise KeyboardInterrupt
def push_msg(data,queue_name="push"): #Creates a random file inside the /Requests subdirectory within a Queue, #the PushServer will process these files file_id = get_random_str(100) + '.msg' file_path = os.path.join(general.INCOMING_QUEUE_TO_DIR_MAPPING[queue_name], file_id) try: result = general.atomic_write_to_file(general.INCOMING_QUEUE_TO_DIR_MAPPING[queue_name], file_id, data) # The following block is important, because of the fact that completion of the operation # can be known when the push_server.py removes a processed file :P # Without this loop, the normal execution will continue even when db operation is pending. # This may lead to some unwanted and cryptic bugs while os.path.exists(file_path): time.sleep(0.02) return result except KeyboardInterrupt: raise KeyboardInterrupt
def push_msg(data, queue_name="push"): #Creates a random file inside the /Requests subdirectory within a Queue, #the PushServer will process these files file_id = get_random_str(100) + '.msg' file_path = os.path.join(general.INCOMING_QUEUE_TO_DIR_MAPPING[queue_name], file_id) try: result = general.atomic_write_to_file( general.INCOMING_QUEUE_TO_DIR_MAPPING[queue_name], file_id, data) # The following block is important, because of the fact that completion of the operation # can be known when the push_server.py removes a processed file :P # Without this loop, the normal execution will continue even when db operation is pending. # This may lead to some unwanted and cryptic bugs while os.path.exists(file_path): time.sleep(0.02) return result except KeyboardInterrupt: raise KeyboardInterrupt
def push_msg(data, queue_name="push"): #Creates a random file inside the /Requests subdirectory within a Queue, #the PushServer will process these files file_id = get_random_str(100) + '.msg' return general.atomic_write_to_file( general.INCOMING_QUEUE_TO_DIR_MAPPING[queue_name], file_id, data)