microsoft / vscode-azurefunctions

Azure Functions extension for VS Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions
MIT License
291 stars 132 forks source link

nchron expression should be validated / type-safe #4167

Closed spotlesscoder closed 3 months ago

spotlesscoder commented 4 months ago

I have written a function in Typescript with a timer trigger. The first function I wrote had the cron expression 0 0 13 * * 1-5 Then I copied the function for another task which I chose the cron expression 0 0 3 * * 1-7 for. I made the wrong assumption that 1-5 would be Monday-Friday and derived that 7 would then be Sunday The problem was that the second function was never run and thus part of the software was never working at all. The weekdays start at 0, not at 1

I would expect that the schedule property from the TimerTriggerOptions interface in @azure/functions library is migrated from type string to a complex type that validates each nchron expression element Pseudocode (incomplete)

export type SecondsOrMinutes = '*' | 0 | 1 | 2 // .... continue until 59
export type Hours = '*' | 0 | 1 // ... continue to 23
export type Weekdays = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 'Mon' | 'Tue' //  ... continue to 'Sun'
export interface WeekdayRange {
  start: Weekdays;
  end: Weekdays;
}

export interface NChronExpression {
   seconds: SecondsOrMinutes;
   minutes: SecondsOrMinutes;
   hours: Hours;
   days: Days;
   months: Months;
   weekDays: '*' | Weekdays[] | WeekdayRange;
}

In addition (or as a replacement if the suggestion above is not feasible), the vscode azure functions extension should validate the nchron strings it finds in the codebase and show invalid expressions in the Problems view. If this is also not possible, it should at least scan functions before the deploy action is done in vscode so invalid nchron expressions can never be deployed

MicroFish91 commented 3 months ago

Thanks for posting this issue. I think this would likely be a better issue for this repository since we rely on the metadata supplied by this source to display and acquire the templates that are used.

If you do end up posting an upstream request, we would appreciate knowing as we would love to track it as well!

spotlesscoder commented 3 months ago

should I create a new issue there or can you transfer it?

alexweininger commented 3 months ago

We can't transfer the issue to that repo, I would just copy and paste this over there 😄

spotlesscoder commented 3 months ago

Issue is now open here: https://github.com/Azure/azure-functions-templates/issues/1538