task working?
This commit is contained in:
parent
442118fdc7
commit
98b1705d81
10 changed files with 35 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
|||
services:
|
||||
backend:
|
||||
image: facturio
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
|
|
|
@ -41,6 +41,10 @@ services:
|
|||
<<: *x-django
|
||||
command: ["/app/scripts/run-dramatiq.sh"]
|
||||
|
||||
scheduler:
|
||||
<<: *x-django
|
||||
command: [ "/app/scripts/run-scheduler.sh" ]
|
||||
|
||||
gotenberg:
|
||||
image: gotenberg/gotenberg:8
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ MY_APPS = [
|
|||
'accounts.apps.AccountConfig',
|
||||
'subjects.apps.SubjectsConfig',
|
||||
'invoices.apps.InvoicesConfig',
|
||||
'utils.apps.UtilsConfig',
|
||||
]
|
||||
|
||||
THIRD_PARTY_APPS = [
|
||||
|
|
10
scripts/run-scheduler.sh
Executable file
10
scripts/run-scheduler.sh
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o nounset
|
||||
set -o xtrace
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
|
||||
echo "Running scheduler..."
|
||||
./manage.py runscheduler
|
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
5
utils/apps.py
Normal file
5
utils/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UtilsConfig(AppConfig):
|
||||
name = 'utils'
|
0
utils/management/__init__.py
Normal file
0
utils/management/__init__.py
Normal file
0
utils/management/commands/__init__.py
Normal file
0
utils/management/commands/__init__.py
Normal file
|
@ -4,11 +4,12 @@ from copy import deepcopy
|
|||
|
||||
from apscheduler.schedulers.blocking import BlockingScheduler
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
from apscheduler.triggers.interval import IntervalTrigger
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django_apscheduler import util
|
||||
from django_apscheduler.jobstores import DjangoJobStore
|
||||
from django_apscheduler.models import DjangoJobExecution
|
||||
from django_apscheduler.models import DjangoJobStore
|
||||
from django_dramatiq.models import Task
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -18,17 +19,12 @@ DEFAULT_JOB_KWARGS = {
|
|||
"replace_existing": True,
|
||||
}
|
||||
|
||||
# For cron definitions use https://crontab.guru/
|
||||
|
||||
daily_cron = CronTrigger.from_crontab("0 0 * * *")
|
||||
weekly_cron = CronTrigger.from_crontab("0 0 * * 0")
|
||||
monthly_cron = CronTrigger.from_crontab("30 3 1 * *")
|
||||
daily_export_cron = CronTrigger.from_crontab("0 5 * * *")
|
||||
DAY_SEC = 24*60*60
|
||||
|
||||
PERIODIC_JOBS = [
|
||||
{
|
||||
"task": "not_working.yet",
|
||||
"trigger": daily_cron,
|
||||
"task": "utils.tasks:send_queued_mail_task.send",
|
||||
"trigger": IntervalTrigger(seconds=30),
|
||||
},
|
||||
|
||||
]
|
||||
|
@ -38,7 +34,7 @@ PERIODIC_JOBS = [
|
|||
# unusable or are obsolete are closed before and after your job has run.
|
||||
# You should use it to wrap any jobs that you schedule that access the Django database in any way.
|
||||
@util.close_old_connections
|
||||
def delete_old_job_executions(max_age: int = 604_800) -> None:
|
||||
def delete_old_job_executions(max_age: int = 7 * DAY_SEC) -> None:
|
||||
"""
|
||||
This job deletes APScheduler job execution entries older than `max_age` from the database.
|
||||
It helps to prevent the database from filling up with old historical records that are no
|
||||
|
@ -53,7 +49,7 @@ def delete_old_job_executions(max_age: int = 604_800) -> None:
|
|||
|
||||
class Command(BaseCommand):
|
||||
help = "Runs APScheduler." # noqa: A003
|
||||
scheduler = None
|
||||
scheduler: BlockingScheduler = None
|
||||
|
||||
def prepare_scheduler(self):
|
||||
self.stdout.write(self.style.NOTICE("Preparing scheduler"))
|
||||
|
@ -92,7 +88,6 @@ class Command(BaseCommand):
|
|||
self.prepare_scheduler()
|
||||
self.add_jobs()
|
||||
|
||||
# signal.signal(signal.SIGINT, self.handle_shutdown)
|
||||
signal.signal(signal.SIGTERM, self.handle_shutdown)
|
||||
|
||||
try:
|
7
utils/tasks.py
Normal file
7
utils/tasks.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
import dramatiq
|
||||
from django.core.management import call_command
|
||||
|
||||
|
||||
@dramatiq.actor()
|
||||
def send_queued_mail_task():
|
||||
call_command('send_queued_mail')
|
Reference in a new issue