F# class in Azure isolated process function. No job functions found

Tri Nguyen 0 Reputation points
2024-08-02T20:07:15.05+00:00

I could not create an Azure isolated process function if I use F# class semantics, it works with the native F# function semantic. Could someone please take a look? Thank you!

The error is: No job functions found. Try making your job classes and methods public. If you're using binding extensions [...more...]


module Functions

open Microsoft.Azure.Functions.Worker
open Microsoft.Extensions.Logging

// this works, but could not use dependency registered in Host
[<Function("TimerTriggerFunction")>]
let TimeIntervalFunction ([<TimerTrigger("*/10 * * * * *")>] myTimer: TimerInfo) (context: FunctionContext) =
    let logger = context.GetLogger("")
    logger.LogInformation("function is triggered!")


// I need dependency injection but this doesn't work
type TimeIntervalFunctionClass() =
        
    [<Function("TimerTriggerFunction")>] 
    member this.Run ([<TimerTrigger("*/3 * * * * *")>] myTimer: TimerInfo) (context: FunctionContext) =
        context.GetLogger("test").LogInformation("finally")



Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,159 questions
F#
F#
A strongly typed, multi-paradigm programming language developed by the F# Software Foundation, Microsoft, and open contributors.
73 questions
.NET F#
.NET F#
.NET: Microsoft Technologies based on the .NET software framework.F#: A strongly typed, multi-paradigm programming language developed by the F# Software Foundation, Microsoft, and open contributors.
108 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pinaki Ghatak 4,840 Reputation points Microsoft Employee
    2024-08-09T09:09:47.03+00:00

    Hello @Tri Nguyen

    One thing to note is that the Function attribute should be applied to a method, not a class. In your example, you have applied the attribute to the TimeIntervalFunctionClass class, which might be causing the issue. Instead, you should define a public method inside the class and apply the Function attribute to that method. Here's an example of how you can define a public method inside the TimeIntervalFunctionClass class and apply the Function attribute to that method:

    open Microsoft.Azure.Functions.Worker
    open Microsoft.Extensions.Logging
    type TimeIntervalFunctionClass() = [] 
    	member this.Run ([] myTimer: TimerInfo) (context: FunctionContext) = 
    	let logger = context.GetLogger() logger.LogInformation("finally")
    

    In this example, the Run method is marked with the Function attribute and takes a TimerInfo parameter and a FunctionContext parameter. The TimerTrigger attribute is applied to the myTimer parameter to specify the timer trigger schedule. The FunctionContext parameter is used to get a logger instance, which can be used to log information.


    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.