We have a django app which we deployed using IIS Server. The app has been running smoothly and without any problem. However, we want to schedule a job that will run every night at 02:00.
We are using APScheduler which is working perfectly fine on the django local server but it never runs on production.
Here is the code I am using to run the jobs.
myapp/scheduler.py
def schedule():
scheduler = BackgroundScheduler()
scheduler.add_job(daily_schedules, 'interval', minutes=5)
# scheduler.add_job(daily_schedules, trigger='cron', hour='2')
scheduler.start()
def daily_schedules():
time_now = time.clock()
parse_api() # my function
# Keeping logs
path = join(settings.FILES_DIR, 'schedulled/logs.csv')
logs = pd.read_csv(path, encoding='utf-8')
time_end = time.clock() - time_now
logs.loc[len(logs)] = [
datetime.now().strftime('%Y-%m-%d %H:%M:%S'), time_end
]
logs.to_csv(path, encoding='utf-8', index=False)
print(logs)
myapp/apps.py
from django.apps import AppConfig
class MyAppConfig(AppConfig):
name = 'MyApp'
def ready(self):
from myapp import scheduler
scheduler.schedule()
Is there any particular reason why the job is not being run? Do I need to do something else or this method does not work with IIS? Since the server is being used by many developers at the same time, I would like to run the jobs as part of the django application and not run them outside in a separate server.
P.S: I have read all the stackoverflow questions on this matter but none seem to answer my questions.
question from:
https://stackoverflow.com/questions/65846171/django-and-apscheduler-not-running-on-iis-server 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…