在 Azure 应用服务中使用 WebJobs 运行后台任务Run background tasks with WebJobs in Azure App Service

10/19/2020

本文内容

本文介绍如何使用 Azure 门户部署 WebJobs,以便上传可执行文件或脚本。This article shows how to deploy WebJobs by using the Azure portal to upload an executable or script. 有关如何使用 Visual Studio 开发和部署 WebJobs 的信息,请参阅使用 Visual Studio 部署 WebJobs。For information about how to develop and deploy WebJobs by using Visual Studio, see Deploy WebJobs using Visual Studio.

概述Overview

WebJobs 是 Azure 应用服务的一项功能,它允许你在与 Web 应用、API 应用或移动应用相同的实例中运行程序或脚本。WebJobs is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app, API app, or mobile app. 使用 Web 作业无需支付额外的费用。There is no additional cost to use WebJobs.

重要

Linux 上的应用服务尚不支持 WebJobs。WebJobs is not yet supported for App Service on Linux.

可以结合 WebJobs 使用 Azure WebJobs SDK 来简化许多编程任务。The Azure WebJobs SDK can be used with WebJobs to simplify many programming tasks. For more information, see What is the WebJobs SDK.

Web 作业类型WebJob types

下表描述了 连续 和 触发 Web 作业之间的差别。The following table describes the differences between continuous and triggered WebJobs.

连续Continuous

触发Triggered

创建 Web 作业后立即启动。Starts immediately when the WebJob is created. 若要防止作业终止,程序或脚本通常在无限循环中执行其工作。To keep the job from ending, the program or script typically does its work inside an endless loop. 如果作业确实终止,可将其重启。If the job does end, you can restart it.

仅当手动触发或按计划触发时启动。Starts only when triggered manually or on a schedule.

在运行 Web 应用的所有实例上运行。Runs on all instances that the web app runs on. 可以选择性地将 Web 作业限制为单个实例。You can optionally restrict the WebJob to a single instance.

在 Azure 选择用于负载均衡的单个实例上运行。Runs on a single instance that Azure selects for load balancing.

支持远程调试。Supports remote debugging.

不支持远程调试。Doesn't support remote debugging.

备注

