Example #1
0
    def send_to_stomp_or_defer(message, headers=None):
        if not headers:
            headers = generate_headers()
        if options.verbose:
            pprint(message)
        if allow_stomp_fallback and options.dropfile:
            return write_message_to_dropfile(message, headers)
        try:
            stomp = StompTransport()
            if options.dryrun:
                print("Not sending message (running with --dry-run)")
                return
            stomp.connect()
            stomp.send("processing_recipe", message, headers=headers)
        except (
            KeyboardInterrupt,
            SyntaxError,
            AssertionError,
            AttributeError,
            ImportError,
            TypeError,
            ValueError,
        ):
            raise
        except Exception:
            if not allow_stomp_fallback:
                raise
            print("\n\n")
            import traceback

            traceback.print_exc()
            print("\n\nAttempting to store message in fallback location")
            write_message_to_dropfile(message, headers)
Example #2
0
class Worker(object):
    def __init__(self, wait_time=5):

        self.wait_time = wait_time
        self.heartbeat_timestamp = None

        self.transport = StompTransport()
        self.transport.connect()
        self.transport.subscribe_broadcast("heartbeat", self.read_heartbeat)
        self.transport.subscribe("outbound", self.read)

        self.wait()

    def timeout(self):
        from time import time

        if self.heartbeat_timestamp is None:
            self.heartbeat_timestamp = time()
        else:
            if time() - self.heartbeat_timestamp > self.wait_time:
                return True
        return False

    def wait(self):
        from time import time, sleep

        try:
            while not self.timeout():
                sleep(1)
        except KeyboardInterrupt:
            pass

    def send(self, message):
        print("Sending")
        self.transport.send("inbound", message)

    def read_heartbeat(self, header, message):
        from time import time

        self.heartbeat_timestamp = time()

    def read(self, header, message):
        message = {"result": "Hey Hey!"}
        self.send(message)
Example #3
0
def test_messages_are_serialized_for_transport(mockstomp):
    """Test the message serialization."""
    banana = {"entry": [1, 2.0, decimal.Decimal(3), "banana"]}
    banana_str = '{"entry": [1, 2.0, 3.0, "banana"]}'
    stomp = StompTransport()
    stomp.connect()
    mockconn = mockstomp.Connection.return_value

    stomp.send(str(mock.sentinel.channel1), banana)
    mockconn.send.assert_called_once()
    args, kwargs = mockconn.send.call_args
    assert args == ("/queue/" + str(mock.sentinel.channel1), banana_str)

    stomp.broadcast(str(mock.sentinel.channel2), banana)
    args, kwargs = mockconn.send.call_args
    assert args == ("/topic/" + str(mock.sentinel.channel2), banana_str)

    with pytest.raises(Exception):
        stomp.send(str(mock.sentinel.channel), mock.sentinel.unserializable)
    recipe['1']['parameters'] = {}
    recipe['1']['parameters']['arguments'] = sys.argv[1:] + ['>', output_file]
    recipe['1']['parameters']['cwd'] = os.getcwd()

    message['custom_recipe'] = recipe

    # reply_to = 'transient.gctf.%s' % str(uuid.uuid4())
    # recipe['1']['output'] = 2
    # recipe['2'] = {}
    # recipe['2']['service'] = "relion_refine_call_back"
    # recipe['2']['queue'] = reply_to
    # recipe['2']['parameters'] = {}
    # recipe['2']['output'] = 3
    # recipe['3'] = {}

    recipe['start'] = [[1, []]]

    stomp.connect()

    test_valid_recipe = workflows.recipe.Recipe(recipe)
    test_valid_recipe.validate()

    stomp.send('processing_recipe', message)

    # So that BASH can pick this up

    # get_output_file()
    print(output_file)

# print("\nMotioncor2 job submitted")
    recipe['3'] = {}

    print(sys.argv)

    # recipe['1']['parameters'][
    #     'arguments'] = 'module load scipion && /dls_sw/apps/scipion/release-1.1-headless-devel/scipion/software/em/motioncor2-1.0.0/bin/motioncor2 -InMrc GroEL_29-100_0000.mrc -OutMrc GroEL_29-100_0000_aligned_mic.mrc -kV 300.0 -Trunc 0 -FmDose 0.4 -OutStack 0 -Gpu 0 -InitDose 0.0 -PixSize 0.4 -Tol 0.5 -Group 1 -Patch 5 5 -Throw 0 -LogFile micrograph_000029.log -FtBin 1.0 -MaskCent 0 0 -MaskSize 1 1 -Gain /dls/ebic/data/staff-scratch/Joshua/test_full_set/Micrographs/SuperRef_GroEL_29-1_0000.mrc'

    recipe['start'] = [[1, []]]

    message['custom_recipe'] = recipe
    print(
        "********************************* THIS IS THE SUBMITTED RECIPE*******************************************"
    )

    stomp.connect()
    test_valid_recipe = workflows.recipe.Recipe(recipe)

    test_valid_recipe.validate()
    print(message)

    stomp.send('processing_recipe', message
               #headers={'reply-to':'scipion_call_back'}
               )
    print("\nMotioncor2 job submitted")

    stomp2 = StompTransport()
    stomp2.connect()
    # stomp2._subscribe(1,reply_to, update_jobid)
    workflows.recipe.wrap_subscribe(stomp2, reply_to, update_jobid)
    print('end')