Use celery tasks instead of systemd timers for periodic work; and add more tests
All checks were successful
Deploy to Server / deploy (push) Successful in 26s
All checks were successful
Deploy to Server / deploy (push) Successful in 26s
This commit is contained in:
parent
333476b30b
commit
66ea46cf23
25 changed files with 2133 additions and 104 deletions
65
twitch/signals.py
Normal file
65
twitch/signals.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
logger = logging.getLogger("ttvdrops.signals")
|
||||
|
||||
|
||||
def _dispatch(task_fn: Any, pk: int) -> None: # noqa: ANN401
|
||||
"""Dispatch a Celery task, logging rather than raising when the broker is unavailable."""
|
||||
try:
|
||||
task_fn.delay(pk)
|
||||
except Exception: # noqa: BLE001
|
||||
logger.debug(
|
||||
"Could not dispatch %s(%d) — broker may be unavailable.",
|
||||
task_fn.name,
|
||||
pk,
|
||||
)
|
||||
|
||||
|
||||
def on_game_saved(sender: Any, instance: Any, created: bool, **kwargs: Any) -> None: # noqa: ANN401, FBT001
|
||||
"""Dispatch a box-art download task when a new Game is created."""
|
||||
if created:
|
||||
from twitch.tasks import download_game_image # noqa: PLC0415
|
||||
|
||||
_dispatch(download_game_image, instance.pk)
|
||||
|
||||
|
||||
def on_drop_campaign_saved(
|
||||
sender: Any, # noqa: ANN401
|
||||
instance: Any, # noqa: ANN401
|
||||
created: bool, # noqa: FBT001
|
||||
**kwargs: Any, # noqa: ANN401
|
||||
) -> None:
|
||||
"""Dispatch an image download task when a new DropCampaign is created."""
|
||||
if created:
|
||||
from twitch.tasks import download_campaign_image # noqa: PLC0415
|
||||
|
||||
_dispatch(download_campaign_image, instance.pk)
|
||||
|
||||
|
||||
def on_drop_benefit_saved(
|
||||
sender: Any, # noqa: ANN401
|
||||
instance: Any, # noqa: ANN401
|
||||
created: bool, # noqa: FBT001
|
||||
**kwargs: Any, # noqa: ANN401
|
||||
) -> None:
|
||||
"""Dispatch an image download task when a new DropBenefit is created."""
|
||||
if created:
|
||||
from twitch.tasks import download_benefit_image # noqa: PLC0415
|
||||
|
||||
_dispatch(download_benefit_image, instance.pk)
|
||||
|
||||
|
||||
def on_reward_campaign_saved(
|
||||
sender: Any, # noqa: ANN401
|
||||
instance: Any, # noqa: ANN401
|
||||
created: bool, # noqa: FBT001
|
||||
**kwargs: Any, # noqa: ANN401
|
||||
) -> None:
|
||||
"""Dispatch an image download task when a new RewardCampaign is created."""
|
||||
if created:
|
||||
from twitch.tasks import download_reward_campaign_image # noqa: PLC0415
|
||||
|
||||
_dispatch(download_reward_campaign_image, instance.pk)
|
||||
Loading…
Add table
Add a link
Reference in a new issue