Beispiel #1
0
    def testLoadMessage(self, mocked_filename):
        self.assertEqual(oc.load_message({}, converter, {}), ({}, None))

        mocked_reader = mock_open(read_data="some data")
        with mock.patch('builtins.open', mocked_reader):
            params = {"stream_contents": False}
            self.assertEqual(oc.load_message({"contents_ref": "unique_name", "any": "value"}, converter, params),
                             ({"any": "value", "contents": "converted some data"}, "unique_name"))
            mocked_reader.assert_called_once_with('filename', 'r')
            handle = mocked_reader()
            handle.read.assert_called()
Beispiel #2
0
    def on_start_tasks(self, msg):
        """Entry method for TaskQueue. Creates tasks and puts task messages on the

        :param msg:
        :return:
        """
        header = msg['header']
        stepid = header['stepid']
        jobid = header['jobid']
        process_id = header['process_id']

        # Incoming message may be large. Manually load message from file if necessary
        msg, _ = load_message(msg, json.loads, {'stream_contents': False})
        """
        tasks: [{'id': 'some_id', 'dependencies': ['some_id', 'some_other_id']}
        """
        tasks = msg['contents']['tasks']
        key_prefix = msg['contents']['key_prefix']
        extra_msg = msg['contents'].get('extra_msg', {})
        extra_header = msg['header'].get('extra', {})
        job, step = get_job_step(jobid, stepid)

        if not step:
            raise GOBException(f"No jobstep found with id {stepid}")

        self._validate_dependencies(tasks)
        self._create_tasks(jobid, stepid, process_id, tasks, key_prefix,
                           extra_msg, extra_header)
        self._queue_free_tasks_for_jobstep(stepid)
 def testLoadMessageReader(self, mocked_filename):
     mocked_reader = mock_open(read_data="some data")
     with mock.patch('builtins.open', mocked_reader):
         params = {"stream_contents": True}
         self.assertEqual(
             oc.load_message({
                 "contents_ref": "unique_name",
                 "any": "value"
             }, converter, params), ({
                 "any": "value",
                 "contents": ANY,
                 "contents_reader": ANY
             }, "unique_name"))
                def get_message_from_body():
                    offload_id = None
                    try:
                        # Try to parse body as json message, else pass it as it is received
                        msg = from_json(body)

                        # Allow for offline contents
                        if self._params["load_message"]:
                            msg, offload_id = load_message(msg, from_json, self._params)
                    except (TypeError, json.decoder.JSONDecodeError):
                        # message was not json, pass message as it is received
                        msg = body

                    return msg, offload_id