Exemplo n.º 1
0
def test_run(scheduler: Scheduler):
    with patch.object(scheduler, "task_queue") as task_queue, patch.object(
            scheduler, "models_metadata_info_provider") as md_client:
        md_client.get_projects.return_value = ["project1"]
        scheduler.run()

    task_queue.assert_has_calls([
        call.put_task(
            Task(project_name="project",
                 model_name=ANY,
                 from_time=ANY,
                 to_time=ANY))
    ])
Exemplo n.º 2
0
def test_run_intervals_sleep(clock_sleep_mock, scheduler: Scheduler):
    """Test scheduling behavior of the Clock.

    If interval is 5 minutes between scheduling predictions, logic is:
        10:01:00 - scheduler was run -> "sleep" for 4 mins;
        10:05:00 - first prediction scheduling made;
        10:10:00 - each next scheduling should be made in 5 mins;
        ...
    """
    times_now = ["10:01:00", "10:05:20", "10:10:25", "10:16:13"]
    expected_sleeps = [240.0, 280.0, 275.0, 227.0]

    datetime_now = [
        datetime.fromisoformat(f"2020-04-10T{t}.000000+00:00")
        for t in times_now
    ]
    with patch("latigo.clock.datetime") as mock_clock_dt, patch.object(
            scheduler, "_run", new=Mock()):
        mock_clock_dt.datetime.now.side_effect = datetime_now
        mock_clock_dt.date.side_effect = datetime_date
        mock_clock_dt.datetime.combine.side_effect = datetime.combine
        scheduler.run()
    clock_sleep_mock.assert_has_calls([call(secs) for secs in expected_sleeps])
Exemplo n.º 3
0
        "auth": {
            "resource":
            environ.get("LATIGO_GORDO_RESOURCE", not_found),
            "tenant":
            environ.get("LATIGO_GORDO_TENANT", not_found),
            "authority_host_url":
            environ.get("LATIGO_GORDO_AUTH_HOST_URL", not_found),
            "client_id":
            environ.get("LATIGO_GORDO_CLIENT_ID", not_found),
            "client_secret":
            environ.get("LATIGO_GORDO_CLIENT_SECRET", not_found),
        },
    },
}
# fmt: on

config_filename = environ.get("LATIGO_SCHEDULER_CONFIG_FILE",
                              "scheduler_config.yaml")

config = load_config(config_filename, config_overlay)
if not config:
    logger.error(
        f"Could not load configuration for scheduler from {config_filename}")
    sys.exit(1)

logger.info("Preparing Latigo Scheduler")
scheduler = Scheduler(config)
logger.info("Running Latigo Scheduler")
scheduler.run()
logger.info("Stopping Latigo Scheduler")