google_cloud_bigquery/http/job/
list.rs

1use reqwest_middleware::{ClientWithMiddleware as Client, RequestBuilder};
2
3use crate::http::job::{JobConfiguration, JobReference, JobState, JobStatistics, JobStatus};
4use crate::http::types::ErrorProto;
5
6#[derive(Clone, PartialEq, serde::Deserialize, serde::Serialize, Debug, Default)]
7#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
8pub enum Projection {
9    #[default]
10    Manual,
11    Full,
12}
13
14#[derive(Clone, PartialEq, serde::Deserialize, serde::Serialize, Debug, Default)]
15#[serde(rename_all = "camelCase")]
16pub struct ListJobsRequest {
17    /// Whether to display jobs owned by all users in the project. Default False.
18    pub all_users: Option<bool>,
19    /// The maximum number of results to return in a single response page. Leverage the page tokens to iterate through the entire collection.
20    pub max_results: Option<i64>,
21    /// Min value for job creation time, in milliseconds since the POSIX epoch.
22    /// If set, only jobs created after or at this timestamp are returned.
23    pub min_creation_time: Option<u64>,
24    /// Max value for job creation time, in milliseconds since the POSIX epoch.
25    /// If set, only jobs created before or at this timestamp are returned.
26    pub max_creation_time: Option<u64>,
27    /// Restrict information returned to a set of selected fields
28    pub projection: Option<Projection>,
29    /// Filter for job state
30    pub state_filter: Option<Vec<JobState>>,
31    /// If set, show only child jobs of the specified parent. Otherwise, show all top-level jobs.
32    pub parent_job_id: String,
33}
34
35#[derive(Clone, PartialEq, serde::Deserialize, serde::Serialize, Debug, Default)]
36#[serde(rename_all = "camelCase")]
37pub struct JobOverview {
38    /// Unique opaque ID of the job.
39    pub id: String,
40    /// The resource type.
41    pub kind: String,
42    /// Unique opaque ID of the job.
43    pub job_reference: JobReference,
44    /// Running state of the job. When the state is DONE,
45    /// errorResult can be checked to determine whether the job succeeded or failed.
46    pub state: JobState,
47    /// A result object that will be present only if the job has failed.
48    pub error_result: Option<ErrorProto>,
49    /// Output only. Information about the job, including starting time and ending time of the job.
50    pub statistics: Option<JobStatistics>,
51    /// Required. Describes the job configuration.
52    pub configuration: JobConfiguration,
53    /// [Full-projection-only] Describes the status of this job.
54    pub status: Option<JobStatus>,
55    /// [Full-projection-only] Email address of the user who ran the job.
56    pub user_email: Option<String>,
57    /// [Full-projection-only] String representation of identity of requesting party.
58    /// Populated for both first- and third-party identities.
59    /// Only present for APIs that support third-party identities.
60    pub principal_subject: Option<String>,
61}
62
63#[derive(Clone, PartialEq, serde::Deserialize, serde::Serialize, Debug, Default)]
64#[serde(rename_all = "camelCase")]
65pub struct ListJobsResponse {
66    /// A hash of this page of results.
67    pub etag: String,
68    /// The resource type of the response.
69    pub kind: String,
70    /// A token to request the next page of results.
71    pub next_page_token: Option<String>,
72    /// List of jobs that were requested.
73    pub jobs: Vec<JobOverview>,
74}
75
76pub fn build(
77    base_url: &str,
78    client: &Client,
79    project_id: &str,
80    data: &ListJobsRequest,
81    page_token: Option<String>,
82) -> RequestBuilder {
83    let url = format!("{}/projects/{}/jobs", base_url, project_id);
84    let builder = client.get(url).query(data);
85    if let Some(page_token) = page_token {
86        builder.query(&[("pageToken", page_token.as_str())])
87    } else {
88        builder
89    }
90}