在 Azure 中运行 Python 脚本的选项 [英] Options for running Python scripts in Azure

查看:41
本文介绍了在 Azure 中运行 Python 脚本的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Python 脚本,可以从 Google Analytics 获取数据并将其放入 CSV 文件中.我目前在本地机器上运行此脚本,但我想在我的公司 Azure 租户中运行该脚本.我可以/应该使用什么 Azure 服务来每天运行此脚本?

解决方案

根据您的需要,我建议您使用 Web Apps Service 中的 Web Jobs.

它有两种类型的 Azure Web 作业供您选择:持续触发.根据您的需要,应采用触发器.

您可以在

我使用python第三方模块virtualenv创建了一个独立的python环境,并使用pip install requests命令行下载了请求所依赖的libs包.

然后将 Sample.py 统一压缩到一个文件夹中,其中包含依赖于您依赖的请求的 libs 包.

第 2 步:在 Web 应用服务中创建 webjob.在这里,我选择了 Triggered Type 并设置了 cron 表达式 0/5 * * * * * 这意味着该作业将每 5 秒执行一次.

创建成功后,您将看到 Web 作业列表.

第 3 步:您可以通过日志按钮查看正在运行的网络作业的状态和日志,如下所示:

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?

解决方案

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:

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.

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

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.

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:

这篇关于在 Azure 中运行 Python 脚本的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