Skip to content

Commit

Permalink
[UPDT] BASE: Scheduler start function call updated by adding sys.argv…
Browse files Browse the repository at this point in the history
… condition
  • Loading branch information
horilla-opensource committed Jan 3, 2025
1 parent 53728e1 commit 9542567
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 151 deletions.
15 changes: 11 additions & 4 deletions employee/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import sys
from datetime import timedelta

from apscheduler.schedulers.background import BackgroundScheduler
Expand Down Expand Up @@ -131,7 +132,13 @@ def block_unblock_disciplinary():
return


scheduler = BackgroundScheduler()
scheduler.add_job(update_experience, "interval", hours=4)
scheduler.add_job(block_unblock_disciplinary, "interval", seconds=25)
scheduler.start()
if not any(
cmd in sys.argv for cmd in ["makemigrations", "migrate", "compilemessages", "flush"]
):
"""
Initializes and starts background tasks using APScheduler when the server is running.
"""
scheduler = BackgroundScheduler()
scheduler.add_job(update_experience, "interval", hours=4)
scheduler.add_job(block_unblock_disciplinary, "interval", seconds=25)
scheduler.start()
13 changes: 10 additions & 3 deletions leave/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import calendar
import datetime as dt
import sys
from datetime import datetime, timedelta

from apscheduler.schedulers.background import BackgroundScheduler
Expand Down Expand Up @@ -46,7 +47,13 @@ def leave_reset():
leave_type.save()


scheduler = BackgroundScheduler()
scheduler.add_job(leave_reset, "interval", seconds=20)
if not any(
cmd in sys.argv for cmd in ["makemigrations", "migrate", "compilemessages", "flush"]
):
"""
Initializes and starts background tasks using APScheduler when the server is running.
"""
scheduler = BackgroundScheduler()
scheduler.add_job(leave_reset, "interval", seconds=20)

scheduler.start()
scheduler.start()
139 changes: 0 additions & 139 deletions leave/templates/leave/leave_type_view.html

This file was deleted.

22 changes: 17 additions & 5 deletions recruitment/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import calendar
import datetime as dt
import sys
from datetime import datetime, timedelta

from apscheduler.schedulers.background import BackgroundScheduler
Expand All @@ -9,7 +10,10 @@


def recruitment_close():
"""
Closes recruitment campaigns that have reached their end date.
"""
from recruitment.models import Recruitment

today_date = today.date()
Expand All @@ -25,7 +29,9 @@ def recruitment_close():


def candidate_convert():

"""
Converts candidates to a "converted" state if they already exist as users.
"""
from django.contrib.auth.models import User

from recruitment.models import Candidate
Expand All @@ -41,8 +47,14 @@ def candidate_convert():
cand.save()


scheduler = BackgroundScheduler()
scheduler.add_job(candidate_convert, "interval", seconds=10)
scheduler.add_job(recruitment_close, "interval", hours=1)
if not any(
cmd in sys.argv for cmd in ["makemigrations", "migrate", "compilemessages", "flush"]
):
"""
Initializes and starts background tasks using APScheduler when the server is running.
"""
scheduler = BackgroundScheduler()
scheduler.add_job(candidate_convert, "interval", seconds=10)
scheduler.add_job(recruitment_close, "interval", hours=1)

scheduler.start()
scheduler.start()

0 comments on commit 9542567

Please sign in to comment.