10

So I was looking into scheduling a python script on a daily basis and, rather than using Task Scheduler on my own machine, I was wondering if it is possible to do so using an Azure cloud account.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
lemac
  • 193
  • 1
  • 1
  • 7

1 Answers1

11

For your needs, I suggest you use Web Jobs in Web Apps Service.

It has two types of Azure Web Jobs for you to choose: Continuous and Trigger. For your needs, Trigger should be adopted.

You could refer to the document here for more details.In addition, here shows how to run tasks in WebJobs.

You could refer to the steps as below to create your webjob.

Step 1 : Use the virtualenv component to create an independent python runtime environment in your system.Please install it first with command pip install virtualenv if you don't have it.

If you installed it successfully ,you could see it in your python/Scripts file.

enter image description here

Step2 : Run the commad to create independent python runtime environment.

enter image description here

Step 3: Then go into the created directory's Scripts folder and activate it (this step is important , don't miss it)

enter image description here

Please don't close this command window and use pip install <your libraryname> to download external libraries in this command window.

enter image description here

Step 4:Keep the Webjob.py(which is your own business code) uniformly compressed into a folder with the libs packages in the Libs/site-packages folder that you rely on.

enter image description here

Step 5: Create webjob in Web app service and upload the zip file,then you could execute your Web Job and check the log

enter image description here

You could also refer to the SO thread:

1.Options for running Python scripts in Azure

2.Python libraries on Web Job

BTW,you need to create a azure web app first because Webjob runs in azure web app.

Hope it helps you.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • 2
    I started with this provided answer but the free tier didn't provide the functionality I needed (Python + scheduled trigger). I switched to a serverless Azure Function in Python with a timer trigger to get the required functionality. Tutorial, use timer trigger instead of http trigger: https://learn.microsoft.com/en-us/azure/developer/python/tutorial-vs-code-serverless-python-01 – Synck Dec 19 '20 at 11:35