-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathschedule_collection.py
More file actions
162 lines (133 loc) · 5.93 KB
/
schedule_collection.py
File metadata and controls
162 lines (133 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from apify_client._utils import filter_out_none_values_recursively
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync
from apify_client.clients.resource_clients.schedule import _get_schedule_representation
if TYPE_CHECKING:
from apify_client.clients.base.resource_collection_client import ListPage
class ScheduleCollectionClient(ResourceCollectionClient):
"""Sub-client for manipulating schedules."""
def __init__(self, *args: Any, **kwargs: Any) -> None:
resource_path = kwargs.pop('resource_path', 'schedules')
super().__init__(*args, resource_path=resource_path, **kwargs)
def list(
self,
*,
limit: int | None = None,
offset: int | None = None,
desc: bool | None = None,
) -> ListPage[dict]:
"""List the available schedules.
https://docs.apify.com/api/v2#/reference/schedules/schedules-collection/get-list-of-schedules
Args:
limit: How many schedules to retrieve.
offset: What schedules to include as first when retrieving the list.
desc: Whether to sort the schedules in descending order based on their modification date.
Returns:
The list of available schedules matching the specified filters.
"""
return self._list(limit=limit, offset=offset, desc=desc)
def create(
self,
*,
cron_expression: str,
is_enabled: bool,
is_exclusive: bool,
name: str | None = None,
actions: list[dict] | None = None, # ty: ignore[invalid-type-form]
description: str | None = None,
timezone: str | None = None,
title: str | None = None,
) -> dict:
"""Create a new schedule.
https://docs.apify.com/api/v2#/reference/schedules/schedules-collection/create-schedule
Args:
cron_expression: The cron expression used by this schedule.
is_enabled: True if the schedule should be enabled.
is_exclusive: When set to true, don't start Actor or Actor task if it's still running from the previous
schedule.
name: The name of the schedule to create.
actions: Actors or tasks that should be run on this schedule. See the API documentation for exact structure.
description: Description of this schedule.
timezone: Timezone in which your cron expression runs (TZ database name from
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
title: Title of this schedule.
Returns:
The created schedule.
"""
if not actions:
actions = []
schedule_representation = _get_schedule_representation(
cron_expression=cron_expression,
is_enabled=is_enabled,
is_exclusive=is_exclusive,
name=name,
actions=actions,
description=description,
timezone=timezone,
title=title,
)
return self._create(filter_out_none_values_recursively(schedule_representation))
class ScheduleCollectionClientAsync(ResourceCollectionClientAsync):
"""Async sub-client for manipulating schedules."""
def __init__(self, *args: Any, **kwargs: Any) -> None:
resource_path = kwargs.pop('resource_path', 'schedules')
super().__init__(*args, resource_path=resource_path, **kwargs)
async def list(
self,
*,
limit: int | None = None,
offset: int | None = None,
desc: bool | None = None,
) -> ListPage[dict]:
"""List the available schedules.
https://docs.apify.com/api/v2#/reference/schedules/schedules-collection/get-list-of-schedules
Args:
limit: How many schedules to retrieve.
offset: What schedules to include as first when retrieving the list.
desc: Whether to sort the schedules in descending order based on their modification date.
Returns:
The list of available schedules matching the specified filters.
"""
return await self._list(limit=limit, offset=offset, desc=desc)
async def create(
self,
*,
cron_expression: str,
is_enabled: bool,
is_exclusive: bool,
name: str | None = None,
actions: list[dict] | None = None, # ty: ignore[invalid-type-form]
description: str | None = None,
timezone: str | None = None,
title: str | None = None,
) -> dict:
"""Create a new schedule.
https://docs.apify.com/api/v2#/reference/schedules/schedules-collection/create-schedule
Args:
cron_expression: The cron expression used by this schedule.
is_enabled: True if the schedule should be enabled.
is_exclusive: When set to true, don't start Actor or Actor task if it's still running from the previous
schedule.
name: The name of the schedule to create.
actions: Actors or tasks that should be run on this schedule. See the API documentation for exact structure.
description: Description of this schedule.
timezone: Timezone in which your cron expression runs (TZ database name from
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
title: Title of this schedule.
Returns:
The created schedule.
"""
if not actions:
actions = []
schedule_representation = _get_schedule_representation(
cron_expression=cron_expression,
is_enabled=is_enabled,
is_exclusive=is_exclusive,
name=name,
actions=actions,
description=description,
timezone=timezone,
title=title,
)
return await self._create(filter_out_none_values_recursively(schedule_representation))