Esempio n. 1
0
def queue_processor(writer, queue_plugin):
    queue = load_plugin(queue_plugin)
    plugin_state.register(queue=queue)

    logger.info("Entering queue processing loop.")
    for job in queue.read():
        start_time = time.time()
        if job.is_expired:
            logger.info(
                "Discarding expired queue entry",
                uuid=str(job["uuid"]),
                reader=job["reader"],
            )
            continue

        reader = load_plugin(job["reader"],
                             parameters=job.get("parameters", None))
        plugin_state.register(queue=queue, reader=reader, writer=writer)
        logger.info("Will process queue entry.",
                    uuid=str(job["uuid"]),
                    reader=job["reader"])

        writer.write(reader.read())

        stop_time = time.time()
        duration = stop_time - start_time

        logger.info(
            "Finished processing queue entry.",
            uuid=str(job["uuid"]),
            reader=job["reader"],
            duration=duration,
        )
Esempio n. 2
0
def static_reader_writer_processor(writer, reader_plugin):
    reader = load_plugin(reader_plugin)
    plugin_state.register(reader=reader, writer=writer)

    logger.info("Entering read/write loop.")
    while True:
        writer.write(reader.read())

        if reader.is_one_shot_reader:
            break
Esempio n. 3
0
File: main.py Progetto: janw/uptimer
def main():
    logger = get_logger()
    logger.info(
        "Starting uptimer",
        starttime=datetime.now().isoformat(),
        env=settings.ENV_FOR_DYNACONF,
    )
    register_handlers()
    try:
        writer = load_plugin(settings.WRITER_PLUGIN)

        if settings.get("QUEUE_PLUGIN"):
            queue_processor(writer, settings.QUEUE_PLUGIN)
        else:
            static_reader_writer_processor(writer, settings.READER_PLUGIN)
    except Exception:  # pragma: no cover
        logger.exception("Caught exception in main. Exiting.", exc_info=True)
        os._exit(1)
Esempio n. 4
0
def test_load_plugin_from_invalid_entrypoint(entrypoint, error):

    with pytest.raises(error):
        load_plugin(entrypoint)
Esempio n. 5
0
def test_load_plugin_from_entrypoint(entrypoint, expected):
    plugin = load_plugin(entrypoint)

    assert isinstance(plugin, expected)
Esempio n. 6
0
def test_load_plugin_with_parameters(entrypoint, parameters, event_assertion):
    plugin = load_plugin(entrypoint, parameters=parameters)

    events = list(plugin.read())
    assert event_assertion(events)