[UPDT] ATTENDANCE: Updated the scheduler interval and added delay to the work record change

This commit is contained in:
Horilla
2025-02-28 18:53:01 +05:30
parent f228f91dc5
commit 3aea5dea49
2 changed files with 42 additions and 1 deletions

41
attendance/scheduler.py Normal file
View File

@@ -0,0 +1,41 @@
import datetime
import sys
from apscheduler.schedulers.background import BackgroundScheduler
today = datetime.datetime.today()
def create_work_record(date=today):
from attendance.models import WorkRecords
from employee.models import Employee
work_records = WorkRecords.objects.all()
employees = Employee.objects.all()
if len(work_records.filter(date=date)) == len(employees):
return
else:
for employee in employees:
try:
shift = employee.employee_work_info.shift_id
WorkRecords.objects.get_or_create(
employee_id=employee,
date=date,
defaults={"work_record_type": "DFT", "shift_id": shift, "message": ""},
)
except:
pass
if not any(
cmd in sys.argv
for cmd in ["makemigrations", "migrate", "compilemessages", "flush", "shell"]
):
"""
Initializes and starts background tasks using APScheduler when the server is running.
"""
scheduler = BackgroundScheduler()
scheduler.add_job(create_work_record, "interval", hours=3)
scheduler.start()

View File

@@ -62,7 +62,7 @@
name="month"
hx-get="{% url 'work-records-change-month' %}"
hx-target="#workRecordTable"
hx-trigger="input">
hx-trigger="keyup changed delay:0.5s">
</div>
</h6>
</div>