Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule broken in Develop branch #1395

Closed
mdaneri opened this issue Sep 19, 2024 · 3 comments · Fixed by #1384
Closed

Schedule broken in Develop branch #1395

mdaneri opened this issue Sep 19, 2024 · 3 comments · Fixed by #1384
Labels
Milestone

Comments

@mdaneri
Copy link
Contributor

mdaneri commented Sep 19, 2024

Describe the Bug

The last Pull #1393 has broken the Pode Schedule

Steps To Reproduce

run the examples\Schedule.ps1

Expected Behavior

Name                           Value
----                           -----
Name                           predefined
OnStart                        False
NextTriggerTime
EndTime
StartTime
UsingVariables                 {[SubExpressions, System.Object[]], [NewNameWithDollar, $__using_message], [OldName, $using:message], [Value, Hello, world!]…}
LastTriggerTime                9/19/2024 6:22:00 AM
Script                         …
Count                          2
CronsRaw                       {@minutely}
Arguments                      {}
Limit                          2
Completed                      True
Crons                          {[DayOfMonth, System.Collections.Hashtable], [Random, False], [Minute, System.Collections.Hashtable], [Hour, System.Collections.Hashtable]…}

Last: <something here>
Next: <and here>
Message1:
Message2:
Hello, there!
double cron
Hello, there!

Actual Behavior

Name                           Value
----                           -----
Name                           predefined
OnStart                        False
NextTriggerTime
EndTime
StartTime
UsingVariables                 {[SubExpressions, System.Object[]], [NewNameWithDollar, $__using_message], [OldName, $using:message], [Value, Hello, world!]…}
LastTriggerTime                9/19/2024 6:22:00 AM
Script                         …
Count                          2
CronsRaw                       {@minutely}
Arguments                      {}
Limit                          2
Completed                      True
Crons                          {[DayOfMonth, System.Collections.Hashtable], [Random, False], [Minute, System.Collections.Hashtable], [Hour, System.Collections.Hashtable]…}

Last:
Next:
Message1:
Message2:
Hello, there!
double cron
Hello, there!
@Badgerati
Copy link
Owner

I've found why it worked for myself, and now doesn't in the develop branch.

For Schedules/Tasks the param names in the supplied scriptblock have to be explicitly named, and it's just a by-product of the scriptblock originally running directly as runspaces rather than being invoked via a wrapping scriptblock - and I've left it as is for backwards compatibility support.

This means if you want to use the event object, you need a parameter explicitly called $Event:

Add-PodeSchedule -Name 'predefined' -Cron '@minutely' -Limit 2 -ScriptBlock {
    param($Event, $Message1, $Message2)
    $using:message | Out-Default
    Get-PodeSchedule -Name 'predefined' | Out-Default
    "Last: $($Event.Sender.LastTriggerTime)" | Out-Default
    "Next: $($Event.Sender.NextTriggerTime)" | Out-Default
    "Message1: $($Message1)" | Out-Default
    "Message2: $($Message2)" | Out-Default
}

It seems to stem from #1333, and one we missed, but in there the parameter name was changed:

Add-PodeSchedule -Name 'predefined' -Cron '@minutely' -Limit 2 -ScriptBlock {
    param($TriggeredEvent, $Message1, $Message2)
    $using:message | Out-Default
    Get-PodeSchedule -Name 'predefined' | Out-Default
    "Last: $($TriggeredEvent.Sender.LastTriggerTime)" | Out-Default
    "Next: $($TriggeredEvent.Sender.NextTriggerTime)" | Out-Default
    "Message1: $($Message1)" | Out-Default
    "Message2: $($Message2)" | Out-Default
}

Changing $TriggeredEvent back to $Event fixes it.

I can fix it, though not sure on how to get a test in there for it. I'll have a think.

@mdaneri
Copy link
Contributor Author

mdaneri commented Sep 19, 2024

I can fix it here
It’s my fault because I wanted to remove the reserved variable name $event
I can create a pester test for that

@mdaneri
Copy link
Contributor Author

mdaneri commented Sep 20, 2024

Fixed in #1384
I also created a pester test for that

@Badgerati Badgerati added this to the 2.11.0 milestone Sep 21, 2024
@Badgerati Badgerati linked a pull request Sep 21, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from Backlog to Done in 🚀 Pode Roadmap Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants