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?

user2637453
  • 345
  • 1
  • 3
  • 9

2 Answers2

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

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • What's in `activate.bat` (Step 1, second screenshot)? – Mike Feb 09 '19 at 22:24
  • @Mike That's the Virtualenv in Python, please see this document:https://virtualenv.pypa.io/en/stable/userguide/ – Jay Gong Feb 11 '19 at 02:11
  • Yep, should've checked the path in the screenshot. I thought you had created a custom wrapper for it. Thanks – Mike Feb 11 '19 at 02:19
  • It seems that screenhot url is not valid anymore? Woould you edit it? – Gultekin Jun 08 '19 at 15:36
  • 1
    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 –  Sep 16 '20 at 08:16
  • 1
    Using a Python Runtime stack requires you to use a Linux App instance, which does not currently support WebJobs https://learn.microsoft.com/en-us/azure/app-service/webjobs-create – Naishy Sep 24 '20 at 19:27
  • @Jay Gong I have searched all over and look like your post could help me run a python script using webjobs. I however cant access your link that explains activate.bat. Are you able to explain what the .batfile is? – wwnde Oct 31 '20 at 03:41
5

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

Srgrn
  • 1,770
  • 16
  • 30
  • 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#) – user2637453 Aug 16 '17 at 16:08
  • 1
    Worthwhile to say that Azure Functions now support the Timer Trigger in Python – scottdavidwalker Mar 26 '21 at 09:57