Beispiel #1
0
async def _run_flow(
    caplog: Optional[pytest.LogCaptureFixture],
    schd: Scheduler,
    level: int = logging.INFO
):
    """Start a scheduler and set it running."""
    if caplog:
        caplog.set_level(level, CYLC_LOG)

    # install
    await schd.install()

    # start
    try:
        await schd.start()
    except Exception as exc:
        async with timeout(5):
            await schd.shutdown(exc)
    # run
    try:
        task = asyncio.create_task(schd.run_scheduler())
        yield caplog

    # stop
    finally:
        async with timeout(5):
            # ask the scheduler to shut down nicely
            schd._set_stop(StopMode.REQUEST_NOW_NOW)
            await task

        if task:
            # leave everything nice and tidy
            task.cancel()
Beispiel #2
0
async def _run_flow(run_dir: Path,
                    caplog: Optional[pytest.LogCaptureFixture],
                    scheduler: Scheduler,
                    level: int = logging.INFO):
    """Start a scheduler."""
    contact = (run_dir / scheduler.workflow / WorkflowFiles.Service.DIRNAME /
               WorkflowFiles.Service.CONTACT)
    if caplog:
        caplog.set_level(level, CYLC_LOG)
    task = None
    started = False
    await scheduler.install()
    try:
        task = asyncio.get_event_loop().create_task(scheduler.run())
        started = await _poll_file(contact)
        yield caplog
    finally:
        if started:
            # ask the scheduler to shut down nicely
            async with timeout(5):
                scheduler._set_stop(StopMode.REQUEST_NOW_NOW)
                await task

        if task:
            # leave everything nice and tidy
            task.cancel()
Beispiel #3
0
async def _run_flow(caplog: Optional[pytest.LogCaptureFixture],
                    schd: Scheduler,
                    level: int = logging.INFO):
    """Start a scheduler and set the main loop running."""
    if caplog:
        caplog.set_level(level, CYLC_LOG)

    await schd.install()

    task: Optional[asyncio.Task] = None
    try:
        # Nested `try...finally` to ensure caplog always yielded even if
        # exception occurs in Scheduler
        try:
            await schd.start()
            # Do not await as we need to yield control to the main loop:
            task = asyncio.create_task(schd.run_scheduler())
        finally:
            # After this `yield`, the `with` block of the context manager
            # is executed:
            yield caplog
    finally:
        # Cleanup - this always runs after the `with` block of the
        # context manager.
        # Need to shut down Scheduler, but time out in case something
        # goes wrong:
        async with timeout(5):
            if task:
                # ask the scheduler to shut down nicely,
                # let main loop handle it:
                schd._set_stop(StopMode.REQUEST_NOW_NOW)
                await task
        if schd.contact_data:
            async with timeout(5):
                # Scheduler still running... try more forceful tear down:
                await schd.shutdown(SchedulerStop("integration test teardown"))
        if task:
            # Brute force cleanup if something went wrong:
            task.cancel()