Azure Timer trigger is not working in .net 5 isolated function app - azure

Azure Timer trigger is not working in .net 5 isolated function app with the CRON expression to get triggered for every minute.
This is working fine if we run that in local visual studio.
public static class NotificationScheduler
{
[Function("NotificationScheduler")]
public static void Run([TimerTrigger("1-2 * * * * *")] MyInfo myTimer, FunctionContext context)
{
var logger = context.GetLogger("NotificationScheduler");
logger.LogInformation($"Notification Scheduler trigger function executed at: {DateTime.Now}");
//logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");
}
}

As per your ask I have run the function in my local environment and it is working fine for me below is my code for reference make changes accordingly on your environment.
Created Function App in Azure Portal
2. Below is the Code which I have Used in function App
Function1.cs
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
namespace KrishFuncTimerTriggerApp
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 * * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
Then I went to Code+Integration and when I did a Test Run my function app ran every minute as per my logic
As per the below Image .Net isolated function is not supported for editing in Azure Portal.
Also, try to check your SDK version as per this SO and blog if you are using SDK version "6.0.100-preview.7.21379.14" as it is in Preview could be the reason why your function app is not working, if that is the case then try to downgrade your function app.
Also Check the Cron expression link for further details

Related

Azure Function and permanent process

I need to update data from external resource and should do it as often as possible.
I created Azure Function with 1-minute timer and marked it as Singleton:
[Singleton]
[FunctionName("FunctionSync")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
but, seems to me, it's being created queue with waiting instances, so it's not good.
Other way - add queue with one message like semaphore and get message on the start add message on the end of function:
[Singleton]
[FunctionName("FunctionSync")]
public async Task Run(
[QueueTrigger("tablet-management-sync-last-datetime", Connection = "StorageConnectionString")]string myQueueItem,
[Queue("tablet-management-sync-last-datetime", Connection = "StorageConnectionString")]CloudQueue outputQueue,
ILogger log
)
{
but this solution is fragile, if something wrong, message is not added to queue and process is stopped.
Which solution is the best?
Azure Functions that are triggered via a TimerTrigger will only be called once per interval, even if there are multiple instances. So this is something that you don't have to worry about. It does this using Blob Leases, and you can read about it here on the webjob sdk wiki.

TimerTrigger not triggering after start of function app

I am trying to create a very simple TimerTriggered function to prevent my app from getting cold.
The issue is that after deploying the app or after restarting it the TimerTriggered function is never executed. After invoking the function manually the timer starts running as expected.
Some info that might be useful:
My app has a mix of different triggers.
The runtime version used is 2.0.11651.0.
The app service plan has a consumption plan and has to stay that way.
In this case I deploy using Visual Studio
My class looks like the following:
public static class KeepAliveTask
{
[FunctionName("KeepAlive")]
public static void Run([TimerTrigger("0 */4 * * * *", RunOnStartup = true)]TimerInfo timer, TraceWriter log)
{
log.Info("Keeping service alive");
}
}
That's all there is to it. I've been searching but has been unable to find anyone with the same problem. Any suggestions is appreciated.

Scheduled web job confusing about schedule

I have a web job that needs to run every day at 1am.
My settings.job is configured like this:
{
"schedule": "0 0 1 * * *",
"is_singleton": true
}
I have function declared in the Functions.cs
namespace Dsc.Dmp.SddUpgrade.WebJob
{
using System;
using System.IO;
using Microsoft.Azure.WebJobs;
public class Functions
{
public static void TriggerProcess(TextWriter log)
{
log.Write($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
}
I am getting the following logs:
[09/28/2017 12:02:05 > 9957a4: SYS INFO] Status changed to Running
[09/28/2017 12:02:07 > 9957a4: INFO] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
As I read the documentation, some people are using a function signature like this:
public static void TriggerProcess([TimerTrigger("0 0 1 * * *")] TimerInfo timerInfo, TextWriter log)
However, this does not seem logic to me, because a have already configured my web job to by scheduled in the settings.job.
What am I missing here?
If you use a settings.job file to schedule your WebJob, your logic should go in the Program.cs's Main function. You can ignore the Functions.cs file if you go this route. This is great for migrating a console app into a WebJob and scheduling it.
The TimerTrigger is a WebJob extension. It's useful because it's possible to have multiple methods in Functions.cs, each with a separate TimerTrigger that executes on a different schedule. To use these, your WebJob needs to be continuous.
You need to put your logic in Program.cs.
The runtime will run your WebJob by executing the executable, running the Main method in Program.cs.
You seem to be missing the [FunctionName("TriggerProcess")] attribute in the function definition, that´s why you´re getting the "job not found" error.

Azure WebJob won't run locally in debugger

My Azure WebJob used to run in the VS2015 Debugger, but I found it gradually became very intermittent and now won't run at all. It works fine it I deploy it to Azure. The job is marked as RunOnStartUp.
public class Program
{
static void Main()
{
var config = new JobHostConfiguration();
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
}
}
public class TestJob : BaseJob
{
public static async Task StartupJob([TimerTrigger("05:00:00", RunOnStartup = true)] TimerInfo timerInfo, TextWriter log)
{
log.WriteLine("StartupJob");
await Jobs.Test(some params);
log.WriteLine("Sorted");
}
}
What do I need to do to get it running in the Debugger?
I'm guessing you use the same storage account for your job in Azure and when you debug it locally? If that's the case - the TimeTrigger runs as a singleton which means it needs to acquire a lock to be able to execute. If your webjob is already running in Azure your local version, which you're trying to debug, is not able to acquire the lock.
To avoid this just use different storage accounts for "live" Azure version and local local development.
I would also recommend to enable "development settings" - config.UseDevelopmentSettings(); - when you debug locally. If you enable it you'll see the messages "unable to acquire lock for function..." (or something similar).
See Jason Haley's comment in this thread:
(total hack but should work) rename the function while debugging so
the lock listener blob name will be different.
This hack worked for me. Maybe to make it less hacky, you could use the Disable-attribute to create a timer-triggered function that would only be enabled in your local environment:
Create "MyFunction", which handles the logic. This is the one that will run in your Azure app. Note RunOnStartup=false as recommended by the docs.
[FunctionName("MyFunction")]
public async Task RunJob(
[TimerTrigger("0 0 0 * * *", RunOnStartup = false)] TimerInfo timer)
{
//logic here
}
Create "MyFunction-Local" with the Disable attribute and a different method name. All this does is call the method above.
[FunctionName("MyFunction-Local")]
[Disable("Disable_MyFunction")]
public async Task RunJobLocal(
[TimerTrigger("0 0 0 * * *", RunOnStartup = true)] TimerInfo timer)
{
RunJob(timer);
}
In your local app configuration, set {"Disable_MyFunction" = false}, whereas for the app running in Azure, set this to true.

Azure Web Job Timmer trigger exception

I'm trying to run a triggered azure web job using azure-webjobs-sdk-extensions (https://github.com/Azure/azure-webjobs-sdk-extensions)
JobHostConfiguration config = new JobHostConfiguration();
config.UseTimers();
JobHost host = new JobHost(config);
host.Call(typeof(Functions).GetMethod("CronJob"));
host.RunAndBlock();
public static void CronJob([TimerTrigger("0 */5 * * * *")] TimerInfo timer)
{
Console.WriteLine("Cron job fired!");
}
But I'm getting this exception.
Microsoft.Azure.WebJobs.Host System.ObjectDisposedException
I've also tried downloding the sample projects from that gitbug repo, but even with those TimerTrigger examples I'm getting the same exception.
Any ideas?
Thanks
host.Call(typeof(Functions).GetMethod("CronJob"));
Please pay attention that you should provide the CronJob function with a TimerInfo parameter. The CronJob function is invoked automatically by the TimeTrigger you defined. If you want to invoke the CronJob function before you call host.RunAndBlock(), you could refer to the following code:
host.Call(typeof(Functions).GetMethod("CronJob"),new { timerInfo = new TimerInfo(null, null) });
But I'm getting this exception.Microsoft.Azure.WebJobs.Host System.ObjectDisposedException
According to your description, I downloaded the example projects from the GitHub you mentioned and found the versions of related package are old. Please follow this tutorial to create an Azure WebJob project and install the latest version packages of Microsoft.Azure.WebJobs and Microsoft.Azure.WebJobs.Extensions, then test your TimeTrigger function.

Resources