We have a webjob project that is a timer based project. It runs locally (offline in VS2022 debugger), but we are using devops to build as a linux target ‘–runtime linux-x64’ and deploying to App_Data/jobs/triggered/Jobnamefolder/appfiles, and when deployed it does not appear to run, or at least there is no evidence the job exists – it is not shown on the webjobs page – more on that later.
The job is basically the following:
using My.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace My.WebJobs
{
class Program
{
static async Task Main()
{
var host = new HostBuilder()
.ConfigureWebJobs(webJobsBuilder =>
{
webJobsBuilder.AddTimers();
})
.ConfigureAppConfiguration((context, configBuilder) =>
{
configBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
})
.ConfigureLogging((context, b) =>
{
b.AddConsole();
})
.ConfigureServices((context, services) =>
{
var configuration = context.Configuration;
var connectionString = configuration["ConnectionStrings:DefaultConnection"];
services.AddDbContext<DatabaseService>(options =>
{
options.UseSqlServer(connectionString);
});
})
.Build();
using (host)
{
await host.RunAsync();
}
}
}
}
and
using Azure;
using Azure.Communication.Email;
using My.Data;
using My.Domain;
using Microsoft.Azure.WebJobs;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
namespace My.WebJobs
{
public class Functions
{
private readonly DatabaseService _databaseService;
public Functions(DatabaseService databaseService)
{
_databaseService = databaseService;
}
public void TimerTriggeredFunction([TimerTrigger("0 */1 * * * *")] TimerInfo timerInfo, ILogger logger)
{
logger.LogInformation($"Function executed at: {DateTime.Now}");
SendFeedbackEmails(logger).Wait();
}
// this attribute defines what function will be triggered by the web job
[NoAutomaticTrigger]
public async Task SendFeedbackEmails(ILogger logger)
{
...
}
}
}
I have 2 functions, one a TimerTrigger and the other flagged with a NoAutomaticTrigger as it is not called Run.
We also have a ‘settings.job’ with “schedule”: {“0 * * * * *”}
Our website runs up fine but the webjob never runs.
I can SSH into the site and confirm the files are in the folder and log stream shows them copying too.
Logs show nothing related to the webjob unless we go to the Azure Portal webjobs page, in which case a background exception occurs:
2024-07-09T00:20:23.0533898Z Exception StackTrace : at Kudu.Services.Diagnostics.HttpRequestExtensions.ForwardToContainer(String route, HttpRequestMessage request) in /tmp/KuduLite/Kudu.Services/Diagnostics/HttpRequestExtensions.cs:line 22
2024-07-09T00:20:23.0725163Z at Kudu.Services.Jobs.JobsController.ForwardJobRequestToContainer(String route) in /tmp/KuduLite/Kudu.Services/Jobs/JobsController.cs:line 200
2024-07-09T00:20:23.0725763Z at Kudu.Services.Jobs.JobsController.ListAllJobs() in /tmp/KuduLite/Kudu.Services/Jobs/JobsController.cs:line 28
2024-07-09T00:20:23.0725790Z at lambda_method132(Closure , Object , Object[] )
2024-07-09T00:20:23.0725821Z at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
2024-07-09T00:20:23.0725850Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
2024-07-09T00:20:23.0725876Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
2024-07-09T00:20:23.0725962Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
2024-07-09T00:20:23.0725984Z --- End of stack trace from previous location ---
2024-07-09T00:20:23.0726010Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
2024-07-09T00:20:23.0726036Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
2024-07-09T00:20:23.0726059Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
2024-07-09T00:20:23.0732366Z --- End of stack trace from previous location ---
2024-07-09T00:20:23.0732406Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2024-07-09T00:20:23.0732430Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
2024-07-09T00:20:23.0732456Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
2024-07-09T00:20:23.0732502Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
2024-07-09T00:20:23.0732529Z --- End of stack trace from previous location ---
2024-07-09T00:20:23.0732555Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
2024-07-09T00:20:23.0732582Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
2024-07-09T00:20:23.0732604Z at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
2024-07-09T00:20:23.0732630Z at Kudu.Services.Web.Tracing.TraceMiddleware.Invoke(HttpContext context) in /tmp/KuduLite/Kudu.Services.Web/Tracing/TraceMiddleware.cs:line 107
2024-07-09T00:20:23.1611928Z [41m[30mfail[39m[22m[49m: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
2024-07-09T00:20:23.1612508Z An unhandled exception has occurred while executing the request.
2024-07-09T00:20:23.1612536Z System.Net.Http.HttpRequestException: Connection refused (169.254.130.5:50555)
2024-07-09T00:20:23.1626364Z ---> System.Net.Sockets.SocketException (111): Connection refused
2024-07-09T00:20:23.1626787Z at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 )
2024-07-09T00:20:23.1626817Z at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs , ValueTask , CancellationToken )
2024-07-09T00:20:23.1626843Z at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String , Int32 , HttpRequestMessage , Boolean , CancellationToken )
2024-07-09T00:20:23.1626866Z --- End of inner exception stack trace ---
2024-07-09T00:20:23.1626891Z at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String , Int32 , HttpRequestMessage , Boolean , CancellationToken )
2024-07-09T00:20:23.1626917Z at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage , Boolean , CancellationToken )
2024-07-09T00:20:23.1626946Z at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage , Boolean , CancellationToken )
2024-07-09T00:20:23.1626971Z at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage )
2024-07-09T00:20:23.1627045Z at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken )
2024-07-09T00:20:23.1627071Z at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage , Boolean , CancellationToken )
2024-07-09T00:20:23.1627096Z at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage , Boolean , Boolean , CancellationToken )
2024-07-09T00:20:23.1627122Z at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage , Boolean , CancellationToken )
2024-07-09T00:20:23.1627147Z at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage , Boolean , CancellationToken )
2024-07-09T00:20:23.1627177Z at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage , HttpCompletionOption , CancellationTokenSource , Boolean , CancellationTokenSource , CancellationToken )
2024-07-09T00:20:23.1627203Z at Kudu.Services.Web.Tracing.TraceMiddleware.Invoke(HttpContext context) in /tmp/KuduLite/Kudu.Services.Web/Tracing/TraceMiddleware.cs:line 107
2024-07-09T00:20:23.1627229Z at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore(HttpContext context)
2024-07-09T00:20:23.1627256Z at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
No documentation appears to quite say ‘how’ the webjob is running – I.e. what hosts the application or starts it.
Any ideas on how to diagnose beyond this point? Anything clearly wrong with what we have?
Thanks!