예제 #1
0
def test_shared_queue_producer():
    # Append items to the shared queue
    queue = get_event_queue(QueueHost, QueuePortNr, QueueAuthCode)
    assert queue is not None, "Failed to connect to queue manager"

    for cnt in range(NItems):
        queue.put(f"Item {cnt}")
예제 #2
0
def change_directory():
    args = _parseArguments(sys.argv)
    if args.input is not '':
        newdir = Path(args.input).expanduser().absolute()
    else:
        date_string = datetime.utcnow().strftime('%Y%m%dUT')
        newdir = Path(f'~/V20Data/Images/{date_string}').expanduser()
        if args.cals is True:
            newdir = Path(
                f'~/V20Data/Images/{date_string}/Calibration').expanduser()
        if args.flats is True:
            newdir = Path(
                f'~/V20Data/Images/{date_string}/AutoFlat').expanduser()

    args.input = str(newdir)
    if newdir.exists() is False:
        newdir.mkdir(parents=True)

    framework_config_fullpath = pkg_resources.resource_filename(
        "vysosdrp", "framework.cfg")
    cfg = ConfigClass(framework_config_fullpath)
    queue = queues.get_event_queue(cfg.queue_manager_hostname,
                                   cfg.queue_manager_portnr,
                                   cfg.queue_manager_auth_code)

    if queue is None:
        print("Failed to connect to Queue Manager")
    else:
        pending = queue.get_pending()
        event = Event("set_file_type", args)
        queue.put(event)
        event = Event("update_directory", args)
        queue.put(event)
예제 #3
0
def analyze_one():
    args = _parseArguments(sys.argv)
    p = Path(args.input).expanduser().absolute()
    if p.exists() is False:
        print(f'Unable to find file: {p}')
        return
    args.name = f"{p}"

    framework_config_fullpath = pkg_resources.resource_filename(
        "vysosdrp", "framework.cfg")
    cfg = ConfigClass(framework_config_fullpath)
    queue = queues.get_event_queue(cfg.queue_manager_hostname,
                                   cfg.queue_manager_portnr,
                                   cfg.queue_manager_auth_code)
    if queue is None:
        print("Failed to connect to Queue Manager")
        return

    if args.overwrite is True:
        pending = queue.get_pending()
        event = Event("set_overwrite", args)
        queue.put(event)

    pending = queue.get_pending()
    event = Event("next_file", args)
    queue.put(event)
 def _get_queue(self):
     """
     Returns True is getting event queue was successful.
     """
     if self.queue is None:
         cfg = self.config
         hostname = cfg.queue_manager_hostname
         portnr = cfg.queue_manager_portnr
         auth_code = cfg.queue_manager_auth_code
         self.queue = queues.get_event_queue(hostname, portnr, auth_code)
     return self.queue is not None
예제 #5
0
    def _get_queue_manager(self, cfg):
        """
        Tries to get an event queue. 
        If successful then returns the manager and the queue, 
        otherwise starts the new queue manager. 
        """
        hostname = cfg.queue_manager_hostname
        portnr = cfg.queue_manager_portnr
        auth_code = cfg.queue_manager_auth_code

        self.logger.debug(
            f"Getting shared event queue from {hostname}:{portnr}")
        queue = queues.get_event_queue(hostname, portnr, auth_code)
        if queue is None:
            self.logger.debug("Starting Queue Manager")
            self.queue_manager = queues.start_queue_manager(
                hostname, portnr, auth_code, self.logger)
            queue = queues.get_event_queue(hostname, portnr, auth_code)
            if queue is not None:
                self.logger.debug("Got event queue from Queue Manager")
            return queue
        else:
            return queue
예제 #6
0
    def _get_event_queue(self):
        """
        If multiprocessing is desired then returns the shared queue,
        otherwise returns the Simple_event_queue, which will only work within a single process.
        """
        cfg = self.config
        want_multi = cfg.get("want_multiprocessing", False)

        if want_multi:
            hostname = cfg.queue_manager_hostname
            portnr = cfg.queue_manager_portnr
            auth_code = cfg.queue_manager_auth_code
            self.logger.info("Getting shared event queue")
            return queues.get_event_queue(hostname, portnr, auth_code)

        return queues.Simple_event_queue()
예제 #7
0
def test_shared_queue_consumer():
    # Append items to the shared queue
    queue = get_event_queue(QueueHost, QueuePortNr, QueueAuthCode)

    assert queue is not None, "Failed to connect to queue manager"

    cnt = 0
    ok = True
    while ok:
        try:
            item = queue.get(block=False, timeout=1)
        except:
            ok = False
            break
        if item is not None:
            cnt += 1

    assert cnt == NItems, f"Failed to get items from queue, {NItems} expected, got {cnt}"
    try:
        # Kills the queue server process
        queue.terminate()
    except:
        pass
예제 #8
0
                        dest="portnr",
                        type=str,
                        help="Port number")

    try:
        return parser.parse_args(in_args[1:])
    except:
        # parser.print_help()
        sys.exit(0)


if __name__ == "__main__":
    args = _parseArguments(sys.argv)
    cfg = ConfigClass(args.config_file)

    cfg.properties["want_multiprocessing"] = True
    hostname = cfg.queue_manager_hostname if args.hostname is None else args.hostname
    portnr = cfg.queue_manager_portnr if args.portnr is None else args.portnr
    auth_code = cfg.queue_manager_auth_code

    queue = queues.get_event_queue(hostname, portnr, auth_code)
    print(f"Hostname = {hostname}\nPort nr = {portnr}\n")
    if queue is None:
        print("Failed to connect to Queue Manager")
    else:
        try:
            queue.terminate()
        except:
            pass
        print("Stop request sent.")
예제 #9
0
    epilog = "\nStart event queue manager\n"

    parser = argparse.ArgumentParser(prog=f"{in_args[0]}", description=description, usage=usage, epilog=epilog)
    parser.add_argument("-c", "--config", dest="config_file", type=str, help="Configuration file")
    parser.add_argument("-H", "--host", dest="hostname", type=str, help="Host name")
    parser.add_argument("-p", "--port", dest="portnr", type=str, help="Port number")

    try:
        return parser.parse_args(in_args[1:])
    except:
        # parser.print_help()
        sys.exit(0)


if __name__ == "__main__":
    args = _parseArguments(sys.argv)
    cfg = ConfigClass(args.config_file)
    cfg.properties["want_multiprocessing"] = True
    hostname = cfg.queue_manager_hostname if args.hostname is None else args.hostname
    portnr = cfg.queue_manager_portnr if args.portnr is None else args.portnr
    auth_code = cfg.queue_manager_auth_code

    if queues.get_event_queue(hostname, portnr, auth_code) is not None:
        print("Queue Manager is already running\n")
    else:
        queue = queues.start_queue_manager(hostname, portnr, auth_code, logger=logging.getLogger())

        print(f"Hostname = {hostname}\nPort nr = {portnr}\n")
        print("Started Queue Manager.")
    os._exit(0)