Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

Django and APScheduler not running on IIS Server

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...