first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
تسکهای Celery برای واکشی دادههای هواشناسی.
|
||||
"""
|
||||
|
||||
from config.celery import app
|
||||
|
||||
from location_data.models import SoilLocation
|
||||
|
||||
from .services import update_weather_for_location, update_weather_for_all_locations
|
||||
|
||||
|
||||
@app.task(bind=True)
|
||||
def fetch_weather_task(self, location_id: int):
|
||||
"""
|
||||
واکشی پیشبینی هواشناسی ۷ روزه برای یک location مشخص.
|
||||
"""
|
||||
try:
|
||||
location = SoilLocation.objects.get(pk=location_id)
|
||||
except SoilLocation.DoesNotExist:
|
||||
return {
|
||||
"status": "error",
|
||||
"error": f"SoilLocation with id={location_id} not found.",
|
||||
}
|
||||
|
||||
return update_weather_for_location(location)
|
||||
|
||||
|
||||
@app.task(bind=True)
|
||||
def fetch_weather_all_locations_task(self):
|
||||
"""
|
||||
واکشی پیشبینی هواشناسی برای تمام locationها.
|
||||
مناسب برای Celery Beat (مثلاً هر ۶ ساعت).
|
||||
"""
|
||||
return update_weather_for_all_locations()
|
||||
Reference in New Issue
Block a user