Azure-webjobs-sdk: Add support for 'ScheduleType' on attribute 'TimerTriggerAttribute'

Created on 15 Feb 2018  路  6Comments  路  Source: Azure/azure-webjobs-sdk

_From @ahmelsayed on February 7, 2018 0:57_

_From @eloekset on October 25, 2017 13:34_

Tooling Information

  • Visual Studio: 15.4.1
  • Azure Functions SDK: 1.0.6
  • VSTS Visual Studio Version: Latest
  • VSTS Visual Studio Build Task Version: 1.*

Issue Description

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.

  1. Could it be a miss that this check breaks the build?

  2. ..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_

Feature

Most helpful comment

Has a solution been found for this issue? I also need to create a custom Timer Schedule for my Azure Functions.

All 6 comments

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.b__1_2(Attribute a)
at System.Linq.Utilities.<>c__DisplayClass2_03.<CombineSelectors>b__0(TSource x) at System.Linq.Utilities.<>c__DisplayClass2_03.b__0(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.ToList() at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at MakeFunctionJson.ParameterInfoExtensions.ToFunctionJsonBindings(ParameterDefinition parameterInfo)
at MakeFunctionJson.MethodInfoExtensions.<>c.b__6_1(ParameterDefinition p)
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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hajekj picture hajekj  路  3Comments

kamranayub picture kamranayub  路  4Comments

mathewc picture mathewc  路  5Comments

christopheranderson picture christopheranderson  路  3Comments

mathewc picture mathewc  路  4Comments