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 Start-Process. |
|
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 Start-Process.
The wrapper:
Creates the job directory
Starts the command in a new detached PowerShell process
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_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.
- 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)[source]¶
Build a POSIX command to clean up the job directory.
- Parameters:
job_dir (str) – Path to the job directory
- 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)[source]¶
Build a PowerShell command to clean up the job directory.
- Parameters:
job_dir (str) – Path to the job directory
- Returns:
PowerShell command to remove the directory
- Raises:
ValueError – If job_dir is not under the expected base directory
- Return type: