spring-cloud-function
spring-cloud-function copied to clipboard
Please provide an Azure function sample with TimerTrigger
The project located at https://github.com/spring-cloud/spring-cloud-function/tree/master/spring-cloud-function-samples/function-sample-azure is extremely helpful. Could I ask you to please add a sample on how to use an Azure function with TimerTrigger.
I also fighting to implement TimerTriggered azure function. Sample code would be really helpful. Thank you.
Questions:
- what should AzureSpringBootRequestHandler be abstract of ? <String, String> ? <Void>, <?>, not at all?
- What functional interface shout implementing bean implements ? Function/Consumer/Producer... or runnable if working?
- How to manually trigger this function during dev/testing?
- How to write tests? ...
I managed to implement TimerTriggered function with Function<String, String>... Here is sample for anybody who could be interested.
// BUG1: input parameter does not accept timerInfo string - it is JSON and it tries to deserialize to object which fails )-: // BUG2: input parameter could not be null -> NPE in identifying type of input parameter // PROBLEM: input parameter of AzureSpringBootRequestHandler could not be VOID and than call handlerRequest with null - fails on BUG2
public class MyFunctionHandler extends AzureSpringBootRequestHandler<String, String> {
@FunctionName("MyFunction")
public void run(
@TimerTrigger(name = "CronTrigger", schedule = "0 0 0 * * *") String timerInfo,
final ExecutionContext context) throws Exception {
String result = handleRequest("", context);
}
}
// NOTE input parameter timerInfo is not used
@Component("MyFunction")
public class MyFunction implements Function<String, String> {
@Override
public String apply(String empty) {
return "anything";
}
}
Requests:
###
POST http://localhost:8080/MyFunction
Content-Type: text/plain
###
POST http://localhost:7071/admin/functions/MyFunction
Content-Type: application/json
{
}