Web 应用可在进入非活动状态 20 分钟后超时。A web app can time out after 20 minutes of inactivity. 只有向实际 Web 应用发出的请求才会重置计时器。Only requests to the actual web app reset the timer. 在 Azure 门户中查看应用的配置或向高级工具站点 (https://.scm.chinacloudsites.cn) 发出请求不会重置计时器。Viewing the app's configuration in the Azure portal or making requests to the advanced tools site (https://.scm.chinacloudsites.cn) don't reset the timer. 如果应用运行连续性或计划的(计时器触发器)WebJobs,可启用 Always On 来确保 WebJobs 可靠运行。If your app runs continuous or scheduled (Timer trigger) WebJobs, enable Always On to ensure that the WebJobs run reliably. 此功能仅在基本、标准和高级定价层中提供。This feature is available only in the Basic, Standard, and Premium pricing tiers.

支持的脚本或程序文件类型Supported file types for scripts or programs

支持以下文件类型:The following file types are supported:

.cmd、.bat、.exe(使用 Windows cmd).cmd, .bat, .exe (using Windows cmd)

.ps1(使用 PowerShell).ps1 (using PowerShell)

.sh(使用 Bash).sh (using Bash)

.php(使用 PHP).php (using PHP)

.py(使用 Python).py (using Python)

.js(使用 Node.js).js (using Node.js)

.jar(使用 Java).jar (using Java)

创建连续 Web 作业Create a continuous WebJob

在 Azure 门户中,转到应用服务 Web 应用、API 应用或移动应用的“应用服务”页。In the Azure portal, go to the App Service page of your App Service web app, API app, or mobile app.

选择“Web 作业”。Select WebJobs .

在“Web 作业”页中,选择“添加”。In the WebJobs page, select Add .

使用表中指定的“添加 Web 作业” 设置。Use the Add WebJob settings as specified in the table.

设置Setting

示例值Sample value

说明Description

名称Name

myContinuousWebJobmyContinuousWebJob

在应用服务应用中唯一的名称。A name that is unique within an App Service app. 必须以字母或数字开头,且不能包含除“-”和“”以外的特殊字符。Must start with a letter or a number and cannot contain special characters other than "-" and "".

文件上传File Upload

ConsoleApp.zipConsoleApp.zip

一个 .zip 文件,其中包含可执行文件或脚本文件,以及运行程序或脚本所需的所有支持文件。A .zip file that contains your executable or script file as well as any supporting files needed to run the program or script. 支持的文件类型部分中列出了支持的可执行文件或脚本文件类型。The supported executable or script file types are listed in the Supported file types section.

类型Type

连续Continuous

本文前面介绍了 Web 作业类型。The WebJob types are described earlier in this article.

缩放Scale

多实例Multi instance

仅适用于连续 Web 作业。Available only for Continuous WebJobs. 确定程序或脚本是在所有实例还是只在一个实例上运行。Determines whether the program or script runs on all instances or just one instance. 指定要在多个实例上运行的选项不适用于免费或共享定价层。The option to run on multiple instances doesn't apply to the Free or Shared pricing tiers.

单击 “确定” 。Click OK .

新的 Web 作业随即显示在“Web 作业”页上。The new WebJob appears on the WebJobs page.

要停止或重启某个连续 Web 作业,请在列表中右键单击该 Web 作业,并单击“停止”或“启动”。To stop or restart a continuous WebJob, right-click the WebJob in the list and click Stop or Start .

创建手动触发的 Web 作业Create a manually triggered WebJob

在 Azure 门户中,转到应用服务 Web 应用、API 应用或移动应用的“应用服务”页。In the Azure portal, go to the App Service page of your App Service web app, API app, or mobile app.

选择“Web 作业”。Select WebJobs .

在“Web 作业”页中,选择“添加”。In the WebJobs page, select Add .

使用表中指定的“添加 Web 作业”设置。Use the Add WebJob settings as specified in the table.

设置Setting

示例值Sample value

说明Description

名称Name

myTriggeredWebJobmyTriggeredWebJob

在应用服务应用中唯一的名称。A name that is unique within an App Service app. 必须以字母或数字开头,且不能包含除“-”和“”以外的特殊字符。Must start with a letter or a number and cannot contain special characters other than "-" and "".

文件上传File Upload

ConsoleApp.zipConsoleApp.zip

一个 .zip 文件,其中包含可执行文件或脚本文件,以及运行程序或脚本所需的所有支持文件。A .zip file that contains your executable or script file as well as any supporting files needed to run the program or script. 支持的文件类型部分中列出了支持的可执行文件或脚本文件类型。The supported executable or script file types are listed in the Supported file types section.

类型Type

触发Triggered

本文前面介绍了 Web 作业类型。The WebJob types are described earlier in this article.

触发器Triggers

手动Manual

单击 “确定” 。Click OK .

新的 Web 作业随即显示在“Web 作业”页上。The new WebJob appears on the WebJobs page.

如果要运行 Web 作业,请在列表中右键单击其名称,并单击“运行” 。To run the WebJob, right-click its name in the list and click Run .

创建计划的 Web 作业Create a scheduled WebJob

在 Azure 门户中,转到应用服务 Web 应用、API 应用或移动应用的“应用服务”页。In the Azure portal, go to the App Service page of your App Service web app, API app, or mobile app.

选择“Web 作业”。Select WebJobs .

在“Web 作业”页中,选择“添加”。In the WebJobs page, select Add .

使用表中指定的“添加 Web 作业”设置。Use the Add WebJob settings as specified in the table.

设置Setting

示例值Sample value

说明Description

名称Name

myScheduledWebJobmyScheduledWebJob

在应用服务应用中唯一的名称。A name that is unique within an App Service app. 必须以字母或数字开头,且不能包含除“-”和“”以外的特殊字符。Must start with a letter or a number and cannot contain special characters other than "-" and "".

文件上传File Upload

ConsoleApp.zipConsoleApp.zip

一个 .zip 文件,其中包含可执行文件或脚本文件,以及运行程序或脚本所需的所有支持文件。A .zip file that contains your executable or script file as well as any supporting files needed to run the program or script. 支持的文件类型部分中列出了支持的可执行文件或脚本文件类型。The supported executable or script file types are listed in the Supported file types section.

类型Type

触发Triggered

本文前面介绍了 Web 作业类型。The WebJob types are described earlier in this article.

触发器Triggers

计划Scheduled

要使计划可靠运行,请启用 Always On 功能。For the scheduling to work reliably, enable the Always On feature. Always On 仅在基本、标准和高级定价层中提供。Always On is available only in the Basic, Standard, and Premium pricing tiers.

CRON 表达式CRON Expression

0 0/20 * * * *0 0/20 * * * *

以下部分介绍了 CRON 表达式。CRON expressions are described in the following section.

单击 “确定” 。Click OK .

新的 Web 作业随即显示在“Web 作业”页上。The new WebJob appears on the WebJobs page.

NCRONTAB 表达式NCRONTAB expressions

可以在门户中输入 NCRONTAB 表达式,或者在 Web 作业 .zip 文件的根目录中包含一个 settings.job 文件,如以下示例中所示:You can enter a NCRONTAB expression in the portal or include a settings.job file at the root of your WebJob .zip file, as in the following example:

{

"schedule": "0 */15 * * * *"

}

备注

运行 CRON 表达式使用的默认时区为协调世界时 (UTC)。The default time zone used to run CRON expressions is Coordinated Universal Time (UTC). 若要让 CRON 表达式基于其他时区运行,请为函数应用创建一个名为 WEBSITE_TIME_ZONE 的应用设置。To have your CRON expression run based on another time zone, create an app setting for your function app named WEBSITE_TIME_ZONE. 若要了解详细信息,请参阅 NCRONTAB 时区。To learn more, see NCRONTAB time zones.

查看作业历史记录View the job history

选择要查看其历史记录 Web 作业,并选择“日志”按钮。Select the WebJob you want to see history for, and then select the Logs button.

在“Web 作业详细信息”页中,选择一个时间以查看一个运行轮次的详细信息。In the WebJob Details page, select a time to see details for one run.

在“Web 作业运行详细信息”页中,选择“切换输出”查看日志内容的文本。In the WebJob Run Details page, select Toggle Output to see the text of the log contents.

若要在单独的浏览器窗口中查看输出文本,请选择“下载”。To see the output text in a separate browser window, select download . 若要下载文本本身,请右键单击“下载”,并使用浏览器选项来保存文件内容。To download the text itself, right-click download and use your browser options to save the file contents.

选择页面顶部的“Web 作业”痕迹导航链接转到 Web 作业列表。Select the WebJobs breadcrumb link at the top of the page to go to a list of WebJobs.

后续步骤Next steps

可以结合 WebJobs 使用 Azure WebJobs SDK 来简化许多编程任务。The Azure WebJobs SDK can be used with WebJobs to simplify many programming tasks. For more information, see What is the WebJobs SDK.

azure webjob java_使用 WebJobs 运行后台任务 | Azure Docs相关推荐

  1. azure webjob java_Executing Java Web Jobs on Azure

    Executing Java Web Jobs on Azure 04/28/2015 2 分钟可看完 本文内容 To execute the Java web jobs on Azure, foll ...

  2. 构建一个运行在Azure虚拟机上的MySQL Spring Boot应用程序

    \ 关键要点 \\ 从GitHub中获取一个简单的Spring Boot Java应用程序.\\t 将应用程序连接到Azure MySQL数据库服务.\\t 在Azure上配置一个运行WildFly的 ...

  3. 在Azure上的Ubuntu Docker运行SQL Server

    在Azure上的Ubuntu Docker运行SQL Server 备注:Blog具有时效性, 内容随着更新会发现变化,时间是2017年5月22日 这是非常非常难于想象和相信的事情,前几天我写了SQL ...

  4. 「Azure」数据分析师有理由爱Azure之二-立即申请帐号开始学习之旅

    目前关于Azure的学习资料不多,除了官方的文档和Microsoft Learn频道外,几乎没有什么中文性资料可学习,就算有,也是以IT的思维方式来展开介绍,对没有IT背景的数据分析师来说,非常难于适 ...

  5. azure 使用_如何使用JavaScript在Azure上开始使用SignalR

    azure 使用 The other day, some fine developers at my company were getting ready to roll out a status u ...

  6. azure api 管理_通过成本管理跟踪Azure成本

    azure api 管理 The Azure Portal offers the free tool Cost Management that we can use for managing Azur ...

  7. azure 使用_如何使用命令行和Azure自动执行任务

    azure 使用 介绍 ( Introduction ) The sqlcmd is a very powerful tool to run SQL Server scripts, T-SQL com ...

  8. azure创建centos_如何使用Blazor和Azure计算机视觉创建光学字符读取器

    azure创建centos 介绍 (Introduction) In this article, we will create an optical character recognition (OC ...

  9. Azure Stack技术深入浅出系列6:Azure Stack一体机探究 — 揭开黑盒子的神秘面纱

    Azure Stack是微软公有云平台的延伸,为客户环境里提供接口和相关的功能.微软的Azure Stack安装在指定的合作伙伴的一体机中,并以一体机的形式部署到客户的混合云应用环境里的.2017年7 ...

最新文章

  1. 【RecyclerView】 八、RecyclerView.ItemDecoration 条目装饰 ( onDraw 和 onDrawOver 绘制要点 )
  2. 360极速浏览器无法正确getHours
  3. bzoj3252攻略(线段树+dfs序)或者(树链剖分+dfs)
  4. 我的osu游戏程序设计(oo)
  5. 从 0 搭建一个工业级推荐系统
  6. Word Frequency(Leetcode192)
  7. 年末大盘点 2008十大最受欢迎的装机软件
  8. 卡壳卡壳(是读qia)
  9. 远程连接服务器---SSH详解
  10. 医院考勤签到系统设计与实现
  11. 成就系统实现(三)-架构设计
  12. 网上的测量工具-在线直尺
  13. [路由][教程]OpenWrt设置为交换机+无线功能教程
  14. sql server 2014 使用sql清理日志(简单方便)
  15. java毕业设计软件源代码SSM家庭理财|个人理财管理系统|记账系统
  16. 批量下载:斯坦福大学公开课-编程范式,来源:网易公开课
  17. 从容淡定的女人最美丽
  18. spring框架官网直译IOC容器(1.5-1.8)
  19. connectify中文版有效避免wifi辐射
  20. 【Datawhale202208《吴军计算之魂》】

热门文章

  1. 十五、Python操作mysql数据库
  2. mysql数据库关联练习_mysql数据库建立数据表的练习(附代码)
  3. 公开说说别人看不到_当听到别人在说自己坏话时,心里是什么感受?
  4. JQuery Datatables 实现对某一列的数据合计汇总
  5. java网页解析包_java 网页解析工具包 Jsoup
  6. java hibernate 表关联_Hibernate多表关联
  7. 数字图像处理基础与应用 第五章
  8. java重定向cookie_response请求转发和重定向,cookie
  9. oracle ora31633,ORA-31633: unable to create master table
  10. fp算法例题_机器学习(九)—FP-growth算法