Beispiel #1
0
class WorkerProcessController:
    """
    WorkerProcessController controls requests on the `api/v1/admin/ready/` endpoint.
    """
    def __init__(self, context: ServiceContext = None):
        if context is None:
            context = build_context('service')
        self.context = context
        self.work_queue = WorkQueue(self.context.WORK_QUEUE_CONTEXT)
        self.queue_key = QueueKeys.PRODUCT_DATA

    def post(self) -> (OrderedDict, int):
        """
        Routes the request to the correct queue method and returns the status code and error message as applicable.

        :return: (status_code: int, error: str)
        """
        success, error = self.work_queue.put(self.queue_key)
        if success:
            response, model = build_response('ok')
            return ResponseEnvelope(model).create_single_result_response(
                response), 200
        else:
            response = ResponseEnvelope(dict()).create_error_response(error)
            if error == ErrorMessages.LOCKED_EXISTS or error == ErrorMessages.UNLOCKED_EXISTS:
                return response, 500
            else:
                return response, 503
Beispiel #2
0
def main():
    """
    Iterate forever and sleep for the configured time between iterations.
    If there is work to be processed, start a WorkManager.

    :return:
    """
    context = build_context('worker')
    work_queue = FileSystemWorkQueue(context.WORK_QUEUE_CONTEXT)
    while True:
        if not work_queue.empty:
            WorkManager(context, work_queue).run()
        sleep(context.SLEEP_TIME)
Beispiel #3
0
def test_work_manager(test_context, mock_get_connection_object, mock_connection_object):
    mock_get_connection_object.return_value = mock_get_connection_object()

    yield WorkManager(test_context, FileSystemWorkQueue(test_context.WORK_QUEUE_CONTEXT))
Beispiel #4
0
def test_file_queue(test_queue_context):
    yield FileSystemWorkQueue(test_queue_context)
    shutil.rmtree(test_queue_context.PATH)
Beispiel #5
0
def test_queue(test_context):
    from util.queue.filesystem import FileSystemWorkQueue
    queue = FileSystemWorkQueue(test_context)
    yield queue
    import shutil
    shutil.rmtree(queue.context.PATH)
Beispiel #6
0
 def __init__(self, context: ServiceContext = None):
     if context is None:
         context = build_context('service')
     self.context = context
     self.work_queue = WorkQueue(self.context.WORK_QUEUE_CONTEXT)
     self.queue_key = QueueKeys.PRODUCT_DATA