Azure Webjob Queue trigger not working - azure

My queue trigger works only when the azure queue is being populated with messages and when simultaneously the webjob is running.(in my local dev environment)
But when i start the webjob (having the queue trigger) first , and then after a few seconds put new messages into the queue, the trigger doesn't detect them. Its like the trigger stops listening once there is no new messages. is this a normal behaviour for the trigger ? If not how do i resolve this issue ?
Main method :
static void Main()
{
InitializeQueue();
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost();
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
Function with queue trigger
public static void ProcessQueueMessage([QueueTrigger("myqueue")] CloudQueueMessage message)
{
Debug.Write(message.AsString);
}

For on-demand WebJobs, Azure has a configuration setting called WEBJOBS_IDLE_TIMEOUT that is denoted in seconds and defaults to two minutes.
If your on-demand WebJob isn’t triggered within the WEBJOBS_IDLE_TIMEOUT interval, Azure will kill your WebJob.
I recommend setting your Web App’s WEBJOBS_IDLE_TIMEOUT variable to a healthy number of seconds to prevent this from happening.
You can set this variable on the Web App’s Application Settings screen by adding it to the App Settings section of the Web App instance that is hosting your WebJob.

Related

HTTP Request/Response on Azure WebJob

I'm looking to create a WebJob that takes in a request and sends a response, much like an Azure Function with an HTTP trigger. I want to use a WebJob instead because I need to use wkhtmltopdf, which cannot run on a Consumption plan, and we are already paying for an App Service that it can run on.
I know how to run the WebJob using an HTTP POST from this link: https://stackoverflow.com/a/42824776/443044.
What I cannot figure out is how to create the WebJob itself.
Here is my Program class:
public class Program
{
[NoAutomaticTrigger]
public static void TestMethod(TextWriter logger)
{
logger.WriteLine("TEST: " + req.Content.ToString());
}
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
static void Main()
{
var config = new JobHostConfiguration();
...
var host = new JobHost(config);
host.Call(typeof(Program).GetMethod("TestMethod"), null);
}
}
The program throws an exception if I try to give TestMethod the return type of HttpResponseMessage or a parameter of type HttpRequestMessage.
How can I achieve the request/response functionality like with an Azure Function?
we are already paying for an App Service -> You do realize you can host your azure function on an existing app plan as well? learn.microsoft.com/en-us/azure/azure-functions/….
But AFAIK webjobs do not have capabilities to respond to requests.

Azure Timer Trigger webjob: Function is being recognised but not being triggered

I have an Azure timer trigger webjob, deployed in two different environments with two different storage accounts. The webjobs have been deployed for about two months now, and were running as expected for quite some time. However, for about a week now, the function is being recognised but not being executed.
Here is how the logs look:
Found the following functions:
ADFSchedulerWebJob.Functions.ProcessTimerMessage
Job host started
Nothing happens after the Job host is started, i.e., the function ProcessTimerMessage is not called/executed. This is how the function looks:
public static void ProcessTimerMessage([TimerTrigger("0 */2 * * * *", RunOnStartup = true)] TimerInfo info, TextWriter log)
{
//function logic
}
This is how the Main method looks like:
static void Main()
{
JobHostConfiguration config = new JobHostConfiguration();
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
}
The same is occurring even when I try to debug the webjob locally. What could be the possible reason/resolution?
Any help appreciated.
What could be the possible reason/resolution?
As Thoms mentioned that it seems that the same storage account is used for another webjob or others.
We could debug it with following ways:
1.Try to use another storage account
2.Check the webjob log from the storage
We could get more info about Webjob log from the blog.

What happened when using same Storage account for multiple Azure WebJobs (dev/live)?

In my small job, I just use same Storage Account for AzureWebJobsDashboard and AzureWebJobsStorage configs.
But what happened when we use same connection string for local Debugging and Published job equally? Are they treated in isolated manner? Or do they have any conflict issue?
I looked into blobs of published job and found azure-webjobs-dashboad/functions/instances or azure-webjobs-dashboad/functions/recent/by-job-run/{jobname}, or azure-webjobs-hosts/output-logs directories; they have no discriminator specified among jobs while some other directories have GUID with job name.
Note that my job will be run in continuous.
Or do they have any conflict issue?
No, there is no conflict issue. Base on my experience, it is not recommended to local debugging while Published job is running in the azure with the same connection string. Take Azure Storage queue for example, we can't control which queue should be executed in the local or in the azure. If we try to use debug it locally, please have a try to stop the continue WebJob from Azure Portal.
If we try to know WebJob is executed from which instance we could log the instance info in the code with the environment variable WEBSITE_INSTANCE_ID.The following is the code sample:
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
string instance = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
string newMsg = $"WEBSITE_INSTANCE_ID:{instance}, timestamp:{DateTime.Now}, Message:{message}";
log.WriteLine(newMsg);
Console.WriteLine(newMsg);
}
More info please refer to how to use azure queue storage with the WebJob SDK. The following is snipped from the document.
If your web app runs on multiple instances, a continuous WebJob runs on each machine, and each machine will wait for triggers and attempt to run functions. The WebJobs SDK queue trigger automatically prevents a function from processing a queue message multiple times; functions do not have to be written to be idempotent
Update :
About timer trigger we could find more explanation of timer trigger in the WebJob from the GitHub document.So if you want to debug locally, please have a try to stop the WebJob from the azure portal.
only a single instance of a particular timer function will be running across all instances (you don't want multiple instances to process the same timer event).

Azure Storage Queue WebJob never stops

I have an WebApp running on Azure, the purpose of the WebApp is to process jobs from an Azure Storage Queue. It is set to Always On. The problem is that when I stop the WebApp in the Azure management portal the job doesn't actually stop.
I instantiated the job like:
class Program
{
static void Main()
{
string connectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;
JobHostConfiguration config = new JobHostConfiguration(connectionString);
config.NameResolver = new QueueNameResolver();
JobHost host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
}
The function that processes the queue is:
public static void ProcessQueueMessage([QueueTrigger("%apilogeventqueue%")] CloudQueueMessage messageEnvelope, TextWriter log, CancellationToken token)
{
}
I have trace logging so I can see the job never actually gets stopped.
WebJobs run under a special SCM (source control management) site of the host WebApp. When you stop the WebApp in the portal this SCM portion of the WebApp continues to run, because it supplies management capabilities to the WebApp that need to be available even when stopped.
To stop a WebJob from running, you can disable it in the portal UI by right clicking on the job in the jobs list and choosing "Stop". You can also stop ALL jobs in the WebApp by setting the WEBJOBS_STOPPED app setting to 1 (details here).

Azure continuous webjob (blob) triggering only once

I have an Azure webjob that has a few blob triggered functions within. I uploaded this to Azure via the Add job dialog on the portal and set it to "Run Continuously" The behavior expected was that any time a blob is added /modified to the containers specified in the blob trigger the corresponding function be called. This however does not happen.
The only way to trigger the functions (after having uploaded blobs) is to Stop the web job and restart it again.
Every time I restart the job the functions
seem to be triggered and triggered only once. Any subsequent blob updates don’t seem to trigger them again.
On the portal however the WebJob shows as 'Running' however no functions get triggered after the initial trigger.
The main function for this web job looks like this :
static void Main()
{
var host = new JobHost();
host.RunAndBlock();
}
What could be the issue ?
The trigger functions are standard blob triggered functions and work for the first time - hence I am not yet sharing that code.
UPDATE
The function signature looks like this
public static void UpdateData([BlobTrigger("inputcontainer/{env}-update-{name}")] Stream input, string name, string env, TextWriter logger)
public static void DeleteData([BlobTrigger("inputcontainer/{env}-delete-{name}")] Stream input, string name, string env, TextWriter logger)
Because of how the blob triggers are implemented, it can take up to 10 minutes for the function to be invoked.
If the function is not triggered even after 10 minutes, please share with us the function signature and the names of blobs that you are uploading.

Resources