Skip to content

Commit

Permalink
fix: actually set expiration duration
Browse files Browse the repository at this point in the history
  • Loading branch information
mederka committed Oct 4, 2024
1 parent 559c442 commit b2aa355
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
16 changes: 8 additions & 8 deletions projects/fal/src/fal/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from fal.exceptions import RequestCancelledException
from fal.logging import get_logger
from fal.toolkit.file import get_lifecycle_preference
from fal.toolkit.file.providers import fal as fal_provider_module
from fal.toolkit.file.providers.fal import GLOBAL_LIFECYCLE_PREFERENCE

REALTIME_APP_REQUIREMENTS = ["websockets", "msgpack"]

Expand Down Expand Up @@ -268,13 +268,13 @@ async def provide_hints_headers(request, call_next):
@app.middleware("http")
async def set_global_object_preference(request, call_next):
try:
preference_dict = get_lifecycle_preference(request)
if preference_dict is not None:
fal_provider_module.GLOBAL_LIFECYCLE_PREFERENCE = (
fal_provider_module.ObjectLifecyclePreference.from_dict(
preference_dict
)
)
preference_dict = get_lifecycle_preference(request) or {}
expiration_duration = preference_dict.get("expiration_duration_seconds")
if expiration_duration is None:
raise ValueError("Could not find expiration duration")
GLOBAL_LIFECYCLE_PREFERENCE.expiration_duration_seconds = int(
expiration_duration
)

except Exception:
from fastapi.logger import logger
Expand Down
16 changes: 0 additions & 16 deletions projects/fal/src/fal/toolkit/file/providers/fal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
from urllib.error import HTTPError
from urllib.parse import urlparse, urlunparse
from urllib.request import Request, urlopen
Expand Down Expand Up @@ -95,21 +94,6 @@ def _refresh_token(self) -> None:
class ObjectLifecyclePreference:
expiration_duration_seconds: int

@classmethod
def from_dict(cls, data: dict[str, Any]) -> ObjectLifecyclePreference:
expiration_duration_seconds_raw = data.get("expiration_duration_seconds")

if expiration_duration_seconds_raw is None:
raise ValueError(
"expiration_duration_seconds is required and must be provided."
)
try:
expiration_duration_seconds = int(expiration_duration_seconds_raw)
except (ValueError, TypeError):
raise ValueError("The expiration_duration_seconds must be an integer.")

return cls(expiration_duration_seconds=expiration_duration_seconds)


GLOBAL_LIFECYCLE_PREFERENCE = ObjectLifecyclePreference(
expiration_duration_seconds=86400
Expand Down

0 comments on commit b2aa355

Please sign in to comment.