This is my Function.Json
{ "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.28", "configurationSource": "attributes", "bindings": [
{
"type": "timerTrigger",
"schedule": "*/5 * * * * *",
"useMonitor": true,
"runOnStartup": false,
"name": "myTimer"
} ], "disabled": false, "scriptFile": "../bin/PullRequest.dll", "entryPoint": "PullRequest.PullRequest.Run" }
This is my actual function:
[FunctionName("PullRequest")]
public static void Run([TimerTrigger("*/5 * * * * *")]TimerInfo myTimer, ILogger log)
{
if (myTimer.IsPastDue)
{
log.LogInformation("Timer is running late!");
}
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
When I tried to run this function on Azure portal then it only run once and stops.
this is the log of the Azure Funciton:
I rerun it and now it only running once.:
Time trigger will automatically execute as per CORN expression i.e. in your case this function will execute every five seconds and If you run it from azure portal it will run only once.
If you want to check timings of last executions you can go to Monitor tab and check timings .
I have executed this locally and its working as expected
Like DavidG said: the Logs you're showing us, show that the function PullRequest ran at least 3 times.
Once where the executing log line isn't visible, so the reason is not clear
Once because the timer fired (#11:30:00)
Once because it was programmatically called via the host APIs (AKA manually)
Your CRON expression */5 * * * * * roughly translates into 'run this every time the number of seconds is divisible by 5'. That wouldn't match with the logs you're providing. Are you sure that's the CRON expression you're using?
Azure Functions uses the NCronTab library to interpret CRON expressions. A CRON expression includes six fields:
{second} {minute} {hour} {day} {month} {day-of-week}
Taken from Timer trigger for Azure Functions - CRON expressions.
EDIT:
Functions running on a Timer Trigger are automatically triggered on the specified timer intervals. To have the Functions actually run, you (of course) need to have something running that executes that trigger. Otherwise: how can they be triggered?
In Azure, the Functions Runtime is responsible for triggering the Function at the right time. Locally, the func.exe tool that starts automatically when you debug the application will do this for you. But if that doesn't run, nothing will happen.
Azure Functions Core Tools lets you develop and test your functions on your local computer from the command prompt or terminal. Your local functions can connect to live Azure services, and you can debug your functions on your local computer using the full Functions runtime.
and
To run a Functions project, run the Functions host. The host enables triggers for all functions in the project.
Taken from Work with Azure Functions Core Tools.
In short: "The host enables triggers. It needs to run to have something that triggers any Function".
Related
Durable functions keep a state in storage, this is what makes them work, but it is very troublesome while debugging and developing. I have a large number of runs which have not completed and that the system tries to run again when I start the process. Some of the runs have erroneous data same which causes exceptions while others have been terminated early as something did not work as expected.
I don't want to run all the old cases when starting my application in debug (running against my local storage account). How can I automatically clear all data so only new functions will trigger?
You can use Azure Core Tools to purge the orchestration instance state.
First you need to make sure that the Azure Core Tools is installed for your particular Azure Function version. You can do this using the NPM package manager. (Note that this is for the Azure Functions Version - V3.)
npm install -g azure-functions-core-tools#3
Then open a command prompt in the root directory of your Azure Functions project. The Azure Core Tools requires the host.json file from your project to identify your orchestration instances.
You can use the following to look at all of the available actions:
func durable
You can then purge the instance history using the following:
func durable purge-history
There is now this VsCode extension, which now also has 'Purge Durable Functions History' feature. Type 'Purge Durable Functions History' in your Command Palette - and there you go. If you're not using VsCode, then the same tool is available as a standalone service, that you can either run locally or deploy into Azure.
You may call the PurgeInstanceHistoryAsync method with one of the following:
An orchestration instance ID
[FunctionName("PurgeInstanceHistory")]
public static Task Run(
[DurableClient] IDurableOrchestrationClient client,
[ManualTrigger] string instanceId)
{
return client.PurgeInstanceHistoryAsync(instanceId);
}
Time interval
[FunctionName("PurgeInstanceHistory")]
public static Task Run(
[DurableClient] IDurableOrchestrationClient client,
[TimerTrigger("0 0 12 * * *")]TimerInfo myTimer)
{
return client.PurgeInstanceHistoryAsync(
DateTime.MinValue,
DateTime.UtcNow.AddDays(-30),
new List<OrchestrationStatus>
{
OrchestrationStatus.Completed
});
}
Reference for code snippets above: https://learn.microsoft.com/en-gb/azure/azure-functions/durable/durable-functions-instance-management#purge-instance-history
For everyone else wondering just how on earth to do this.
Install the Microsoft Azure Storage Explorer
Add a connection to azure storage, but choose Local storage emulator
4. Use the defaults / click next.
At this point, Click on Local & Attached in the Explorer. Click on (Emulator Default Ports) (Key) -> Tables. Delete the task hug history table, and relaunch your application.
From this point, its only a matter of dev time to figure out a way to do it programatically.
I have a webjob in sdk 3.
public class NotificationsFunction
{
public async Task CustomerNotificationFunctionAsync([TimerTrigger("0 * * * * *")]TimerInfo myTimer, ILogger log)
log.LogInformation("Running job");
It used to run correctly.Now, if i try to debug it locally, it just hangs.. It finds the functions but never trigger it:
Now, if i just change the name in :
public class NotificationsFunction
{
public async Task CustomerNotificationFunctionAsyncTest([TimerTrigger("0 * * * * *")]TimerInfo myTimer, ILogger log)
log.LogInformation("Running job");
It runs perfectly:
I have the same exact problem when i deploy to azure.
I have no idea why this happens (and it took me a while to find this problem)...
As anyone ever had this problem? If so, what can I do?
Thanks
From this document:
TimerTrigger uses the Singleton feature of the WebJobs SDK to ensure that only a single instance of your triggered function is running at any given time. When the JobHost starts up, for each of your TimerTrigger functions a blob lease (the Singleton Lock) is taken. This distributed lock ensures that only a single instance of your scheduled function is running at any time. If the blob for that function is not currently leased, the function will acquire the lease and start running on schedule immediately. If the blob lease cannot be acquired, it generally means that another instance of that function is running, so the function is not started in the current host.
The lock ID is based the fully qualified function name.
According to your webjob in sdk 3, you could use AddAzureStorageCoreServices.
var builder = new HostBuilder()
.ConfigureWebJobs(b=>
{
b.AddTimers();
b.AddAzureStorageCoreServices();
})
.Build();
I have the same exact problem when i deploy to azure.
Also note that if you're sharing the same storage account between your local development and production deployment, the Singleton locks (blob leases) will be shared. To get around this, you can either use a separate storage account for local development or perhaps stop the job running in Azure.
Looking for some self triggering function which starts on a time given.
eg. A user has a conference to start at 25/04/2019 05:30
Here the user should get a notification at 25/04/2019 05:25 | 05:29 That the conference is about to start.
Have created a azure function (Time triggred) which triggers every minute and checks if current time is the Conference Time - 4 minutes, Then send a notification regarding conference to be started.
In future will have multiple users and so I do not want the function to run every minute, Is there a way in which at 05:25 or at the conference time the function will execute itself.
So there can be 100 users and they will have different. Just looking for options about how to implement in a better way.
.net core site,
hosted on azure,
Have azure functions running every minute to check the remainder
When user registered on conference you can queue message(with user details) to queue with visibility delay:
queue.AddMessage(message, initialVisibilityDelay: TimeSpanDelay);
For example, user registered at 6 PM, and conference will be next day at 8 PM, so delay time will be 25 hours and and 55 minutes(supposed, that user want to be notified 5 minutes before conference). Then instead of time triggered function you will use queue triggered function, which will send notifications, when messages from queue become visible:
public static void Run([QueueTrigger("notifications")]QueueTrigger message, TraceWriter log)
{
Notifier.Send(message.UserName, message.UserPhoneNumber, message.Email);
}
Moreover, if by some reason your notification handler will be failed, queue messages will not be lost, so you can retry to process them several times.
I recommend you to write a windows service using quartz library to schedule a job. You can pickup the job schedule time from db or somewhere.
Refer: https://www.quartz-scheduler.net
From your description, you already have a TimerTrigger Function however your Timer set the function running every minutes. Actually you could set more precise Timer trigger with CRON expressions.
This is CRON expressions in Azure Function, it includes six fields:{second} {minute} {hour} {day} {month} {day-of-week}. So you could set your Function 0 25,29 5 22 March *.
And after you deploy the function to Azure, it will keep running however it won't execute the Run method until it triggers the Timer.
public static void Run(TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
I have an Azure Function v2, which works locally. When deployed to Azure, everything seems to be in working order (bin folder containing binaries and function name folder with function.json).
However, when I check if they ran (viewing the logs), they aren't there on the monitor tab (No data available), the kudu log stream nor in the general function view:
2018-01-25T10:27:47 Welcome, you are now connected to log-streaming service.
2018-01-25T10:28:47 No new trace in the past 1 min(s).
2018-01-25T10:29:47 No new trace in the past 2 min(s).
Info:
Using a Timer triggered Azure Function v2 calling a:
Durable Function (but "normal" v2 functions do not work as well)
Using TFS to deploy the code to ARM generated resources
function.json:
{
"generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6",
"configurationSource": "attributes",
"bindings": [
{
"type": "timerTrigger",
"schedule": "0 */1 * * * *",
"useMonitor": true,
"runOnStartup": false,
"name": "timerInfo"
}
],
"disabled": false,
"scriptFile": "../bin/Namespace.dll",
"entryPoint": "Namespace.RetrieveRedisMetrics.RunOrchestrator"
}
I have:
Deleted the function in the Azure portal
Renamed the function
Removed the blob storage "azure-webjobs-hosts" and durable-lease (forgot the exact name) containers for the function
The behavior seems similar to https://github.com/Azure/Azure-Functions/issues/618, but there is no resolution or comment on that bug.
I can't share the information app name privately (according to https://github.com/Azure/azure-webjobs-sdk-script/wiki/Sharing-Your-Function-App-name-privately), since... The function isn't logging!
Any other ideas/recommendations?
When trying to publish the function from Visual Studio to skip the TFS continuous delivery factor, I got the following popup:
Apparently, you need to set the FUNCTIONS_EXTENSION_VERSION to beta.
ARM template:
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "beta" // was ~1
}
Azure portal (Azure Function Application Settings):
It also works with Continuous Delivery. Only problem now is that AF v1 (preview currently) takes 3 to 4 times longer than the AF v1. But that is another story..
I created a web job (Console Application) on azure for copying one container blob to another and register on Azure.
It is working properly.
But I want to call the this from c# code not azure scheduler.
How is it possible ?
Like :-
if (Check == true)
{
//Run Web Job Code here
}
Add an "settings.job" file to the root of your job directory. This file must contain an Cron-Expression to start the job (basic cron syntax).
{
"schedule": "0 * * * * *"
}
runs for example, every hour.
For a more detailed description: https://github.com/projectkudu/kudu/wiki/Web-jobs