|
20 | 20 | import dataclasses as _dataclasses
|
21 | 21 | import re as _re
|
22 | 22 | import typing as _typing
|
| 23 | +from zoneinfo import ZoneInfo as _ZoneInfo |
23 | 24 |
|
24 | 25 | import firebase_functions.private.manifest as _manifest
|
25 | 26 | import firebase_functions.private.util as _util
|
26 | 27 | import firebase_functions.private.path_pattern as _path_pattern
|
27 | 28 | from firebase_functions.params import SecretParam, Expression
|
28 | 29 |
|
| 30 | +Timezone = _ZoneInfo |
| 31 | +"""An alias of the zoneinfo.ZoneInfo for convenience.""" |
| 32 | + |
29 | 33 | RESET_VALUE = _util.Sentinel(
|
30 | 34 | "Special configuration value to reset configuration to platform default.")
|
31 | 35 | """Special configuration value to reset configuration to platform default."""
|
@@ -409,7 +413,7 @@ def _endpoint(
|
409 | 413 | maxDispatchesPerSecond=self.rate_limits.max_dispatches_per_second,
|
410 | 414 | ) if self.rate_limits is not None else None
|
411 | 415 |
|
412 |
| - retry_config: _manifest.RetryConfig | None = _manifest.RetryConfig( |
| 416 | + retry_config: _manifest.RetryConfigTasks | None = _manifest.RetryConfigTasks( |
413 | 417 | maxAttempts=self.retry_config.max_attempts,
|
414 | 418 | maxRetrySeconds=self.retry_config.max_retry_seconds,
|
415 | 419 | maxBackoffSeconds=self.retry_config.max_backoff_seconds,
|
@@ -498,6 +502,86 @@ def _endpoint(
|
498 | 502 | **kwargs, event_filters=event_filters, event_type=event_type))))
|
499 | 503 |
|
500 | 504 |
|
| 505 | +@_dataclasses.dataclass(frozen=True, kw_only=True) |
| 506 | +class ScheduleOptions(RuntimeOptions): |
| 507 | + """ |
| 508 | + Options that can be set on a Schedule trigger. |
| 509 | + """ |
| 510 | + |
| 511 | + schedule: str |
| 512 | + """ |
| 513 | + The schedule, in Unix Crontab or AppEngine syntax. |
| 514 | + """ |
| 515 | + |
| 516 | + timezone: Timezone | Expression[str] | _util.Sentinel | None = None |
| 517 | + """ |
| 518 | + The timezone that the schedule executes in. |
| 519 | + """ |
| 520 | + |
| 521 | + retry_count: int | Expression[int] | _util.Sentinel | None = None |
| 522 | + """ |
| 523 | + The number of retry attempts for a failed run. |
| 524 | + """ |
| 525 | + |
| 526 | + max_retry_seconds: int | Expression[int] | _util.Sentinel | None = None |
| 527 | + """ |
| 528 | + The time limit for retrying. |
| 529 | + """ |
| 530 | + |
| 531 | + max_backoff_seconds: int | Expression[int] | _util.Sentinel | None = None |
| 532 | + """ |
| 533 | + The maximum amount of time to wait between attempts. |
| 534 | + """ |
| 535 | + |
| 536 | + max_doublings: int | Expression[int] | _util.Sentinel | None = None |
| 537 | + """ |
| 538 | + The maximum number of times to double the backoff between |
| 539 | + retries. |
| 540 | + """ |
| 541 | + |
| 542 | + min_backoff_seconds: int | Expression[int] | _util.Sentinel | None = None |
| 543 | + """ |
| 544 | + The minimum time to wait between attempts. |
| 545 | + """ |
| 546 | + |
| 547 | + def _endpoint( |
| 548 | + self, |
| 549 | + **kwargs, |
| 550 | + ) -> _manifest.ManifestEndpoint: |
| 551 | + retry_config: _manifest.RetryConfigScheduler = _manifest.RetryConfigScheduler( |
| 552 | + retryCount=self.retry_count, |
| 553 | + maxRetrySeconds=self.max_retry_seconds, |
| 554 | + maxBackoffSeconds=self.max_backoff_seconds, |
| 555 | + maxDoublings=self.max_doublings, |
| 556 | + minBackoffSeconds=self.min_backoff_seconds, |
| 557 | + ) |
| 558 | + time_zone: str | Expression[str] | _util.Sentinel | None = None |
| 559 | + if isinstance(self.timezone, Timezone): |
| 560 | + time_zone = self.timezone.key |
| 561 | + else: |
| 562 | + time_zone = self.timezone |
| 563 | + |
| 564 | + kwargs_merged = { |
| 565 | + **_dataclasses.asdict(super()._endpoint(**kwargs)), |
| 566 | + "scheduleTrigger": |
| 567 | + _manifest.ScheduleTrigger( |
| 568 | + schedule=self.schedule, |
| 569 | + timeZone=time_zone, |
| 570 | + retryConfig=retry_config, |
| 571 | + ), |
| 572 | + } |
| 573 | + return _manifest.ManifestEndpoint( |
| 574 | + **_typing.cast(_typing.Dict, kwargs_merged)) |
| 575 | + |
| 576 | + def _required_apis(self) -> list[_manifest.ManifestRequiredApi]: |
| 577 | + return [ |
| 578 | + _manifest.ManifestRequiredApi( |
| 579 | + api="cloudscheduler.googleapis.com", |
| 580 | + reason="Needed for scheduled functions.", |
| 581 | + ) |
| 582 | + ] |
| 583 | + |
| 584 | + |
501 | 585 | @_dataclasses.dataclass(frozen=True, kw_only=True)
|
502 | 586 | class StorageOptions(RuntimeOptions):
|
503 | 587 | """
|
|
0 commit comments