_From @ahmelsayed on February 7, 2018 0:57_
_From @eloekset on October 25, 2017 13:34_
I want to schedule a task based on the outcome of the previous run. I'm accessing an API from an Azure Function, and that API fails if I try to send multiple requests at the same time. To overcome this, I've written a custom TimerSchedule to slow down the Azure Function when it fails.
This is the Run method signature of my function:
Run([TimerTrigger(typeof(CustomTriggers.CustomerInfoSyncIntervalTrigger))]TimerInfo myTimer, TraceWriter log)
When debugging the function locally in Visual Studio, it runs and the GetNextOccurrence method in my custom trigger gets executed. But when I build the project in VSTS, I get a build error that says:
2017-10-25T12:59:49.2234014Z ##[error]C:\Users\buildguest\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): Error : System.NotImplementedException: Property 'ScheduleType' on attribute 'TimerTriggerAttribute' is not supported in Azure Functions.
at MakeFunctionJson.AttributeExtensions.CheckIfPropertyIsSupported(String attributeName, PropertyInfo property)
at MakeFunctionJson.AttributeExtensions.ToJObject(Attribute attribute)
at System.Linq.Enumerable.<>c__DisplayClass7_0`3.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.<SelectManyIterator>d__16`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at MakeFunctionJson.MethodInfoExtensions.ToFunctionJson(MethodInfo method, String assemblyPath)
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
Error generating functions metadata
This check looks like it's intended on build, but still it runs locally when debugging in Visual Studio.
Could it be a miss that this check breaks the build?
..if not, could custom TimerTriggers be supported by Azure Functions in a future version?
_Copied from original issue: Azure/azure-functions-vs-build-sdk#130_
_Copied from original issue: Azure/azure-functions-host#2388_
Please consider adding ExecutionContext as an injected value to the custom ScheduleType; this will allow the type to use information about the function and load resources from the FunctionDirectory/FunctionAppDirectory
@grahamehorner Could you explain more on how to use custom ScheduleTypes? I'm getting the same build error as the OP. My code is as follows
public static void Run([TimerTrigger(typeof(RandomHours))]TimerInfo myTimer, TraceWriter log, ExecutionContext context) {}
public class RandomHours : CronSeriesSchedule
{
public RedmondHours(ExecutionContext context) : base("30 */2 * * *", "0 */4 * * *")
{
Directory.SetCurrentDirectory(context.FunctionAppDirectory);
}
}
public class CronSeriesSchedule : TimerSchedule
{
private List<CronSchedule> _schedules = new List<CronSchedule>();
public CronSeriesSchedule(params string[] expressions)
{
_schedules = expressions.Select(s => new CronSchedule(CrontabSchedule.TryParse(s))).ToList();
}
public override DateTime GetNextOccurrence(DateTime now)
{
return _schedules.Select(s => s.GetNextOccurrence(now)).Min();
}
}
Has a solution been found for this issue? I also need to create a custom Timer Schedule for my Azure Functions.
I also have a use case where the timer schedule is stored in a separate system/data storage and would like to be able to control the schedule from there / via the UI without having to tweak the function app appsettings.
Function V3 with the following
```c#
[FunctionName("func")]
public async Task RunAsync([TimerTrigger(typeof(CustomSchedule))] TimerInfo timeInfo)
{}
class CustomSchedule: TimerSchedule
{
public override DateTime GetNextOccurrence(DateTime now)
{
return now.AddSeconds(10);
}
}
is throwing
Microsoft.NET.Sdk.Functions.Build.targets(32, 5): System.NotImplementedException: Property 'ScheduleType' on attribute 'TimerTriggerAttribute' is not supported in Azure Functions.
at MakeFunctionJson.AttributeExtensions.CheckIfPropertyIsSupported(String attributeName, PropertyInfo property)
at MakeFunctionJson.AttributeExtensions.ToJObject(Attribute attribute)
at MakeFunctionJson.ParameterInfoExtensions.<>c.
at System.Linq.Utilities.<>c__DisplayClass2_03.<CombineSelectors>b__0(TSource x)
at System.Linq.Utilities.<>c__DisplayClass2_03.
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at MakeFunctionJson.ParameterInfoExtensions.ToFunctionJsonBindings(ParameterDefinition parameterInfo)
at MakeFunctionJson.MethodInfoExtensions.<>c.
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator2.ToArray()
at System.Linq.Enumerable.ToArrayTSource+MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToListTSource
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
Error generating functions metadata
```
I am also interested in this, can we get any sort of update?
Most helpful comment
Has a solution been found for this issue? I also need to create a custom Timer Schedule for my Azure Functions.