CodeRocks
CodeRocks

Reputation: 715

Django: Run Constantly Running Background Task On IIS-Hosted Application

I have a Django web application hosted on IIS. I subprocess should ALWAYS BE running alongside the web application. When I run the application locally using

python manage.py runserver the background task runs perfectly while the application is running. However, hosted on IIS the background task does not appear to run. How do I make the task run even when hosted on IIS?

In the manage.py file of Django I have the following code:

 def run_background():
     return subprocess.Popen(["python", "background.py"], creationflag=subprocess.CREATE_NEW_PROCESS_GROUP)
 run_background()
 execute_from_command_line(sys.argv)

I do not know how to resolve this issue.

Would something like Celery work to indefinitely run a task? How would I do this? Please give step by step instructions.

Upvotes: 1

Views: 1061

Answers (1)

Jalpa Panchal
Jalpa Panchal

Reputation: 12789

You could set appplication set to auto-start by following below steps:

  • Select Site -> advance setting->Preload enable=”true” enter image description here

  • Select Application pool->advance setting->start mode=”always running”, Under the Process Model section, set the Idle Time-out (minutes) option to 0 and Under the Recycling section, set the Regular Time Interval (minutes) option to 0

enter image description here

  • Run iisreset command from the command prompt. enter image description here

Also, check that you set FastCGI setting: enter image description here

Regards, Jalpa.

Upvotes: 1

Related Questions