I am looking for a simple Scheduler to execute a task inside my Java web application deployed in Azure cloud. I am evaluating Azure functions with TimerTrigger for my requirement. Here, I am planning to define a Azure function with a callback API URL to invoke my application for executing the task inside my application.
I have some queries in this approach. Can anyone help me If you are familiar with Azure functions please?
1) Is it possible to initiate/reschedule/cancel a Azure TimerTrigger function from a Java application through API at runtime?
2) If yes, Is it possible to pass a call back URL to the timer Trigger?
3) Is there any known drawback in using Azure functions?
Thanks!
TimerTriggers don't have an api to control this (you could try to hack one in by uploading a new function.json with the schedule you want and whether or not the timer is disabled, but I don't recommend that at all).
Instead, I'd suggest using a QueueTrigger. This would allow you to pass the function any data you need in the queue item (the callback url) and you could add items to the queue with a visibility timeout in order to create your schedule. If you need to cancel pending executions, just remove the item(s) from the queue. The function is also more durable - if a queue item fails, it will automatically retry (unlike timers).
3) is way too broad of a question to have an answer.
Related
I have a .NET isolated function with a queue trigger.
When triggering that queue from the storage explorer or from another function using a QueueServiceClient, a new operationId is made up. Thus I cannot correlate it, it seems.
Is it possible to do distributed tracing using W3C standard for Azure Function Queue trigger? I can not find any source on this.
If so, how?
Currently not supported.
Azure Functions team will evaluate this scenario (at some unmentioned point in time) whether or not it can be/will be supported. This has to do with their dependency on the team creating the Azure.Storage.Queues SDK.
https://github.com/Azure/azure-functions-dotnet-worker/issues/1126
Can I achieve Azure function chaining with Durable Functions located in different resource groups & consumption plans?
OR do the functions have to exist in the same resource group/service plan?
If this is not possible, then apart from using service bus, how can functions communicate with each other across different services?
We only support chaining durable functions from within a single function app. This is a technical limitation imposed by the current design of the underlying Azure Storage provider.
However, you could work around this in various ways depending on your needs. For example an orchestration in function app A could send a queue message that triggers a queue-trigger function in function app B which internally starts another orchestration or raises an event to an existing orchestration using the Instance Management APIs.
Durable Function orchestrations also support the async HTTP model, which means that an orchestration in function app A could use HTTP to start an orchestration in function app B, then poll the status endpoint it gets back to get the response when it's available (more info in the HTTP API topic).
But can you comment on why you want to have communication across different function apps? We've received this request before and having more data might help us implement a solution sooner. :)
I have a time trigger azure function deployed on portal. It runs daily at 10:00 am. However, there is now a requirement that function should also be invoked and run on some other time dynamically as well.
I know how to set the trigger in function.json file dynamically via Kudu Api using the steps in answer mentioned here. So using those steps, I can set the trigger for the next minute and run the function.
But this isn't real-time, this seems a workaround. Isn't there any direct way to invoke and manually run azure function directly via apis?
Isn't there any direct way to invoke and manually run azure function directly via apis?
We could trigger the deployed Azure function with REST API. I test it with Time Trigger C# Azure function on my side.
Post https://{FunctionAppName}.azurewebsites.net/admin/functions/{functionName}
Note: I trace it from Azure portal, I don't find any official document mentioned this, if you want to use this API in the product environment, please pay more attention to this.
We need x-functions-key as header. And we could get the function key from the function Application.
We also could use bearer token as authorization, about how to get the authorization for this Rest API please refer to another SO thread.
Updated:
Add the body info.
For the requirement above, my recommendation would be to create two functions that share the same logic (if CSX, either by importing the common implementation using #load or adding a reference to a common assembly, or by having a common type).
You'd have one function using a timer trigger and another using a different trigger type that enables you to invoke the function on demand without a dependency on any of the Kudu or Admin APIs (e.g. HTTP, queue, SB, etc.), the function entry point (your Run method) would just invoke the common logic you bring in.
I have looked through documentation for WebJobs, Functions and Logic Apps in Azure but I cannot find a way to schedule a one-time execution of a process through code. My users need to be able to schedule notifications to go out at a specific time in the future (usually within a few hours or a day from being scheduled). Everything I am reading on those processes is using CRON expressions which is not designed for one-time executions. I realize that I could schedule the job to run on intervals and check the database to see if the rest of the job needs to run, but I would like to avoid running the jobs unnecessarily if possible. Any help is appreciated.
If it is relevant, I am using C#, ASP.NET MVC Core, App Services and a SQL database all hosted in Azure. My plan was to use Logic apps to check the database for a scheduled event and send notifications through Twilio, SendGrid, and iOS/Android push notifications.
One option is to create Azure Service Bus Messages in your App using the ScheduledEnqueueTimeUtc property. This will create the message in the queue, but will only be consumable at that time.
Then a Logic App could be listening to that Service Bus Queue and doing the further processing, e.g. SendGrid, Twilio, etc...
HTH
You could use Azure Queue trigger with deferred visibility. This will keep the message invisible for a specified timeout. This conveniently acts as a timer.
CloudQueue queueOutput; // same queue as trigger listens on
var strjson = JsonConvert.SerializeObject(message); // message is your payload
var cloudMsg = new CloudQueueMessage(strjson);
var delay = TimeSpan.FromHours(1);
queueOutput.AddMessage(cloudMsg, initialVisibilityDelay: delay);
See https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.storage.queue.cloudqueue.addmessage?view=azure-dotnet for more details on this overload of AddMessage.
You can use Azure Automation to schedule tasks programmatically using REST API. Learn about it here.
You can use Azure Event Grid also. Based on this article you can “Extend existing workflows by triggering a Logic App once there is a new record in your database".
Hope this helps.
The other answers are all valid options, but there are some others as well.
For Logic Apps you can build this behavior into the app as described in the Scheduler migration guide. The solution described there is to create a logic app with a http trigger, and pass the desired execution time to that trigger (in post data or query parameters). The 'Delay Until' block can then be used to postpone the execution of the following steps to the time passed to the trigger.
You'd have to change the logic app to support this, but depending on the use case that may not be an issue.
For Azure functions a similar pattern could be achieved using Durable Functions which has support for Timers.
I have an Azure webjob that I want to invoke from an Azure website. I want to pass string parameters from the website to the webjob.
I know I can invoke the webjob as a REST API (https://github.com/projectkudu/kudu/wiki/Web-jobs).
So I can invoke the webjob without any parameters: POST jobs/triggered/myjobname/run
But adding parameters at the end doesn't appear to be working, i.e. jobs/triggered/myjobname/run?myparam1=value1
The information I see on using attributes in Microsoft.WindowsAzure.Jobs for binding doesn't mention my case, just binding to Azure storage items (http://blogs.msdn.com/b/jmstall/archive/2014/01/28/trigger-bindings-and-route-parameters-in-azurejobs.aspx).
Is what I want to do doable? Do I need to do something like create a new item in an Azure storage queue to trigger my webjob?
Thanks.
You can invoke an azure webjob with parameters using the address:
"https://mywebsite.scm.azurewebsites.net/api/triggeredwebjobs/mywebjob/run?arguments=myparameter"
class Program
{
static void Main(string[] args)
{
if (args[0]=="myparameter")
...
}
}
Some info in: https://github.com/projectkudu/kudu/pull/1183
If you want to invoke a WebJob from your Website, the best thing you can do is simply have the WebJob code inside your Website and simply call that code, you can still easily use the WebJob SDK from inside your Website. (for calling a WebJobs SDK method sample: https://web.archive.org/web/20180415074357/http://thenextdoorgeek.com/post/WAWS-WebJob-to-upload-FREB-files-to-Azure-Storage-using-the-WebJobs-SDK).
The reason you wouldn't want to invoke the WebJob from your Website is that the invocation contains a secret you rather not store on your Website (deployment credentials).
If you rather separate WebJob and Website code, the best thing to do is to communicate using a queue, the WebJob listens on the queue and the Website pushes the request to the queue.
Regarding the original question, currently there is no way to pass parameters to the WebJob invoke call.
Took me a while to figure out how to setup the job with arguments using Azure Portal UI (not Post Api/Kudu), so here are the steps:
Create the Webjob on your WebApp
Locate the Web Job in one of the regional collections in the "Scheduler Job Collections", "Scheduler Job" lists
Change the Url in the "Action settings" for your job and append the ?arguments=<myArgument> to it so it ends up looking like:
...scm.azurewebsites.net/api/triggeredwebjobs/<my-job-name>/run?arguments=<myArgument>
The documented way of doing this is to put one or more Azure Queue Messages into a Queue. Each message should contain enough parameter information to allow your webjob to do it's magic.
Within your WebJob use a QueueTriggerAttribute to allow Azure to automatically start the WebJob up when the appropriate queue message is received.
Details here
http://azure.microsoft.com/en-gb/documentation/articles/websites-dotnet-webjobs-sdk-storage-queues-how-to/