airflow.providers.ssh.utils.remote_job¶
Utilities for SSH remote job execution.
Attributes¶
Classes¶
Paths for remote job artifacts on the target system. |
Functions¶
|
Generate a unique job ID for remote execution. |
|
Build a POSIX shell wrapper that runs the command detached. |
|
Build a PowerShell wrapper that runs the command detached via |
|
Build a POSIX command to read log bytes from offset. |
|
Build a PowerShell command to read log bytes from offset. |
|
Build a POSIX command to get file size in bytes. |
|
Build a PowerShell command to get file size in bytes. |
|
Build a POSIX command to check if job completed and get exit code. |
|
Build a PowerShell command to check if job completed and get exit code. |
|
Build a POSIX command to kill the remote process. |
|
Build a PowerShell command to kill the remote process. |
|
Build a POSIX command to clean up the job directory. |
|
Build a PowerShell command to clean up the job directory. |
Build a command to detect if the remote system is POSIX-compliant. |
|
Build a command to detect if the remote system is Windows. |
Module Contents¶
- airflow.providers.ssh.utils.remote_job.WINDOWS_DEFAULT_BASE_DIR = '$env:TEMP\\airflow-ssh-jobs'[source]¶
- airflow.providers.ssh.utils.remote_job.generate_job_id(dag_id, task_id, run_id, try_number, suffix_length=8)[source]¶
Generate a unique job ID for remote execution.
Creates a deterministic identifier from the task context with a random suffix to ensure uniqueness across retries and potential race conditions.
- class airflow.providers.ssh.utils.remote_job.RemoteJobPaths[source]¶
Paths for remote job artifacts on the target system.
- airflow.providers.ssh.utils.remote_job.build_posix_wrapper_command(command, paths, environment=None)[source]¶
Build a POSIX shell wrapper that runs the command detached.
The wrapper:
Creates the job directory
Starts the command detached in its own session via
setsid(falling back tonohupwhensetsidis unavailable)Redirects stdout/stderr to the log file
Writes the exit code atomically on completion
Writes the PID for potential cancellation
- airflow.providers.ssh.utils.remote_job.build_windows_wrapper_command(command, paths, environment=None)[source]¶
Build a PowerShell wrapper that runs the command detached via
Win32_Process.Create.The wrapper:
Creates the job directory and writes the command into it as
cmd.ps1, next to the job script that runs itStarts the job script as a separate process that outlives the SSH session, in the SSH session’s working directory
Appends everything the command writes, on every stream, to the log file as UTF-8
Writes the exit code on completion, including when the command calls
exit, throws, or fails to parseWrites the PID for potential cancellation, and fails the submission if the job directory cannot be set up or the process cannot be started
The command runs as a script, so the host’s execution policy applies to it with
-ExecutionPolicy Bypassfor the process; a Group Policy that only allows signed scripts fails the job with the policy error in its log.
- airflow.providers.ssh.utils.remote_job.build_posix_log_tail_command(log_file, offset, max_bytes)[source]¶
Build a POSIX command to read log bytes from offset.
- airflow.providers.ssh.utils.remote_job.build_windows_log_tail_command(log_file, offset, max_bytes)[source]¶
Build a PowerShell command to read log bytes from offset.
The chunk is written to stdout as UTF-8 bytes. Printing it as a PowerShell string would re-encode it in the SSH session’s console code page, which the trigger’s strict UTF-8 decoding rejects for any non-ASCII character.
- airflow.providers.ssh.utils.remote_job.build_posix_file_size_command(file_path)[source]¶
Build a POSIX command to get file size in bytes.
- airflow.providers.ssh.utils.remote_job.build_windows_file_size_command(file_path)[source]¶
Build a PowerShell command to get file size in bytes.
- airflow.providers.ssh.utils.remote_job.build_posix_completion_check_command(exit_code_file)[source]¶
Build a POSIX command to check if job completed and get exit code.
- airflow.providers.ssh.utils.remote_job.build_windows_completion_check_command(exit_code_file)[source]¶
Build a PowerShell command to check if job completed and get exit code.
- airflow.providers.ssh.utils.remote_job.build_posix_kill_command(pid_file)[source]¶
Build a POSIX command to kill the remote process.
Signals the whole process group first (the negative-PID form
kill -<pgid>) so the user command and anything it spawned are terminated together, not just the wrapper. The recorded PID is the job’s session/group leader when it was launched undersetsid(seebuild_posix_wrapper_command()); if the job is not a group leader (host withoutsetsid), the group signal is a no-op and we fall back to killing the single PID, matching the previous behaviour.The pid value is validated as an integer
> 1before being negated: a corrupt or partial pid of0/1would otherwise turnkill -<pid>into a broadcast to every process the SSH account can signal. Best-effort: the command never fails the SSH call.
- airflow.providers.ssh.utils.remote_job.build_windows_kill_command(pid_file)[source]¶
Build a PowerShell command to kill the remote process.
Uses
taskkill /Tto terminate the recorded process and its child processes (the Windows equivalent of a process-group kill), so the user command launched by the detached wrapper is not left orphaned.$procIdis used instead of$pidbecause$PIDis a read-only automatic variable in PowerShell.
- airflow.providers.ssh.utils.remote_job.build_posix_cleanup_command(job_dir, base_dir=None)[source]¶
Build a POSIX command to clean up the job directory.
- Parameters:
- Returns:
Shell command to remove the directory
- Raises:
ValueError – If job_dir is not under the expected base directory
- Return type:
- airflow.providers.ssh.utils.remote_job.build_windows_cleanup_command(job_dir, base_dir=None)[source]¶
Build a PowerShell command to clean up the job directory.
- Parameters:
- Returns:
PowerShell command to remove the directory
- Raises:
ValueError – If job_dir is not under the expected base directory
- Return type: