azure webjob java_使用 WebJobs 运行后台任务 | Azure Docs

在 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 .

ff315ae579f9b6b970ef796db2904cca.png

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

7608eb469e8230bb6abfed9ad39907ca.png

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

90475923b52e0f073fbd2da7f5f5eb54.png

设置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.

3768d21ab05c7e99b8a859cc6b4b9a1f.png

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

8f12a081ef008631cf6628c894c0310e.png

创建手动触发的 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 .

ff315ae579f9b6b970ef796db2904cca.png

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

7608eb469e8230bb6abfed9ad39907ca.png

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

c1ec2626ac08e7424a9cae1079e96a24.png

设置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.

3768d21ab05c7e99b8a859cc6b4b9a1f.png

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

b0916a7372d52bca402abc24ea1fb2d7.png

创建计划的 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 .

ff315ae579f9b6b970ef796db2904cca.png

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

7608eb469e8230bb6abfed9ad39907ca.png

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

b73a1bf89074331f7bb0e9765c0c08d1.png

设置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.

3768d21ab05c7e99b8a859cc6b4b9a1f.png

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.

b705f9f50d2737caa6caaa22a76f2641.png

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

85b088e5baee544d7cc1b1304d588463.png

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

9e4d2f8499c089e3d8a3bc2e8d888418.png

若要在单独的浏览器窗口中查看输出文本,请选择“下载”。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.

d405e47373da2bb6e436dc49ab6ad94a.png

0114a32a5adebe9125ebab7b63e5bfea.png

后续步骤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.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/555854.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

适合程序员的画图工具

最近很多读者私信问我,我图解文章中用到的画图工具、思维导图工具、代码贴图工具是什么? 我在很早的时候提到过,不过时间有点久了,而且比较零散,可能现在大部分读者还不知道。 我今天统一整理一下,我图解…

go加载python_python培训 | python调用go语言来提速

在写一些对性能要求十分严格的功能的时候,python往往力不从心。毕竟是一个解释性的语言,没有办法和变异性的语言去比较速度和内存占用率。但是python的本身的特定就使得我们可以将耗时的操作移交给编译性的语言去实现。由于项目上的关系,需要…

Spring Boot框架中使用Jackson的处理总结

1.前言 通常我们在使用Spring Boot框架时,如果没有特别指定接口的序列化类型,则会使用Spring Boot框架默认集成的Jackson框架进行处理,通过Jackson框架将服务端响应的数据序列化成JSON格式的数据。 本文主要针对在Spring Boot框架中使用Jac…

SpringBoot中对输出的json按字典表排序

SpringBoot中对输出的json按字典表排序 springboot默认的json处理为jackson。 如果是全局设置,在application.properties中添加spring.jackson.mapper.sort-properties-alphabeticallytrue

Java hdfs连接池_Java使用连接池管理Hdfs连接

记录一下Java API 连接hadoop操作hdfs的实现流程(使用连接池管理)。以前做过这方面的开发,本来以为不会有什么问题,但是做的还是坑坑巴巴,内心有些懊恼,记录下这烦人的过程,警示自己切莫眼高手低!一&#x…

为了拿捏 Redis 数据结构,我画了 40 张图(完整版)

Redis 为什么那么快? 除了它是内存数据库,使得所有的操作都在内存上进行之外,还有一个重要因素,它实现的数据结构,使得我们对数据进行增删查改操作时,Redis 能高效的处理。 因此,这次我们就来…

