// The externally facing API allowing users to interact with jobs. edition = "2023"; package workflows.v1; import "buf/validate/validate.proto"; import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; import "tilebox/v1/id.proto"; import "tilebox/v1/query.proto"; import "workflows/v1/core.proto"; import "workflows/v1/diagram.proto"; option features.field_presence = IMPLICIT; // SubmitJobRequest submits and schedules a job for execution. The job can have multiple root tasks. message SubmitJobRequest { option (buf.validate.message).cel = { id: "submit_job_request.tasks_required" message: "At least one task must be submitted." expression: "(this.tasks != null && this.tasks.task_groups.size() > 0) || this.legacy_tasks.size() > 0" }; // The root tasks for the job. TaskSubmissions tasks = 5; // The name of the job. string job_name = 2 [(buf.validate.field).string.min_len = 1]; // Optional. Tracing information for the job. If omitted, the service generates a new trace parent. // This is used to propagate tracing information to the workers that execute the job. string trace_parent = 3; // Optional. The ID of the automation that submits this job. tilebox.v1.ID automation_id = 4; // The root tasks for the job. This field is deprecated and will be removed in the future. Kept around for backwards // compatibility. repeated SingleTaskSubmission legacy_tasks = 1 [ deprecated = true, // we support more than that due to grouping and tree spawning, but we rather want to encourage users // to update their clients to use the new field which has way less serialization overhead. (buf.validate.field).repeated.max_items = 1000 ]; } // GetJobRequest requests details for a job. message GetJobRequest { // The ID of the job to get details for. tilebox.v1.ID job_id = 1 [(buf.validate.field).required = true]; } // TaskSummary is a compact representation of a task within a job's task tree. message TaskSummary { // The ID of the task. Tasks are ordered by this ID within a sibling collection. tilebox.v1.ID id = 1; // The ID of the closest non-virtual ancestor task. It is absent for a root task. tilebox.v1.ID parent_id = 2 [features.field_presence = EXPLICIT]; // A human-readable representation of the task. string display = 3; // The current state of the task. TaskState state = 4; // The time the task was submitted. google.protobuf.Timestamp submitted_at = 5; // The time the task started running. google.protobuf.Timestamp started_at = 6; // The time the task stopped running. google.protobuf.Timestamp stopped_at = 7; // The serialized input parameters in the format expected by the task. bytes input = 8 [features.field_presence = EXPLICIT]; // The number of times the task has been retried. int64 retry_count = 9; // The maximum number of times the task may be retried. int64 max_retries = 10; // Whether the task has children in the user-visible tree. bool has_children = 11; // The slug of the cluster on which the task is scheduled to run. string cluster_slug = 12; // Whether failure of the task is optional, either directly or through an optional ancestor. bool optional = 13; // The remote reference of the task's workflow, owner-local or namespace-qualified as in Workflow.reference. // Absent for unscoped tasks or deleted workflows. Omission does not change the task's stored execution scope. string workflow_reference = 14 [features.field_presence = EXPLICIT]; } // JobTaskChildrenPrefetch configures the child pages included with the requested task page. message JobTaskChildrenPrefetch { // The maximum number of user-visible children to return for each task in the requested page. int64 limit = 1 [(buf.validate.field).int64 = { gte: 1 lte: 100 }]; } // ListJobTasksRequest requests one page from a job's task tree. message ListJobTasksRequest { // The ID of the job whose tasks to list. tilebox.v1.ID job_id = 1 [(buf.validate.field).required = true]; // The parent whose user-visible children to list. If absent, root tasks are listed. tilebox.v1.ID parent_task_id = 2 [features.field_presence = EXPLICIT]; // The pagination parameters for the requested sibling collection. tilebox.v1.Pagination page = 3 [features.field_presence = EXPLICIT]; // Optional configuration for prefetching one user-visible child page per returned task. JobTaskChildrenPrefetch prefetch_children = 4 [features.field_presence = EXPLICIT]; } // JobTaskPage is one page of a job's root tasks or one parent's user-visible children. message JobTaskPage { // The user-visible parent of this sibling collection. It is absent for the root collection. tilebox.v1.ID parent_task_id = 1 [features.field_presence = EXPLICIT]; // The tasks in this page, ordered by ascending task ID. repeated TaskSummary tasks = 2; // The pagination parameters for the next page of this sibling collection. tilebox.v1.Pagination next_page = 3 [features.field_presence = EXPLICIT]; } // ListJobTasksResponse contains the requested task page and any prefetched child pages. message ListJobTasksResponse { // The requested page. JobTaskPage page = 1; // The first user-visible child page for each task in page that has children. repeated JobTaskPage prefetched_child_pages = 2; } // JobTaskQueryFilters restricts which tasks match. All supplied filters must match. message JobTaskQueryFilters { // Filter tasks by task states. An empty list matches all states. // FAILED does not include FAILED_OPTIONAL. repeated TaskState states = 1; // Filter tasks by display text. Empty means no display filter. string display = 2 [(buf.validate.field).string.max_len = 100]; } // QueryJobTasksRequest selects user-visible tasks at any depth in a single job. message QueryJobTasksRequest { tilebox.v1.ID job_id = 1 [(buf.validate.field).required = true]; JobTaskQueryFilters filters = 2; tilebox.v1.Pagination page = 3 [features.field_presence = EXPLICIT]; } // QueryJobTasksResponse contains a flat page of matching tasks across the job. message QueryJobTasksResponse { // Matching tasks, ordered by ascending task ID. repeated TaskSummary tasks = 1; tilebox.v1.Pagination next_page = 2 [features.field_presence = EXPLICIT]; } // RetryJobRequest requests a retry of a job that has failed. message RetryJobRequest { // The job to retry. tilebox.v1.ID job_id = 1 [(buf.validate.field).required = true]; } // RetryJobResponse is the response to a RetryJobRequest. message RetryJobResponse { // The number of tasks that were rescheduled. int64 num_tasks_rescheduled = 1; } // CancelJobRequest requests a cancel of a job. message CancelJobRequest { // The job to cancel. tilebox.v1.ID job_id = 1 [(buf.validate.field).required = true]; } // CancelJobResponse is the response to a CancelJobRequest. message CancelJobResponse { // no fields at the moment } // The theme in which to render a workflow diagram enum WorkflowDiagramTheme { WORKFLOW_DIAGRAM_THEME_UNSPECIFIED = 0; WORKFLOW_DIAGRAM_THEME_LIGHT = 1; WORKFLOW_DIAGRAM_THEME_DARK = 2; WORKFLOW_DIAGRAM_THEME_CONSOLE_LIGHT = 3; WORKFLOW_DIAGRAM_THEME_CONSOLE_DARK = 4; } // VisualizeJobRequest requests a visualization of a job. message VisualizeJobRequest { // The job to visualize. tilebox.v1.ID job_id = 1 [(buf.validate.field).required = true]; // The options for rendering the diagram RenderOptions render_options = 2; // The theme to render the workflow diagram in WorkflowDiagramTheme theme = 3; // whether to include the job name as title in the diagram bool include_job_name = 4; } // QueryFilters contains the filters to apply to a query. message QueryFilters { option (buf.validate.message).oneof = { fields: [ "time_interval", "id_interval" ] required: false }; // Filters by job submission time. If absent or neither bound is set, submission time is not restricted. If only // start_time is set, it is used as the lower bound. If only end_time is set, it is used as the upper bound. If both // are set, jobs between the two bounds are returned. start_exclusive and end_inclusive control whether each bound is // included. tilebox.v1.TimeInterval time_interval = 1; // Filters by job ID. If absent or neither bound is set, job ID is not restricted. If only start_id is set, it is used // as the lower bound. If only end_id is set, it is used as the upper bound. If both are set, jobs between the two // bounds are returned. start_exclusive and end_inclusive control whether each bound is included. tilebox.v1.IDInterval id_interval = 2; // Filter jobs by automations. repeated tilebox.v1.ID automation_ids = 3; // Filter jobs by states. repeated JobState states = 4; // Filter jobs by name. string name = 5 [(buf.validate.field).string.max_len = 100]; // Filter jobs by their tasks (whether they have tasks in a certain state). repeated TaskState task_states = 6; // Filter jobs by their clusters (whether they have tasks on certain clusters). repeated string cluster_slugs = 7; // Filter jobs having at least one task scoped to any of these workflow references. // Empty means no workflow filter. Unscoped tasks never match. repeated string workflow_references = 8 [ (buf.validate.field).repeated.items.string.min_len = 1, (buf.validate.field).repeated.items.string.max_len = 201, (buf.validate.field).repeated.items.string.pattern = "^([a-z0-9]+(-[a-z0-9]+)*:)?[A-Za-z0-9-]{1,100}$", (buf.validate.field).repeated.items.cel = { id: "workflow_reference.namespace_length" message: "workflow namespace must be at most 100 characters" expression: "!this.contains(':') || this.split(':')[0].size() <= 100" } ]; } // QueryJobsRequest requests a list of jobs. message QueryJobsRequest { // Filters to apply to the query. QueryFilters filters = 1; // The pagination parameters for this request. tilebox.v1.Pagination page = 2 [features.field_presence = EXPLICIT]; // The sort order for jobs (by submission date). Defaults to descending order (newest jobs first). tilebox.v1.SortDirection sort_direction = 3; } // A list of jobs. message QueryJobsResponse { // The jobs. repeated Job jobs = 1; // The pagination parameters for the next page. tilebox.v1.Pagination next_page = 3 [features.field_presence = EXPLICIT]; } // GetJobPrototypeRequest requests a clone prototype of a job. message GetJobPrototypeRequest { // The ID of the job to get a clone prototype for. tilebox.v1.ID job_id = 1 [(buf.validate.field).required = true]; } // A clone prototype of a job. message GetJobPrototypeResponse { // The root tasks of the job. repeated SingleTaskSubmission root_tasks = 1; // The name of the job. string job_name = 2; } // CloneJobRequest requests a clone of a job. message CloneJobRequest { // The ID of the job to clone. tilebox.v1.ID job_id = 1 [(buf.validate.field).required = true]; // The updated root tasks of the job. repeated SingleTaskSubmission root_tasks_overrides = 2 [(buf.validate.field).repeated = { min_items: 1 max_items: 64 }]; // The name of the job. string job_name = 3 [(buf.validate.field).string.min_len = 1]; } // GetJobStateCountsRequest requests counts of jobs by their state, optionally filtered by submission time. message GetJobStateCountsRequest { // Filters by job submission time. If absent or neither bound is set, submission time is not restricted. If only // start_time is set, it is used as the lower bound. If only end_time is set, it is used as the upper bound. If both // are set, jobs between the two bounds are counted. start_exclusive and end_inclusive control whether each bound is // included. tilebox.v1.TimeInterval time_interval = 1; } // GetJobStateCountsResponse is the response to a GetJobStateCountsRequest, containing counts of jobs by their state. message GetJobStateCountsResponse { repeated JobStateCount state_counts = 1; int64 total_jobs = 2; } // JobStateCount is a message that represents the count of jobs for a specific state. message JobStateCount { workflows.v1.JobState state = 1; uint64 count = 2; } // GetTaskQueueStatsRequest requests statistics about jobs in the task queue, filtered by submission time. message GetTaskQueueStatsRequest { option (buf.validate.message).oneof = { fields: [ "job_time_interval", "job_max_age" ] required: false }; // Filters by job submission time. If absent or neither bound is set, submission time is not restricted. If only // start_time is set, it is used as the lower bound. If only end_time is set, it is used as the upper bound. If both // are set, jobs between the two bounds are considered. start_exclusive and end_inclusive control whether each bound // is included. tilebox.v1.TimeInterval job_time_interval = 1; // Filters to jobs submitted within this duration before the current time. google.protobuf.Duration job_max_age = 2; } // GetTaskQueueStatsResponse represents statistics about jobs and tasks in the task queue. message GetTaskQueueStatsResponse { // Jobs in SUBMITTED or STARTED. uint64 waiting_jobs = 1; // Jobs in RUNNING. uint64 running_jobs = 2; // QUEUED tasks across all jobs in SUBMITTED, STARTED, or RUNNING state. uint64 queued_tasks = 3; // The oldest job in the requested interval in SUBMITTED or STARTED state. // Will have the id, name, and submitted_at fields set. If there are no waiting jobs, this field will be absent. Job oldest_waiting_job = 4; } // A service for interacting with jobs. service JobService { rpc SubmitJob(SubmitJobRequest) returns (Job); rpc GetJob(GetJobRequest) returns (Job); rpc ListJobTasks(ListJobTasksRequest) returns (ListJobTasksResponse); rpc QueryJobTasks(QueryJobTasksRequest) returns (QueryJobTasksResponse); rpc RetryJob(RetryJobRequest) returns (RetryJobResponse); rpc CancelJob(CancelJobRequest) returns (CancelJobResponse); rpc VisualizeJob(VisualizeJobRequest) returns (Diagram); rpc QueryJobs(QueryJobsRequest) returns (QueryJobsResponse); rpc GetJobPrototype(GetJobPrototypeRequest) returns (GetJobPrototypeResponse); rpc CloneJob(CloneJobRequest) returns (Job); rpc GetJobStateCounts(GetJobStateCountsRequest) returns (GetJobStateCountsResponse); rpc GetTaskQueueStats(GetTaskQueueStatsRequest) returns (GetTaskQueueStatsResponse); }