def test_local_agent_start_max_polls(monkeypatch, runner_token): on_shutdown = MagicMock() monkeypatch.setattr("prefect.agent.local.agent.LocalAgent.on_shutdown", on_shutdown) agent_process = MagicMock() monkeypatch.setattr("prefect.agent.agent.Agent.agent_process", agent_process) agent_connect = MagicMock(return_value="id") monkeypatch.setattr("prefect.agent.agent.Agent.agent_connect", agent_connect) heartbeat = MagicMock() monkeypatch.setattr("prefect.agent.local.agent.LocalAgent.heartbeat", heartbeat) agent = LocalAgent(max_polls=1) agent.start() assert agent_process.called assert heartbeat.called
"""Registers f to "Monitorfich" project. Args: f (prefect.Flow): Prefect flow """ f.register(project_name) if __name__ == "__main__": # Initialize a client, which can interact with the Prefect orchestrator. # The communication with the orchestrator is done through the Prefect GraphQL API. # This API is served on localhost:4200. print("Create client") client = prefect.Client() # Create the project "Monitorfish" in the orchestrator if it does not yet exist print("Create project") create_project_if_not_exists(client, PROJECT_NAME) # Register all flows print("Register flows") for f in flows_to_register: print(f"Register flow {f.name}") register_flow(f, PROJECT_NAME) # Start local "agent" process # This process queries the Prefect GraphQL API every second to ask if any new flows # should be run agent = LocalAgent(show_flow_logs=True) agent.start()