mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 02:16:16 +00:00
jira-290 cron job for expired task
This commit is contained in:
@ -22,7 +22,7 @@ from django.conf import settings
|
||||
"""App Import"""
|
||||
from guardian.models import Guardian
|
||||
from junior.models import Junior
|
||||
from guardian.utils import upload_image_to_alibaba, OTP_EXPIRY
|
||||
from guardian.utils import upload_image_to_alibaba
|
||||
from account.models import UserDeviceDetails, UserPhoneOtp, UserEmailOtp, DefaultTaskImages, UserNotification
|
||||
from django.contrib.auth.models import User
|
||||
"""Account serializer"""
|
||||
@ -36,7 +36,7 @@ from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from base.constants import NUMBER, ZOD, JUN, GRD
|
||||
from guardian.tasks import generate_otp
|
||||
from account.utils import (send_otp_email, send_support_email, custom_response, custom_error_response,
|
||||
generate_code)
|
||||
generate_code, OTP_EXPIRY)
|
||||
from junior.serializers import JuniorProfileSerializer
|
||||
from guardian.serializers import GuardianProfileSerializer
|
||||
|
||||
|
Binary file not shown.
@ -5,6 +5,7 @@ import oss2
|
||||
from django.conf import settings
|
||||
import logging
|
||||
import requests
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
"""Import tempfile"""
|
||||
import tempfile
|
||||
# Import date time module's function
|
||||
@ -13,7 +14,10 @@ from datetime import datetime, time
|
||||
from base.constants import NUMBER, time_url
|
||||
# Import Junior's model
|
||||
from junior.models import Junior, JuniorPoints
|
||||
|
||||
# Import guardian's model
|
||||
from .models import JuniorTask
|
||||
# Import app from celery
|
||||
from zod_bank.celery import app
|
||||
# Define upload image on
|
||||
# ali baba cloud
|
||||
# firstly save image
|
||||
@ -81,3 +85,16 @@ def update_referral_points(referral_code, referral_code_used):
|
||||
junior_query.total_points = junior_query.total_points + NUMBER['five']
|
||||
junior_query.referral_points = junior_query.referral_points + NUMBER['five']
|
||||
junior_query.save()
|
||||
|
||||
|
||||
@app.task
|
||||
def update_expired_task_status(data=None):
|
||||
"""
|
||||
Update task of the status if due date is in past
|
||||
"""
|
||||
try:
|
||||
task_status = [str(NUMBER['one']), str(NUMBER['two'])]
|
||||
JuniorTask.objects.filter(due_date__lt=datetime.today().date(),
|
||||
task_status__in=task_status).update(task_status=str(NUMBER['six']))
|
||||
except ObjectDoesNotExist as e:
|
||||
logging.error(str(e))
|
||||
|
@ -5,6 +5,7 @@ from rest_framework import viewsets, status, generics,views
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from django.contrib.auth.models import User
|
||||
import datetime
|
||||
import requests
|
||||
"""Django app import"""
|
||||
|
||||
|
@ -32,3 +32,14 @@ app.autodiscover_tasks()
|
||||
def debug_task(self):
|
||||
""" celery debug task """
|
||||
print(f'Request: {self.request!r}')
|
||||
|
||||
|
||||
"""cron task"""
|
||||
|
||||
|
||||
app.conf.beat_schedule = {
|
||||
"expired_task": {
|
||||
"task": "guardian.utils.update_expired_task_status",
|
||||
"schedule": crontab(minute=0, hour=0),
|
||||
},
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.postgres',
|
||||
'rest_framework',
|
||||
'fcm_django',
|
||||
'django_celery_beat',
|
||||
# Add your custom apps here.
|
||||
'django_ses',
|
||||
'account',
|
||||
|
Reference in New Issue
Block a user