# Job Commands Manage and execute Treasure Data jobs (queries). ## Commands ```bash tdx jobs # List jobs tdx job list # Same as jobs tdx job schedule list # List scheduled queries ``` ## List Jobs ```bash # List jobs (default: 40 jobs) tdx jobs # List more jobs tdx jobs --limit 100 # Filter by status tdx jobs --status running tdx jobs --status success tdx jobs --status error tdx jobs --status queued # Combine filters tdx jobs --status running --limit 50 # Output as JSON tdx jobs --json ``` ## Show Job Details ```bash # Show job details tdx job show # Show as JSON tdx job show --json ``` ## Submit Jobs ```bash # Submit Trino query (default) tdx job submit "SELECT * FROM mydb.table LIMIT 10" # Submit with specific database tdx job submit "SELECT * FROM table" --database mydb # Submit Hive query from file tdx job submit --job-type hive -f query.sql --database mydb # Submit without specifying database tdx job submit "SELECT 1" # Submit with result export destination (URL format) tdx job submit "SELECT * FROM table" --database mydb --result "s3://bucket/path" # Submit with result export destination (JSON format) tdx job submit "SELECT * FROM table" --database mydb \ --result '{"type":"s3_v2","td_authentication_id":12345,"bucket":"my-bucket","path":"/output/result.csv","format":"csv"}' ``` ## Get Job Results ```bash # Get job results (table format) tdx job result # Get results as JSON tdx job result --json # Save results to file tdx job result --output results.json # Get results as TSV tdx job result --tsv ``` ## Kill a Job ```bash # Kill a job (with confirmation) tdx job kill # Skip confirmation prompt tdx job kill --yes ``` ## Job Command Options | Option | Description | Default | | --- | --- | --- | | `--job-type ` | Job type (`trino` or `hive`) | trino | | `-f, --file ` | Read query from file | - | | `--database ` | Database name | information_schema | | `--result ` | Result export destination (URL or JSON) | - | | `--status ` | Filter by status (for `jobs` list) | - | | `--limit ` | Maximum jobs to list | 40 | ## Status Values | Status | Description | | --- | --- | | `queued` | Job is waiting to run | | `running` | Job is currently executing | | `success` | Job completed successfully | | `error` | Job failed with an error | ## Scheduled Queries Manage scheduled queries (cron-based job execution). ### List Schedules ```bash # List all scheduled queries tdx job schedule list # Filter by wildcard pattern tdx job schedule list "daily*" # Starts with "daily" tdx job schedule list "*_sync" # Ends with "_sync" tdx job schedule list "*hourly*" # Contains "hourly" tdx job schedule list "report_?" # Single character wildcard # Limit results tdx job schedule list --limit 100 # Output as JSON tdx job schedule list --json ``` The default output shows a compact list with status icon, last run time, next run time, cron expression, and schedule name (with link to TD Console). #### Pattern Syntax | Pattern | Matches | | --- | --- | | `*` | Any characters (zero or more) | | `?` | Any single character | Pattern matching is case-insensitive. ### Show Schedule Details ```bash # Show schedule details tdx job schedule show # Show as JSON tdx job schedule show --json ``` ### Create a Schedule ```bash # Create a scheduled query (minimal) tdx job schedule create my-schedule \ -d mydb \ --file query.sql # Create with cron expression tdx job schedule create my-schedule \ -d mydb \ --file query.sql \ --cron "0 0 * * *" \ --timezone "America/Los_Angeles" # Create with all options tdx job schedule create my-schedule \ -d mydb \ --file query.sql \ --type trino \ --cron "0 0 * * *" \ --timezone "America/Los_Angeles" \ --delay 60 \ --priority 1 \ --retry-limit 3 \ --engine-version stable \ --result "td://mydb/result_table" ``` ### Update a Schedule ```bash # Update cron expression tdx job schedule update my-schedule --cron "0 12 * * *" # Update query from file tdx job schedule update my-schedule --file new-query.sql # Update multiple options tdx job schedule update my-schedule \ -d newdb \ --priority 2 \ --retry-limit 5 ``` ### Delete a Schedule ```bash # Delete a schedule (with confirmation) tdx job schedule delete my-schedule # Skip confirmation prompt tdx job schedule delete my-schedule --yes ``` ### Run a Schedule Immediately ```bash # Run immediately with current time tdx job schedule run my-schedule # Run with specific scheduled time tdx job schedule run my-schedule --time "2025-01-15T00:00:00Z" # Run multiple times (1-10) tdx job schedule run my-schedule --num 3 ``` ### Show Schedule History ```bash # Show execution history (default: last 20) tdx job schedule history my-schedule # Show with pagination tdx job schedule history my-schedule --from 0 --to 50 # Output as JSON tdx job schedule history my-schedule --json ``` ### Schedule Command Options #### Create Options | Option | Description | Default | | --- | --- | --- | | `-d, --database ` | Database name (required, global option) | - | | `-f, --file ` | Read query from file (required) | - | | `--type ` | Query type (`trino` or `hive`) | trino | | `--cron ` | Cron expression for scheduling | - | | `--timezone ` | Timezone for cron | UTC | | `--delay ` | Delay in seconds before execution | - | | `--priority <-2~2>` | Job priority (-2 to 2) | - | | `--retry-limit <0~32>` | Retry limit (0 to 32) | - | | `--engine-version ` | Query engine version | - | | `--result ` | Result output destination URL | - | #### Update Options All create options are available (all are optional for update). #### Run Options | Option | Description | Default | | --- | --- | --- | | `--time ` | Scheduled time (ISO 8601 format) | now | | `--num <1-10>` | Number of executions | 1 | #### List Options | Option | Description | Default | | --- | --- | --- | | `[pattern]` | Wildcard pattern to filter names (`*` any chars, `?` single char) | - | | `--limit ` | Maximum schedules to return | 40 | #### History Options | Option | Description | Default | | --- | --- | --- | | `--from ` | Starting offset | 0 | | `--to ` | Ending offset | 20 |