Set up a scheduled job?

后端 未结 24 2533
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 01:13

I\'ve been working on a web app using Django, and I\'m curious if there is a way to schedule a job to run periodically.

Basically I just want to run through the dat

24条回答
  •  逝去的感伤
    2020-11-22 02:07

    Django APScheduler for Scheduler Jobs. Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically. You can add new jobs or remove old ones on the fly as you please.

    note: I'm the author of this library

    Install APScheduler

    pip install apscheduler
    

    View file function to call

    file name: scheduler_jobs.py

    def FirstCronTest():
        print("")
        print("I am executed..!")
    

    Configuring the scheduler

    make execute.py file and add the below codes

    from apscheduler.schedulers.background import BackgroundScheduler
    scheduler = BackgroundScheduler()
    

    Your written functions Here, the scheduler functions are written in scheduler_jobs

    import scheduler_jobs 
    
    scheduler.add_job(scheduler_jobs.FirstCronTest, 'interval', seconds=10)
    scheduler.start()
    

    Link the File for Execution

    Now, add the below line in the bottom of Url file

    import execute
    
    • You can check the full code by executing [Click here] https://github.com/devchandansh/django-apscheduler

提交回复
热议问题