我在 Azure 门户中的暂存槽中使用自动部署来部署 Webjob,但问题是此 webjob 在部署后直接运行,它可能会导致主槽 webjob 和暂存 webjob 之间出现混淆。
有没有办法在不运行 webjob 的情况下部署它,除非我启动它并交换插槽?
我有一个简单的 Azure WebJobs ServiceBusTrigger,看起来像
public static async void ProcessQueueMessage([ServiceBusTrigger("myqueuename")] String json, TextWriter log) { ... }
Run Code Online (Sandbox Code Playgroud)
不幸的是,它无法将 JSON 反序列化为 XML(不足为奇)。我检查了有效负载并确认它只是一个 UTF-8 编码的字节数组。我有两个问题。
堆栈跟踪:
System.InvalidOperationException: Exception binding parameter 'json' ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type System.String. The input source is not correctly formatted. ---> System.Xml.XmlException: The input source is not correctly formatted.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlBufferReader.ReadValue(XmlBinaryNodeType nodeType, ValueHandle value)
at System.Xml.XmlBinaryReader.ReadNode() …Run Code Online (Sandbox Code Playgroud) 场景:生产者向存储队列发送消息,一个WebJobs在QueueTrigger上处理该消息,每条消息只能处理一次,可以有多个WebJob实例。
我一直在谷歌搜索,从我读过的内容来看,我需要编写处理消息的函数以使其具有幂等性,因此消息不会被处理两次。我还读到消息的默认租用时间为 10 分钟。
我的问题是,当在一个 WebJob 实例上触发 QueueTrigger 时,它是否设置了消息的租用时间,以便另一个 WebJob 无法获取相同的消息?如果是这样,为什么我需要考虑消息可以被处理两次的可能性?还是我误解了这一点?
我正在尝试在 Azure 中设置计划的 WebJob。我能够部署我的网络作业。我可以通过门户明确运行网络作业。但是,我似乎无法让它按定期计划运行。
我希望该作业每 5 分钟运行一次。我意识到这不是免费的,我已更改为付费套餐并调整了最大重复阈值设置。有一次我因为设置而收到错误。
当我部署时,WebJob 显示为“按需”,并且它不会重复运行。我究竟做错了什么?
这是我所拥有的:
webjob-发布-settings.json
{
"$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
"webJobName": "Shopping-Logs-WebJob",
"startTime": "2016-01-07T00:00:00-08:00",
"endTime": null,
"jobRecurrenceFrequency": "Minute",
"interval": 5,
"runMode": "Scheduled"
}
Run Code Online (Sandbox Code Playgroud)
程序.cs
public class Program
{
static void Main()
{
var host = new JobHost();
host.Call(typeof(Functions).GetMethod("ManualTrigger"));
}
}
Run Code Online (Sandbox Code Playgroud)
函数.cs
public class Functions
{
[NoAutomaticTrigger]
public static void ManualTrigger(TextWriter log)
{
string storageAccountName = CloudConfigurationManager.GetSetting("AzureStorageAccountName");
string storageKey = CloudConfigurationManager.GetSetting("AzureStorageAccessKey");
SendMessage("String Fetched", (storageAccountName ?? String.Empty) + ":" + (storageKey ?? String.Empty));
if (String.IsNullOrWhiteSpace(storageAccountName) || String.IsNullOrWhiteSpace(storageKey))
{ …Run Code Online (Sandbox Code Playgroud) Azure 文件存储活动可以触发 Azure WebJob 或 Azure Function 吗?
例如,在文件夹“/todo/”中创建文件时。
我在使用 Webhook url 触发 Azure webjobs 时遇到问题。
我创建了一个简单的“NoAutomaticTriggerAttribute”Azure web 作业,下面是代码
例如:
class Program
{
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
static void Main()
{
var test = ConfigurationManager.ConnectionStrings["AzureWebJobsDashboard"].ConnectionString.ToString();
var config = new JobHostConfiguration(test);
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
host.Call(typeof(Functions).GetMethod("ProcessMethod"));
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
}
Run Code Online (Sandbox Code Playgroud)
下面是函数类代码:
public class Functions
{
// This function will …Run Code Online (Sandbox Code Playgroud) 我有一个 Azure Web 作业 ( .NET Core 2.2),它在启动时从配置中读取一些设置,如下所示:
var builder = new HostBuilder()
.UseEnvironment(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"))
.ConfigureWebJobs()
.ConfigureAppConfiguration((hostContext, configApp) =>
{
configApp.AddEnvironmentVariables();
configApp.AddJsonFile("appsettings.json", optional: false);
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConsole();
var instrumentationKey = hostingContext.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
if (!string.IsNullOrEmpty(instrumentationKey))
{
Console.Writeline(instrumentationKey); // <- this always outputs key from appsettings.json, not from Azure Settings
logging.AddApplicationInsights(instrumentationKey);
}
})
.UseConsoleLifetime();
Run Code Online (Sandbox Code Playgroud)
如你看到的, appsettings.json文件应该有一个APPINSIGHTS_INSTRUMENTATIONKEY密钥,并且在开发环境中读取它很好。
现在,对于生产,我想覆盖它 APPINSIGHTS_INSTRUMENTATIONKEY通过在 Azure 应用程序设置 Web 界面中添加具有相同密钥的设置密钥。
但是,当我将我的 webjob 部署到 Azure 时,它仍然具有来自appsettings.json. 为了强制我的 webjob 具有 Azure 应用程序设置中的覆盖密钥,我必须从appsettings.json. …
我有一个 Azure Functions 应用程序。
我很惊讶地发现,在定义 Azure WebJob 函数时,HttpTriggerAttribute 不必应用于 HttpRequest 参数。
因此,虽然这是有效的,并且与大多数教程和示例相匹配,
[FunctionName("get")]
public async Task<IActionResult> Get(
[HttpTrigger(AuthorizationLevel.Anonymous, nameof(HttpMethods.Get), Route = "api/get")]HttpRequest httpRequest)
Run Code Online (Sandbox Code Playgroud)
这也是有效的,
[FunctionName("post")]
public async Task<IActionResult> Post(
[HttpTrigger(AuthorizationLevel.Anonymous, nameof(HttpMethods.Post), Route = "api/post")]MyType body)
Run Code Online (Sandbox Code Playgroud)
由于该属性未绑定到 HttpRequest 参数,因此我很惊讶该属性是参数属性而不是方法属性,例如,
[FunctionName("post")]
[HttpTrigger(AuthorizationLevel.Anonymous, nameof(HttpMethods.Post), Route = "api/post")]
public async Task<IActionResult> Post(MyType body)
Run Code Online (Sandbox Code Playgroud)
为什么 HttpTriggerAttribute 被实现为参数属性而不是像 FunctionNameAttribute 这样的方法属性?
与我的问题 60304305有点相关......我的 Azure webJob 应用程序处理多个队列,但它们不会产生高流量。尽管如此,该应用程序仍会不时遇到超时异常,并且几乎不可能重现该错误,但是在 Queue 函数内的断点处中断并保持一段时间时,我取得了一些成功。
System.TimeoutException
HResult=0x********
Message=The operation 'GetMessages' with id '********-****-****-****-************' did not complete in '00:02:00'.
Source=Microsoft.Azure.WebJobs.Extensions.Storage
StackTrace:
at Microsoft.Azure.WebJobs.Extensions.Storage.TimeoutHandler.<ExecuteWithTimeout>d__1`1.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\TimeoutHandler.cs:line 30
at Microsoft.Azure.WebJobs.Host.Timers.WebJobsExceptionHandler.<>c__DisplayClass3_0.<OnUnhandledExceptionAsync>b__0() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Timers\WebJobsExceptionHandler.cs:line 54
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
This exception was originally thrown at this call stack:
Microsoft.Azure.WebJobs.Extensions.Storage.TimeoutHandler.ExecuteWithTimeout<T>(string, string, Microsoft.Azure.WebJobs.Host.Timers.IWebJobsExceptionHandler, System.Func<System.Threading.Tasks.Task<T>>) in TimeoutHandler.cs
Microsoft.Azure.WebJobs.Host.Timers.WebJobsExceptionHandler.OnUnhandledExceptionAsync.AnonymousMethod__0() …Run Code Online (Sandbox Code Playgroud) 在我的解决方案中,我有一个 aspnet core 2.2 WebApp,我想添加一个现有项目,例如 webJob,但没有选项:从现有项目添加 WebJobs
为什么?使用相同的过程,我在其他 .Net 应用程序上添加 WebJobs,该选项显示在 Visual Studio 2019 中
编辑
用英语更改图像。有时,“添加”>“现有项目”会显示为 Azure WebJobs,但如果我单击它,则会显示以下错误:
(选择的项目是aspnet.core 2.2.WebApp)
单击此按钮后,“添加”>“作为 Azure WebJobs 的现有项目”将不再可见。
c# azure-webjobs azure-webjobssdk asp.net-core visual-studio-2019