mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-07-15 09:12:39 +02:00
feat: internal code for automatic exchange rate fetching
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import logging
|
||||
|
||||
from procrastinate.contrib.django import app
|
||||
from apps.currencies.exchange_rates.fetcher import ExchangeRateFetcher
|
||||
from apps.currencies.models import ExchangeRateService
|
||||
from django.utils import timezone
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@app.periodic(cron="0 * * * *") # Run every hour
|
||||
@app.task(name="automatic_fetch_exchange_rates")
|
||||
def automatic_fetch_exchange_rates(timestamp=None):
|
||||
"""Fetch exchange rates for all due services"""
|
||||
fetcher = ExchangeRateFetcher()
|
||||
|
||||
try:
|
||||
fetcher.fetch_due_rates()
|
||||
except Exception as e:
|
||||
logger.error(e, exc_info=True)
|
||||
|
||||
|
||||
@app.task(name="manual_fetch_exchange_rates")
|
||||
def manual_fetch_exchange_rates(timestamp=None):
|
||||
"""Fetch exchange rates for all due services"""
|
||||
fetcher = ExchangeRateFetcher()
|
||||
|
||||
try:
|
||||
fetcher.fetch_due_rates(force=True)
|
||||
except Exception as e:
|
||||
logger.error(e, exc_info=True)
|
||||
Reference in New Issue
Block a user