使用 PowerShell 创建计划的 Azure WebJob [英] Create a Scheduled Azure WebJob with PowerShell

查看:20
本文介绍了使用 PowerShell 创建计划的 Azure WebJob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 Azure WebJob 以将 BrokeredMessage 发送到 Azure ServiceBus 主题,创建和发送消息的实际行为是微不足道的,但是我一直无法找到自动化的方法计划 WebJob 的创建.

I am trying to create an Azure WebJob to send a BrokeredMessage to an Azure ServiceBus Topic, the actual act of creating and sending the message is trivial however I have been unable to find a way to automate the creation of the Scheduled WebJob.

自动化工作流程应该如下工作:

The automated workflow should work as follows:

  1. 创建一个新的 Azure 网站[完成]
  2. 创建一个新的触发 Azure WebJob,上传 PS1 文件[完成]
  3. 创建新的 Azure 调度程序作业集合[经过验证的概念]
  4. 创建一个触发 WebJob 的新 Azure 调度程序作业

Azure 管理门户为此功能提供了一个不错的 UI,它在后台创建了一个在所选网站中的 Azure WebJob、一个 Azure 调度程序作业集合和一个 Azure 调度程序作业:

The Azure Management Portal provides a nice UI for this functionality, which under the covers creates an Azure WebJob in the selected WebSite, an Azure Scheduler Job Collection and an Azure Scheduler Job:

似乎没有类似的机制可以使用 Azure 服务管理 PowerShell 模块创建计划的 Azure WebJob.当然可以创建新的 WebJobs, Azure 调度程序集合Jobs - 但是我不知道 Azure 调度程序发布到哪个 URL 或存储队列来调度 Azure WebJobs.

There doesn't appear to be an analogous mechanism for creating a scheduled Azure WebJob with the Azure Service Management PowerShell Module. It is certainly possible to create new WebJobs, Azure Scheduler Collections and Jobs - however I have no idea what URL or Storage Queue the Azure Scheduler is posting to to schedule Azure WebJobs.

推荐答案

Azure Scheduler 和 Azure WebJobs 之间有着密切的关系.具体来说,Azure WebJobs 对调度没有任何内部支持,WebJobs 依赖 Azure 调度程序调用 *.scm.azurewebsites.net 网站.

There is a close relationship between Azure Scheduler and Azure WebJobs. Specifically Azure WebJobs does not have any internal support for scheduling, WebJobs relies on the Azure Scheduler to call into the *.scm.azurewebsites.net website.

因此,可以对这些服务使用 PowerShell cmdlet 来设置 Azure WebJobs,以便使用 Azure Scheduler 按计划触发.

As such it is possible to use PowerShell cmdlets for these services to setup Azure WebJobs to be triggered on schedule using Azure Scheduler.

$location = "North Europe";

$site = New-AzureWebsite -Location $location `
  -Name "amido-test-website";
$job = New-AzureWebsiteJob -Name $site.Name `
  -JobName "amido-test-job" `
  -JobType Triggered `
  -JobFile ~Desktop	est.zip;
$jobCollection = New-AzureSchedulerJobCollection `
  -Location $location `
  -JobCollectionName "amido-test-job-collection";
$authPair = "$($site.PublishingUsername):$($site.PublishingPassword)";
$pairBytes = [System.Text.Encoding]::UTF8.GetBytes($authPair);
$encodedPair = [System.Convert]::ToBase64String($pairBytes);
New-AzureSchedulerHttpJob `
  -JobCollectionName $jobCollection[0].JobCollectionName `
  -JobName "test" `
  -Method POST `
  -URI "$($job.Url)
un" `
  -Location $location `
  -StartTime "2014-01-01" `
  -Interval 1 `
  -Frequency Minute `
  -EndTime "2015-01-01" `
  -Headers @{ `
    "Content-Type" = "text/plain"; `
    "Authorization" = "Basic $encodedPair"; `
  };

这有点冗长,所以用简单的英语来说,上面的脚本执行以下操作:

It's a little long winded so in plain english the above script does the following:

  1. 创建一个新的 Azure 网站.
  2. 创建并上传新的 WebJob.
  3. 创建一个新的 Azure 调度程序作业集合.
  4. 生成 HTTP 基本身份验证标头值.
  5. 创建一个新的 Azure 调度程序 HTTP 作业,向 *.scm.azurewebsites.net API 发出经过身份验证的请求.

希望这可以使其他一些开发人员免于摸不着头脑地试图弄清楚这一点.

Hope this saves a few other developers from scratching their head trying to figure this one out.

这篇关于使用 PowerShell 创建计划的 Azure WebJob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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