apify_client/clients/run_collection.rs
1//! Client for an Actor-run collection (`/v2/actor-runs`, `/v2/actors/{id}/runs`, etc.).
2
3use crate::clients::base::{list_resource, ResourceContext};
4use crate::common::{ListOptions, PaginationList, QueryParams};
5use crate::error::ApifyClientResult;
6use crate::http_client::HttpClient;
7use crate::models::ActorRun;
8
9/// Filtering options for [`RunCollectionClient::list`], covering the spec query parameters of
10/// `GET /v2/actor-runs` and `GET /v2/actors/{actorId}/runs`.
11///
12/// As in the reference client, the same options type is reused for the task-scoped run
13/// collection (`GET /v2/actor-tasks/{actorTaskId}/runs`), whose spec does not define
14/// `startedAfter`/`startedBefore`; those params are simply ignored server-side when set on a
15/// task-scoped list. This deliberate reference-parity reuse keeps the API surface uniform.
16#[derive(Debug, Default, Clone)]
17pub struct RunListOptions {
18 /// Only return runs with one of these statuses (e.g. `SUCCEEDED`, `RUNNING`). The API
19 /// accepts multiple statuses; they are sent as a comma-separated list. Empty means no
20 /// status filter. Matches the reference client, whose `status` accepts a string or array.
21 pub status: Vec<String>,
22 /// Only return runs started at or after this ISO 8601 timestamp. (Actor-scoped lists only.)
23 pub started_after: Option<String>,
24 /// Only return runs started at or before this ISO 8601 timestamp. (Actor-scoped lists only.)
25 pub started_before: Option<String>,
26}
27
28/// Client for listing Actor runs.
29#[derive(Debug, Clone)]
30pub struct RunCollectionClient {
31 ctx: ResourceContext,
32}
33
34impl RunCollectionClient {
35 pub(crate) fn new(http: HttpClient, base_url: &str, resource_path: &str) -> Self {
36 Self {
37 ctx: ResourceContext::collection(http, base_url, resource_path),
38 }
39 }
40
41 /// Lists runs with offset/limit pagination and optional status/started-time filtering.
42 pub async fn list(
43 &self,
44 options: ListOptions,
45 filter: RunListOptions,
46 ) -> ApifyClientResult<PaginationList<ActorRun>> {
47 let mut params = QueryParams::new();
48 params
49 .add_int("offset", options.offset)
50 .add_int("limit", options.limit)
51 .add_bool("desc", options.desc)
52 .add_csv("status", Some(&filter.status))
53 .add_str("startedAfter", filter.started_after)
54 .add_str("startedBefore", filter.started_before);
55 list_resource(&self.ctx, None, ¶ms).await
56 }
57}