Skip to content

Commit cdd1c5f

Browse files

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use super::WorkersSchedule;
4+
5+
use crate::framework::{
6+
endpoint::{EndpointSpec, Method},
7+
response::{ApiResult, ApiSuccess},
8+
};
9+
10+
/// List Schedules
11+
/// <https://developers.cloudflare.com/api/resources/workers/subresources/scripts/subresources/schedules/methods/get/>
12+
#[derive(Debug)]
13+
pub struct ListSchedules<'a> {
14+
/// Account ID of owner of the script
15+
pub account_identifier: &'a str,
16+
/// The name of the script to list the schedules
17+
pub script_name: &'a str,
18+
}
19+
20+
#[derive(Debug, Deserialize, Serialize)]
21+
pub struct ListSchedulesResponse {
22+
pub schedules: Vec<WorkersSchedule>,
23+
}
24+
25+
impl ApiResult for ListSchedulesResponse {}
26+
27+
impl EndpointSpec for ListSchedules<'_> {
28+
type JsonResponse = ListSchedulesResponse;
29+
type ResponseType = ApiSuccess<Self::JsonResponse>;
30+
31+
fn method(&self) -> Method {
32+
Method::GET
33+
}
34+
35+
fn path(&self) -> String {
36+
format!(
37+
"accounts/{}/workers/scripts/{}/schedules",
38+
self.account_identifier, self.script_name
39+
)
40+
}
41+
}

cloudflare/src/endpoints/workers/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ mod delete_secret;
1313
mod delete_tail;
1414
mod list_bindings;
1515
mod list_routes;
16+
mod list_schedules;
1617
mod list_secrets;
1718
mod list_tails;
1819
mod send_tail_heartbeat;
20+
mod update_schedules;
1921

2022
pub use create_route::{CreateRoute, CreateRouteParams};
2123
pub use create_secret::{CreateSecret, CreateSecretParams};
@@ -27,9 +29,11 @@ pub use delete_secret::DeleteSecret;
2729
pub use delete_tail::DeleteTail;
2830
pub use list_bindings::ListBindings;
2931
pub use list_routes::ListRoutes;
32+
pub use list_schedules::{ListSchedules, ListSchedulesResponse};
3033
pub use list_secrets::ListSecrets;
3134
pub use list_tails::ListTails;
3235
pub use send_tail_heartbeat::SendTailHeartbeat;
36+
pub use update_schedules::{UpdateSchedules, UpdateSchedulesResponse};
3337

3438
/// Workers KV Route
3539
/// Routes are basic patterns used to enable or disable workers that match requests.
@@ -157,6 +161,17 @@ pub enum WorkersBinding {
157161
impl ApiResult for WorkersBinding {}
158162
impl ApiResult for Vec<WorkersBinding> {}
159163

164+
// Schedule for a Workers Script
165+
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Default, PartialOrd, Ord)]
166+
pub struct WorkersSchedule {
167+
pub cron: Option<String>,
168+
pub created_on: Option<String>,
169+
pub modified_on: Option<String>,
170+
}
171+
172+
impl ApiResult for WorkersSchedule {}
173+
impl ApiResult for Vec<WorkersSchedule> {}
174+
160175
#[cfg(test)]
161176
mod tests {
162177
use std::collections::VecDeque;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use serde::Deserialize;
2+
3+
use super::WorkersSchedule;
4+
5+
use crate::framework::{
6+
endpoint::{EndpointSpec, Method, RequestBody},
7+
response::{ApiResult, ApiSuccess},
8+
};
9+
10+
/// Update Schedules
11+
/// <https://developers.cloudflare.com/api/resources/workers/subresources/scripts/subresources/schedules/methods/update/>
12+
#[derive(Debug)]
13+
pub struct UpdateSchedules<'a> {
14+
/// Account ID of owner of the script
15+
pub account_identifier: &'a str,
16+
/// Name of the script, used in URLs and route configuration.
17+
pub script_name: &'a str,
18+
/// Schedules to be updated
19+
pub schedules: Vec<WorkersSchedule>,
20+
}
21+
22+
#[derive(Debug, Deserialize)]
23+
pub struct UpdateSchedulesResponse {
24+
pub schedules: Vec<WorkersSchedule>,
25+
}
26+
27+
impl ApiResult for UpdateSchedulesResponse {}
28+
29+
impl EndpointSpec for UpdateSchedules<'_> {
30+
type JsonResponse = UpdateSchedulesResponse;
31+
type ResponseType = ApiSuccess<Self::JsonResponse>;
32+
33+
fn method(&self) -> Method {
34+
Method::PUT
35+
}
36+
37+
fn path(&self) -> String {
38+
format!(
39+
"accounts/{}/workers/scripts/{}/schedules",
40+
self.account_identifier, self.script_name
41+
)
42+
}
43+
44+
#[inline]
45+
fn body(&self) -> Option<RequestBody> {
46+
let body = serde_json::to_string(&self.schedules).unwrap();
47+
Some(RequestBody::Json(body))
48+
}
49+
}

0 commit comments

Comments
 (0)