[UPDT] ATTENDANCE: Updated the scheduler interval and added delay to the work record change
This commit is contained in:
41
attendance/scheduler.py
Normal file
41
attendance/scheduler.py
Normal 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()
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
name="month"
|
name="month"
|
||||||
hx-get="{% url 'work-records-change-month' %}"
|
hx-get="{% url 'work-records-change-month' %}"
|
||||||
hx-target="#workRecordTable"
|
hx-target="#workRecordTable"
|
||||||
hx-trigger="input">
|
hx-trigger="keyup changed delay:0.5s">
|
||||||
</div>
|
</div>
|
||||||
</h6>
|
</h6>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user