Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/firebase_functions/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ def _endpoint(
schedule=self.schedule,
timeZone=time_zone,
retryConfig=retry_config,
attemptDeadlineSeconds=self.timeout_sec,
),
}
return _manifest.ManifestEndpoint(**_typing.cast(dict, kwargs_merged))
Expand Down
1 change: 1 addition & 0 deletions src/firebase_functions/private/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class ScheduleTrigger(_typing.TypedDict):
schedule: str | _params.Expression[str]
timeZone: str | _params.Expression[str] | _util.Sentinel | None
retryConfig: RetryConfigScheduler | None
attemptDeadlineSeconds: int | _params.Expression[int] | _util.Sentinel | None


class BlockingTriggerOptions(_typing.TypedDict):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_scheduler_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ def test_on_schedule_decorator(self):
self.assertEqual(endpoint.scheduleTrigger.get("schedule"), schedule)
self.assertEqual(endpoint.scheduleTrigger.get("timeZone"), tz)

def test_on_schedule_with_timeout(self):
"""
Tests that attemptDeadlineSeconds is set to timeoutSeconds.
"""
decorated_func = scheduler_fn.on_schedule(
schedule="* * * * *",
timeout_sec=120,
)(Mock(__name__="example_func"))
endpoint = decorated_func.__firebase_endpoint__
self.assertEqual(endpoint.timeoutSeconds, 120)
self.assertEqual(endpoint.scheduleTrigger.get("attemptDeadlineSeconds"), 120)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure the unification of timeouts works correctly for the default case (when timeout_sec is not specified), it would be beneficial to add a test case that covers this scenario. This will help verify that attemptDeadlineSeconds is set to the function's default timeout (60s) instead of Cloud Scheduler's default.

    def test_on_schedule_with_default_timeout(self):
        """
        Tests that attemptDeadlineSeconds is set to the default timeoutSeconds.
        """
        decorated_func = scheduler_fn.on_schedule(
            schedule="* * * * *",
        )(Mock(__name__="example_func"))
        endpoint = decorated_func.__firebase_endpoint__
        # The function timeout will be the platform default, but the attempt deadline
        # should be explicitly set to the function's default timeout (60s).
        self.assertEqual(endpoint.timeoutSeconds, scheduler_fn._options.RESET_VALUE)
        self.assertEqual(endpoint.scheduleTrigger.get("attemptDeadlineSeconds"), 60)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disagree. scheduler having a default timeout of 3m. functions have default timeout of 1m. when scheudler timeout > function timeout, we don't expect things to go wrong.

def test_on_schedule_call(self):
"""
Tests to ensure the decorated function is called correctly
Expand Down
Loading