java put set_Java PutItemRequest.setItem方法代码示例

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入方法依赖的package包/类public List reindex(T instance) throws DataStoreException {DynamoClassMapping tableInfo getClassMapping(instance);log.debug("reindex {}", instance.getClas…

fastjson为什么默认是无序的

在做项目的时候,无意间发现添加到json中的元素是无存放顺序的。严格来说,json默认是有存放顺序的,不过是采用HashCode值来排序。下面来看一段源码 上图展示了创建json对象的一个过程,可以清晰的看出,无论用户调用哪个…

php一句话怎么写_PHP一句话木马后门

在我们进行渗透测试的最后阶段,入侵到内网里,无论是想要浏览网站结构,还是抓取数据库,或者是挂个木马等等,到最后最常用的就是执行一句话木马,从客户端轻松连接服务器。一句话木马的原理很简单,…

JSON书写格式

JSON是什么 JSON ( JavaScript Object Notation) ,是一种数据交互格式。 为什么有这个技术 Json之前,大家都用 XML 传递数据。XML 是一种纯文本格式,所以适合在网络上交换数据,但是 XML 格式比较复杂,终于道格拉斯克…

php判断目录是否有写的权限,php中判断文件空目录是否有读写权限

/*问题出现:如何检查一个目录是否可写,如何目录下还有目录和文件,那么都要检查思路:(1)首先先写出检查空目录是否可写的算法:在该目录中生成一个文件,如果不能生成,表明该目录没有写的权限(2)使…

List.addAll方法的入参不能为null

缘由: ​ 某天,发现一段日志中出现了诡异的NPE。经过定位,认为是ArrayList不能加入null所致。 验证: ​ new一个ArrayList,然后调用其addAll方法,并将入参设为null。 public static void main(String[] …

php 微信转账,php实现微信公众号企业转账功能

企业付款提供由商户直接付钱至用户微信零钱的能力,支持平台操作及接口调用两种方式,资金到账速度快,使用及查询方便。主要用来解决合理的商户对用户付款需求,比如:保险理赔、彩票兑换等等。特点发起方式灵活&#xff0…

Java之HashMap.values()转List时的错误和正确操作

因为项目中需要获取到Map的值的集合&#xff0c;所以调用了HashMap.values()方法转成List&#xff0c;当时是使用了以下代码。&#xff08;逻辑上这样想应该没问题&#xff0c;但生活总是会是不是给你一点小“”惊喜“”&#xff09; List<AreaItemOpt> areaItemOpts (…

php检测表大小,查询mysql数据库、表的大小

一、关于mysql表数据大小mysql存储数据文件一般使用表空间存储 &#xff1b;当mysql使用innodb存储引擎的时候&#xff0c;mysql使用表存储数据分为共享表空间和独享表空间两种方式 。共享表空间&#xff1a;Innodb的所有数据保存在一个单独的表空间里面&#xff0c;而这个表空…

Java利用stream(流)对map中的values进行过滤、排序操作

前言 对于Java8中的stream(流)这种优雅、方便、快捷、高效的操作已经是信手沾来了吧&#xff0c;但是却仅限List、Set。难道我Map不要面子得嘛&#xff1f;在工作中需要对从List转Map的数据进行操作&#xff0c;因此便有这随笔。 新建一个User类&#xff0c;注意下面使用lombok…

cls certificate.php,php加密解密处理类

PHP加密解密也是常有的事&#xff0c;发现discuz论坛里的PHP加密解密处理类代码&#xff0c;感觉挺不错&#xff0c;在用的时候&#xff0c;要参考Discuz论坛的passport相关函数&#xff0c;后面我会附上使用方法。php加密解密处理类<?php /* 文件名称&#xff1a;cls.sys_…

【redis】java操作redis时,StringRedisTemplate的expire()方法的作用,什么时候使用

java操作redis时&#xff0c;StringRedisTemplate的expire()方法的作用&#xff0c;什么时候使用 //重新设置过期时间为30分钟&#xff0c;刷新时间 redisTemplate.expire(MsOpenApiRedisUtil.SESSION_KEY_IN_LOGIN_NAMEloginName,30,TimeUnit.MINUTES); redisTemplate.expire…

springboot使用redis(StringRedisTemplate的常用方法)

1. 先了解RedisTemplate和StringRedisTemplate之间的关系&#xff1a; RedisTemplate是Spring对于Redis的封装&#xff0c;而StringRedisTemplate继承RedisTemplate。两者的数据是不共通的&#xff1b;也就是说StringRedisTemplate只能管理StringRedisTemplate里面的数据&…

html提交表单给php邮件发送,在HTML表单中通过PHP自动发送电子邮件

我最终解决了我的问题吧一个细节。我的HTML帖子回答:Navn: Kontakt e-post: Kontakt telefon: Fest:LokalfestHjemmefestKommune: Deltagere: Rydding: Vasking: Dorvakt: Noe annet?: 我的PHP帖子回答:if(isset($_POST[mailform]))$email $_POST[Epost] ;$name $_POST[Navn…