在Azure上计划python脚本 [英] Scheduling a python script on Azure
问题描述
所以我一直在考虑每天安排python脚本,而不是在自己的计算机上使用Task Scheduler,所以我想知道使用Azure云帐户这样做的最佳选择是什么.
根据您的需求,建议您在Web Apps Service中使用 Web Jobs .
它有两种类型的Azure Web作业供您选择:连续和触发.根据您的需求,应采用触发器.
您可以在
<强> 步骤2 强>:执行commad创建独立Python运行时环境
第3步 :然后进入创建目录的 Scripts 文件夹并激活它(这一步很重要,不要错过)
请不要关闭此命令窗口,并使用 pip install<您的库名称>
在此命令窗口中下载外部库.
第4步 :将Webjob.py(这是您自己的业务代码)保持统一压缩到一个文件夹中,该文件夹包含 Libs/site中的libs包-packages 文件夹.
第5步 :在Web应用服务中创建Webjob并上传zip文件,然后您可以执行Web Job并检查日志
您还可以参考SO线程:
顺便说一句,您需要首先创建一个Azure Web应用程序,因为Webjob在Azure Web应用程序中运行.
希望它对您有帮助.
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 what is the best option I have to do so using an Azure cloud account.
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.
Step2 : Run the commad to create independent python runtime environment.
Step 3: Then go into the created directory's Scripts folder and activate it (this step is important , don't miss it)
Please don't close this command window and use pip install <your libraryname>
to download external libraries in this command window.
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.
Step 5: Create webjob in Web app service and upload the zip file,then you could execute your Web Job and check the log
You could also refer to the SO thread:
1.Options for running Python scripts in Azure
BTW,you need to create a azure web app first because Webjob runs in azure web app.
Hope it helps you.
这篇关于在Azure上计划python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!