async def parse_inspection_completed(inspection_completed: Dict[str, Any], openshift: OpenShift, **kwargs):
    """Schedule graph sync for inspection after completion."""
    wait_for_limit(openshift=openshift, workflow_namespace=openshift.middletier_namespace)
    workflow_name = openshift.schedule_graph_sync(
        inspection_completed["inspection_id"], force_sync=inspection_completed["force_sync"]
    )

    _LOGGER.debug(f"Graph sync workflow, {workflow_name}, for inspection {inspection_completed['inspection_id']}")
    inspection_completed_success.inc()
Example #2
0
def cli(scheduler_namespace: str,
        graph_sync_namespace: str,
        verbose: bool = False):
    """Scheduler handling Thoth's graph syncs."""
    if verbose:
        _LOGGER.setLevel(logging.DEBUG)

    _LOGGER.info(
        "Graph sync scheduler is running thoth-common in version %r, built from %r",
        thoth_common_version, os.getenv("OPENSHIFT_BUILD_COMMIT"))
    _LOGGER.info(
        "Graph sync scheduler is watching namespace %r and scheduling graph syncs in namespace %r",
        scheduler_namespace, graph_sync_namespace)

    openshift = OpenShift()

    queue = Queue()
    producer = Process(target=event_producer,
                       args=(queue, scheduler_namespace))

    producer.start()
    while producer.is_alive():
        template_name, document_id = queue.get()

        try:
            graph_sync_id = openshift.schedule_graph_sync(
                document_id, graph_sync_namespace, template_name=template_name)
            _LOGGER.info("Scheduled new graph sync with id %r", graph_sync_id)
        except Exception as exc:
            _LOGGER.exception(
                "Failed to run sync for document id %r, the template to be triggered was %r: %s",
                document_id, template_name, exc)

    producer.join()

    # Always fail, this should be run forever.
    sys.exit(1)