| Server IP : 65.108.144.40 / Your IP : 216.73.217.165 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 User : dev ( 1000) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/erp/recruitment/ |
Upload File : |
import calendar
import datetime as dt
import sys
from datetime import datetime, timedelta
from apscheduler.schedulers.background import BackgroundScheduler
from dateutil.relativedelta import relativedelta
today = datetime.now()
def recruitment_close():
"""
Closes recruitment campaigns that have reached their end date.
"""
from recruitment.models import Recruitment
today_date = today.date()
recruitments = Recruitment.objects.filter(closed=False)
for rec in recruitments:
if rec.end_date:
if rec.end_date == today_date:
rec.closed = True
rec.is_published = False
rec.save()
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
candidates = Candidate.objects.filter(is_active=True)
mails = list(Candidate.objects.values_list("email", flat=True))
existing_emails = list(
User.objects.filter(username__in=mails).values_list("email", flat=True)
)
for cand in candidates:
if cand.email in existing_emails:
cand.converted = True
cand.save()
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(candidate_convert, "interval", seconds=10)
scheduler.add_job(recruitment_close, "interval", hours=1)
scheduler.start()