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 .
在“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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 应用指定显示到副屏_广电演播领域与舞台L
- 下一篇: css 文字重叠_学习过CSS,那你知道