mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-30 13:55:41 +00:00
Add Celery periodic task for deactivating expired devices and update requirements
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 11m3s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 11m3s
This commit is contained in:
parent
99982d13d5
commit
0f19f0c15c
@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
from celery import Celery
|
||||
from celery.schedules import crontab
|
||||
|
||||
# Set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "apibase.settings")
|
||||
@ -17,6 +18,15 @@ app.config_from_object("django.conf:settings", namespace="CELERY")
|
||||
app.autodiscover_tasks(["api", "devices"])
|
||||
|
||||
|
||||
# Add periodic task scheduler
|
||||
app.conf.beat_schedule = {
|
||||
"deactivate-expired-devices-every-day": {
|
||||
"task": "api.tasks.deactivate_expired_devices",
|
||||
"schedule": crontab(hour=0, minute=0), # Runs daily at midnight
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@app.task(bind=True, ignore_result=True)
|
||||
def debug_task(self):
|
||||
print(f"Request: {self.request!r}")
|
||||
|
@ -28,9 +28,9 @@ env.read_env(os.path.join(BASE_DIR, ".env"))
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = env("SECRET_KEY", default=get_random_secret_key())
|
||||
|
||||
DEBUG = env.bool("DJANGO_DEBUG", default=True)
|
||||
DEBUG = env.bool("DJANGO_DEBUG", default=True) # type: ignore
|
||||
|
||||
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[])
|
||||
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[]) # type: ignore
|
||||
|
||||
|
||||
if DEBUG:
|
||||
@ -68,6 +68,7 @@ INSTALLED_APPS = [
|
||||
# third party
|
||||
"django_filters",
|
||||
"corsheaders",
|
||||
"django_celery_beat",
|
||||
]
|
||||
|
||||
if DEBUG:
|
||||
@ -123,10 +124,10 @@ if not DEBUG:
|
||||
SECURE_SSL_REDIRECT = env("DJANGO_SECURE_SSL_REDIRECT", cast=bool)
|
||||
SESSION_COOKIE_SECURE = True
|
||||
CSRF_COOKIE_SECURE = True
|
||||
SECURE_HSTS_SECONDS = env("SECURE_HSTS_SECONDS", default=3600, cast=int)
|
||||
SECURE_HSTS_SECONDS = env("SECURE_HSTS_SECONDS", default=3600, cast=int) # type: ignore
|
||||
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
|
||||
SECURE_HSTS_PRELOAD = True
|
||||
CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS", default=[])
|
||||
CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS", default=[]) # type: ignore
|
||||
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||
SECURE_BROWSER_XSS_FILTER = True
|
||||
X_FRAME_OPTIONS = "DENY"
|
||||
@ -162,7 +163,7 @@ CACHES = {
|
||||
else "django.core.cache.backends.locmem.LocMemCache"
|
||||
),
|
||||
"LOCATION": (
|
||||
env("REDIS_URL", default="redis://redis:6379/") if not DEBUG else ""
|
||||
env("REDIS_URL", default="redis://redis:6379/") if not DEBUG else "" # type: ignore
|
||||
),
|
||||
"OPTIONS": (
|
||||
{
|
||||
@ -347,10 +348,10 @@ logging.config.dictConfig(
|
||||
EMAIL_BACKEND = (
|
||||
"django.core.mail.backends.smtp.EmailBackend" # Replace with your preferred backend
|
||||
)
|
||||
EMAIL_HOST = env("EMAIL_HOSTNAME", default="")
|
||||
EMAIL_PORT = env("EMAIL_PORT", cast=int, default=25)
|
||||
EMAIL_HOST_USER = env("EMAIL_USERNAME", default="")
|
||||
EMAIL_HOST_PASSWORD = env("EMAIL_PASSWORD", default="")
|
||||
EMAIL_HOST = env("EMAIL_HOSTNAME", default="") # type: ignore
|
||||
EMAIL_PORT = env("EMAIL_PORT", cast=int, default=25) # type: ignore
|
||||
EMAIL_HOST_USER = env("EMAIL_USERNAME", default="") # type: ignore
|
||||
EMAIL_HOST_PASSWORD = env("EMAIL_PASSWORD", default="") # type: ignore
|
||||
# DEFAULT_FROM_EMAIL = "noreply@sarlink.net"
|
||||
EMAIL_USE_TLS = True
|
||||
|
||||
|
@ -31,7 +31,6 @@ if not PAYMENT_BASE_URL:
|
||||
raise ValueError(
|
||||
"PAYMENT_BASE_URL is not set. Please set it in your environment variables."
|
||||
)
|
||||
print("PAYMENT_BASE_URL from env:", PAYMENT_BASE_URL)
|
||||
|
||||
|
||||
class InsufficientFundsError(Exception):
|
||||
|
@ -4,6 +4,8 @@
|
||||
"reportMissingImports": "error",
|
||||
"include": ["src"],
|
||||
"typeCheckingMode": "standard",
|
||||
"reportArgumentType": "warning",
|
||||
"reportUnusedVariable": "warning",
|
||||
"exclude": [
|
||||
"council-api/**/migrations",
|
||||
"**/__pycache__",
|
||||
|
@ -23,10 +23,12 @@ click-didyoumean==0.3.1
|
||||
click-plugins==1.1.1
|
||||
click-repl==0.3.0
|
||||
colorama==0.4.6
|
||||
cron-descriptor==1.4.5
|
||||
cryptography==41.0.7
|
||||
cssselect2==0.7.0
|
||||
dj-database-url==2.1.0
|
||||
django==5.2
|
||||
django-celery-beat==2.8.0
|
||||
django-cors-headers==4.3.1
|
||||
django-debug-toolbar==4.2.0
|
||||
django-easy-audit==1.3.7
|
||||
@ -40,6 +42,7 @@ django-seed==0.3.1
|
||||
django-storages==1.14.4
|
||||
django-stubs==5.1.1
|
||||
django-stubs-ext==5.1.1
|
||||
django-timezone-field==7.1
|
||||
djangorestframework==3.14.0
|
||||
djangorestframework-simplejwt==5.3.1
|
||||
djangorestframework-stubs==3.15.1
|
||||
@ -82,6 +85,7 @@ pyotp==2.9.0
|
||||
pypdf==4.0.2
|
||||
pypng==0.20220715.0
|
||||
python-bidi==0.4.2
|
||||
python-crontab==3.2.0
|
||||
python-dateutil==2.9.0.post0
|
||||
python-decouple==3.8
|
||||
python-telegram-bot==22.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user