|
| 1 | +from collections.abc import Iterable |
1 | 2 | import copy |
2 | 3 | import logging |
3 | 4 | import warnings |
4 | 5 | from collections import namedtuple |
5 | | -from typing import TYPE_CHECKING, Callable, Optional, Union |
| 6 | +from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union, overload |
6 | 7 |
|
7 | 8 | from .endpoint import Endpoint, api, parameter_added_in |
8 | 9 | from .exceptions import MissingRequiredFieldError |
9 | 10 | from tableauserverclient.server import RequestFactory |
10 | 11 | from tableauserverclient.models import PaginationItem, ScheduleItem, TaskItem, ExtractItem |
| 12 | +from tableauserverclient.models.schedule_item import parse_batch_schedule_state |
11 | 13 |
|
12 | 14 | from tableauserverclient.helpers.logging import logger |
13 | 15 |
|
@@ -279,3 +281,48 @@ def get_extract_refresh_tasks( |
279 | 281 | extract_items = ExtractItem.from_response(server_response.content, self.parent_srv.namespace) |
280 | 282 |
|
281 | 283 | return extract_items, pagination_item |
| 284 | + |
| 285 | + @overload |
| 286 | + def batch_update_state( |
| 287 | + self, |
| 288 | + schedules: Iterable[ScheduleItem | str], |
| 289 | + state: Literal["active", "suspended"], |
| 290 | + update_all: Literal[False] = False, |
| 291 | + ) -> list[str]: ... |
| 292 | + |
| 293 | + @overload |
| 294 | + def batch_update_state( |
| 295 | + self, schedules: Any, state: Literal["active", "suspended"], update_all: Literal[True] |
| 296 | + ) -> list[str]: ... |
| 297 | + |
| 298 | + @api(version="3.27") |
| 299 | + def batch_update_state(self, schedules, state, update_all=False) -> list[str]: |
| 300 | + """ |
| 301 | + Batch update the status of one or more scheudles. If update_all is set, |
| 302 | + all schedules on the Tableau Server are affected. |
| 303 | +
|
| 304 | + Parameters |
| 305 | + ---------- |
| 306 | + schedules: Iterable[ScheudleItem | str] | Any |
| 307 | + The schedules to be updated. If update_all=True, this is ignored. |
| 308 | +
|
| 309 | + state: Literal["active", "suspended"] |
| 310 | + The state of the schedules, whether active or suspended. |
| 311 | +
|
| 312 | + update_all: bool |
| 313 | + Whether or not to apply the status to all schedules. |
| 314 | +
|
| 315 | + Returns |
| 316 | + ------- |
| 317 | + List[str] |
| 318 | + The IDs of the affected schedules. |
| 319 | + """ |
| 320 | + params = {"state": state} |
| 321 | + if update_all: |
| 322 | + params["updateAll"] = "true" |
| 323 | + payload = RequestFactory.Empty.empty_req() |
| 324 | + else: |
| 325 | + payload = RequestFactory.Schedule.batch_update_state(schedules) |
| 326 | + |
| 327 | + response = self.put_request(self.baseurl, payload, parameters={"params": params}) |
| 328 | + return parse_batch_schedule_state(response, self.parent_srv.namespace) |
0 commit comments