I am making a Timer trigger Azure Function. I am using a variable here which indicates TimeToCopy. This variable has to be updated after every iteration of the function.
I have:
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, TraceWriter log, myTimerItem elapsedTime)
I want to:
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, TraceWriter log, myTimerItem elapsedTime, double TimeToCopy)
Functions can't reliably keep the state between the calls in memory.
If you can accept the possibility of data loss, you could maintain the value in a static variable.
To save/restore the state reliably you need to add additional binding to your function, e.g. to utilize Table Storage. Something like:
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */2 * * * *")] TimerInfo myTimer,
myTimerItem elapsedTime,
[Table("MyFuncState", "default", "Function1")>] StateEntity entity)
{
// ...
entity.TimeToCopy = entity.TimeToCopy * 2.0;
}
public class StateEntity: TableEntity
{
public double TimeToCopy { get; set; }
}