16

I have a Python script that gets data from Google Analytics and puts in into a CSV file. I currently run this script on a local machine but I'd like to run the script in my companies Azure tenant. What Azure service could / should I use to run this script on a daily schedule?

2 Answers 2

25

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.

I created a simple Trigger webjob for your reference.

Step 1: I write a Sample.py as below:

enter image description here

I used the python third-party module virtualenv create a isolated python environment and used the pip install requests command line to download the libs packages that the requests depend on.

enter image description here

​ then keep the Sample.py uniformly compressed into a folder with the libs packages dependent on the requests that you rely on.

enter image description here

Step 2: Create webjob in Web app service. Here, I choose Triggered Type and set cron expression 0/5 * * * * * which means this job will be excuted per 5 seconds.

enter image description here

you'll see the Web Job list after your successful creation.

Step 3: You could check your running web job's status and logs via the Logs button as below:

enter image description here

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

7 Comments

What's in activate.bat (Step 1, second screenshot)?
@Mike That's the Virtualenv in Python, please see this document:virtualenv.pypa.io/en/stable/userguide
Yep, should've checked the path in the screenshot. I thought you had created a custom wrapper for it. Thanks
Hello! May I ask because the guy asking the question asked that the program generates a .csv file, in that case if he would run it on azure where would he be able to get the .csv file? Thank you! :D
Using a Python Runtime stack requires you to use a Linux App instance, which does not currently support WebJobs learn.microsoft.com/en-us/azure/app-service/webjobs-create
|
6

In addition to the first answer you can also use azure functions with a timer which is basically a script on a cronjob without a full machine and paid by invocation. https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview

2 Comments

Thanks, this looks like a better option than a VM however it seems the Timer trigger - necessary for the script to run on a schedule - doesn't work with Python (only C#, Javascript, and F#)
Worthwhile to say that Azure Functions now support the Timer Trigger in Python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.