jason810496 commented on code in PR #64022:
URL: https://github.com/apache/airflow/pull/64022#discussion_r2973000634
##########
airflow-core/tests/unit/cli/commands/test_triggerer_command.py:
##########
@@ -82,6 +83,29 @@ def test_trigger_run_serve_logs(self, mock_process,
mock_run_job, mock_trigger_j
execute_callable=mock_trigger_job_runner.return_value._execute,
)
+ @mock.patch("airflow.cli.commands.triggerer_command.TriggererJobRunner")
+ @mock.patch("airflow.cli.commands.triggerer_command.run_job")
+ @mock.patch("airflow.cli.commands.triggerer_command._serve_logs")
+ def test_triggerer_run_sets_airflow_process_context_server(
+ self, mock_serve, mock_run_job, mock_triggerer_job_runner,
monkeypatch: pytest.MonkeyPatch
+ ):
+ """triggerer_run sets _AIRFLOW_PROCESS_CONTEXT=server before starting
the job runner."""
+ mock_triggerer_job_runner.return_value.job_type = "TriggererJob"
+ monkeypatch.delenv("_AIRFLOW_PROCESS_CONTEXT", raising=False)
+
+ triggerer_command.triggerer_run(
+ skip_serve_logs=True, capacity=100, triggerer_heartrate=5,
queues=None
+ )
+
+ assert os.environ.get("_AIRFLOW_PROCESS_CONTEXT") == "server"
+ mock_triggerer_job_runner.assert_called_once_with(job=mock.ANY,
capacity=100, queues=None)
+ mock_run_job.assert_called_once_with(
+ job=mock_triggerer_job_runner.return_value.job,
+ execute_callable=mock_triggerer_job_runner.return_value._execute,
+ )
Review Comment:
For the tests, it would be better to also verify the secret backend classes
we get, like:
https://github.com/apache/airflow/blob/3428dc98fc1958049f301ee6dea635d4833cd1e1/task-sdk/tests/task_sdk/execution_time/test_secrets.py#L194-L208
but import from `from airflow.sdk.configuration import
ensure_secrets_loaded` instead of importing from `from
airflow.sdk.execution_time.supervisor import ensure_secrets_backend_loaded `
(TaskSDK).
##########
airflow-core/src/airflow/cli/commands/triggerer_command.py:
##########
Review Comment:
It's almost the correct patch but actually we need to move the
`os.environ["_AIRFLOW_PROCESS_CONTEXT"] = "server"` to the `_execute` method of
Triggerer to make the behavior more consistent:
https://github.com/apache/airflow/blob/0decb3cbd1ecce2a6e55d6148f517f4cde6cefdd/airflow-core/src/airflow/jobs/triggerer_job_runner.py#L168
Like how we implement for scheduler:
https://github.com/apache/airflow/blob/4679057427e67435032e04a13f91f4c46b47abd2/airflow-core/src/airflow/jobs/scheduler_job_runner.py#L1435-L1439
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]