[UPDT] BASE: Updated scheduler add_job function call by adding it in a condition to start

This commit is contained in:
Horilla
2025-01-07 15:13:47 +05:30
parent d6ab7f5d74
commit d827f6c807
7 changed files with 83 additions and 68 deletions

View File

@@ -4,6 +4,7 @@ scheduler.py
This module is used to register scheduled tasks This module is used to register scheduled tasks
""" """
import sys
from datetime import date, timedelta from datetime import date, timedelta
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
@@ -83,7 +84,11 @@ def notify_expiring_documents():
document.is_active = False document.is_active = False
scheduler = BackgroundScheduler() if not any(
scheduler.add_job(notify_expiring_assets, "interval", hours=4) cmd in sys.argv
scheduler.add_job(notify_expiring_documents, "interval", hours=4) for cmd in ["makemigrations", "migrate", "compilemessages", "flush", "shell"]
scheduler.start() ):
scheduler = BackgroundScheduler()
scheduler.add_job(notify_expiring_assets, "interval", hours=4)
scheduler.add_job(notify_expiring_documents, "interval", hours=4)
scheduler.start()

View File

@@ -1,5 +1,6 @@
import calendar import calendar
import datetime as dt import datetime as dt
import sys
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
@@ -429,66 +430,67 @@ def recurring_holiday():
recurring_holiday.save() recurring_holiday.save()
scheduler = BackgroundScheduler() if not any(
cmd in sys.argv
for cmd in ["makemigrations", "migrate", "compilemessages", "flush", "shell"]
):
scheduler = BackgroundScheduler()
# Set the initial start time to the current time # Add jobs with next_run_time set to the end of the previous job
start_time = datetime.now() try:
scheduler.add_job(rotate_shift, "interval", minutes=5, id="job1")
except:
pass
# Add jobs with next_run_time set to the end of the previous job try:
try: scheduler.add_job(
scheduler.add_job(rotate_shift, "interval", minutes=5, id="job1") rotate_work_type,
except: "interval",
pass minutes=5,
id="job2",
)
except:
pass
try: try:
scheduler.add_job( scheduler.add_job(
rotate_work_type, undo_shift,
"interval", "interval",
minutes=5, minutes=5,
id="job2", id="job3",
) )
except: except:
pass pass
try: try:
scheduler.add_job( scheduler.add_job(
undo_shift, switch_shift,
"interval", "interval",
minutes=5, minutes=5,
id="job3", id="job4",
) )
except: except:
pass pass
try: try:
scheduler.add_job( scheduler.add_job(
switch_shift, undo_work_type,
"interval", "interval",
minutes=5, minutes=5,
id="job4", id="job6",
) )
except: except:
pass pass
try: try:
scheduler.add_job( scheduler.add_job(
undo_work_type, switch_work_type,
"interval", "interval",
minutes=5, minutes=5,
id="job6", id="job5",
) )
except: except:
pass pass
try: scheduler.add_job(recurring_holiday, "interval", hours=4)
scheduler.add_job( scheduler.start()
switch_work_type,
"interval",
minutes=5,
id="job5",
)
except:
pass
scheduler.add_job(recurring_holiday, "interval", hours=4)
scheduler.start()

View File

@@ -133,7 +133,8 @@ def block_unblock_disciplinary():
if not any( if not any(
cmd in sys.argv for cmd in ["makemigrations", "migrate", "compilemessages", "flush"] cmd in sys.argv
for cmd in ["makemigrations", "migrate", "compilemessages", "flush", "shell"]
): ):
""" """
Initializes and starts background tasks using APScheduler when the server is running. Initializes and starts background tasks using APScheduler when the server is running.

View File

@@ -48,7 +48,8 @@ def leave_reset():
if not any( if not any(
cmd in sys.argv for cmd in ["makemigrations", "migrate", "compilemessages", "flush"] cmd in sys.argv
for cmd in ["makemigrations", "migrate", "compilemessages", "flush", "shell"]
): ):
""" """
Initializes and starts background tasks using APScheduler when the server is running. Initializes and starts background tasks using APScheduler when the server is running.

View File

@@ -171,7 +171,7 @@
</div> </div>
<div class="col-sm-12 col-md-12"> <div class="col-sm-12 col-md-12">
<div class="oh-input-group oh-label__info"> <div class="oh-input-group oh-label__info">
<label for="id_carryforward_expire_date" class="oh-label">{% trans "Carryforward Expire In" %}</label> <label for="id_carryforward_expire_date" class="oh-label">{% trans "Carryforward Expire Date" %}</label>
<span class=" oh-info me-3" title="{% trans 'The date on which carryforward leave resets to 0. After this reset, the date will be updated to the next expiration period.' %}"></span> <span class=" oh-info me-3" title="{% trans 'The date on which carryforward leave resets to 0. After this reset, the date will be updated to the next expiration period.' %}"></span>
</div> </div>
{{form.carryforward_expire_date}} {{form.carryforward_expire_date}}

View File

@@ -5,6 +5,7 @@ This module is used to register scheduled tasks
""" """
import json import json
import sys
from datetime import date, timedelta from datetime import date, timedelta
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
@@ -137,7 +138,11 @@ def auto_payslip_generate():
generate_payslip(date=date.today(), companies=companies, all=False) generate_payslip(date=date.today(), companies=companies, all=False)
scheduler = BackgroundScheduler() if not any(
scheduler.add_job(expire_contract, "interval", hours=4) cmd in sys.argv
scheduler.add_job(auto_payslip_generate, "interval", hours=3) for cmd in ["makemigrations", "migrate", "compilemessages", "flush", "shell"]
scheduler.start() ):
scheduler = BackgroundScheduler()
scheduler.add_job(expire_contract, "interval", hours=4)
scheduler.add_job(auto_payslip_generate, "interval", hours=3)
scheduler.start()

View File

@@ -48,7 +48,8 @@ def candidate_convert():
if not any( if not any(
cmd in sys.argv for cmd in ["makemigrations", "migrate", "compilemessages", "flush"] cmd in sys.argv
for cmd in ["makemigrations", "migrate", "compilemessages", "flush", "shell"]
): ):
""" """
Initializes and starts background tasks using APScheduler when the server is running. Initializes and starts background tasks using APScheduler when the server is running.