azure - 在 Start-Job 中运行时调用 Web-Request Post 未到达 API
问题描述
我有一个 powershell 脚本,它调用我试图在 Azure Runbook 中运行的 API 以使其自动化。从 Web 请求返回响应需要超过 4 分钟,因此我只需触发并忘记它,以避免在 Azure 中触发错误。
我尝试过使用 Start-Job 和 -asJob 但它们中的任何一个都没有运气。我是 powershell 的新手,我曾疯狂地尝试过谷歌搜索,但运气不佳。
当不作为工作运行时,一切正常。任何帮助将不胜感激!
编辑:经过更多挖掘后,我认为这是因为 Azure 的 powershell 处于“受约束的语言模式”,或者至少由于我收到此错误而受到某种限制,Cannot invoke method. Method invocation is supported only on core types in this language mode.
而且脚本在我的本地机器上运行良好。有没有另一种方法可以开火并忘记?
脚本:
Start-Job -ScriptBlock {
$url = "api.com/apitocall"
$ID = [System.guid]::New("id")
$ApiKey = "apikey"
$credPair = "$($ID):$($ApiKey)"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
$headers = @{ Authorization = "Basic $encodedCredentials" }
$headers.Add('Accept','Application/Json')
$responseData = Invoke-WebRequest -Uri $url -Method POST -Headers $headers -
UseBasicParsing -TimeoutSec 660
Write-Output($responseData)
}
Get-Job | Wait-Job
输出:
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 Job1 BackgroundJob Running True localhost ...
1 Job1 BackgroundJob Completed True localhost ...
解决方案
推荐阅读
- python - Sqlalchemy 覆盖关联表中的字段
- python - 如何使用硬盘驱动器上的本地文件实现?
- python - 如何从 Coinmarketcap 解析历史 BTC 数据?
- arrays - 如何创建可循环的已分配但长度为零的数组?
- reactjs - 反应.js。有没有办法实现通用的“onChange”事件处理程序
- scala - 从 Spark DataFrame 中列出的所有列的不同之处
- javascript - 在 Safari 中扩展本机(es6)类的问题
- java - 从 ServerSOAPFaultException 读取 CXF 异常消息详细信息
- apache - ErrorDocument 不能作为 httpd-vhosts.conf 中的本地路径工作
- java - Android:AsyncTask 中的 execute() 方法是如何工作的?