-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
Invoking "Use-PodeRoutes" as schedule #964
Comments
Hey @RobinBeismann, I just tried a similar, albeit simpler 😂, setup with the following Start-PodeServer -Threads 2 {
Add-PodeEndpoint -Address localhost -Port 8090 -Protocol Http
New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging
Add-PodeSchedule -Name 'test' -Cron '@minutely' -OnStart -ScriptBlock {
Use-PodeRoutes
}
Enable-PodeOpenApi -Path '/docs/openapi' -Title 'Test' -Version 1.0.0.0 -RouteFilter "/route-*"
Enable-PodeOpenApiViewer -Type 'Swagger' -Path '/' -DarkMode -OpenApiUrl "/docs/openapi"
} and $rand = Get-Random -Minimum 1 -Maximum 1000
"adding: /route-file$($rand)" | out-default
Add-PodeRoute -Method Get -Path "/route-file$($rand)" -ScriptBlock {
Write-PodeJsonResponse -Value @{ Message = "I'm from a route file!" }
} For me, For being "published", is it that the routes for you aren't being created at all? Or that they are but not appearing in Swagger? Everything in your above code does look like it's good. |
Hey @Badgerati, I just tried your example also (which in the end does the same as mine) and figured out that it works on PowerShell 7.x but not on PowerShell 5. |
Hey @RobinBeismann, Hmm, that's weird. For me, on both 5 and 7, the Route is added and works, and OpenAPI is updated 🤔 I also tried via NSSM as well, and that worked. Which version of Pode are you using? I've tested the version I'm working on right now, the latest (2.6.2), and 2.6.0. I'm guessing no errors are being thrown and written to the log file? |
Hey @Badgerati, sorry, didn't get around earlier. I just figured out that Pode actually errors out when re-importing a route it already has (which effectively happens for me): |
Hey @RobinBeismann, No worries! :) Aah, yes that would make sense! You're right that there isn't anything in place at the moment to "skip" or "only import new routes". I don't think there's anything we could put onto What we could maybe do is add a |
I actually worked around it with -ErrorAction SilentlyContinue for now, but I could raise a PR with a larger Parameter Set when I find time. |
Hey @Badgerati, I'll close it for now as I probably won't find time to inplement it any time soon. I'll reopen it when I get to it. |
Hey @RobinBeismann, I'm looking at what to put into v2.8.0, and I've had somebody ask about a similar feature on Pode.Web. If you're OK, I can implement the work for the new parameters and function? :) |
Hey @Badgerati, sure, go ahead, I was planning on implementing it already but I'm too exhausted by work at the moment plus currently on a business trip right now. |
Linking with Badgerati/Pode.Web#367 |
I've added a new To Skip over creating a Route that already exists: Start-PodeServer -Thread 2 -Verbose {
Add-PodeEndpoint -Address * -Port 8090 -Protocol Http
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
Write-PodeJsonResponse -Value @{ Result = 1 }
}
Add-PodeRoute -Method Get -Path '/' -IfExists Skip -ScriptBlock {
Write-PodeJsonResponse -Value @{ Result = 2 }
}
} Running the above, and calling The same parameter has also been added onto Use-PodeRoutes -IfExists Skip Furthermore, there's also a new Set-PodeRouteIfExistsPreference -Value Overwrite In the case of the options:
The default value that is used is defined by the following hierarchy:
|
Great. Especially the |
Hey @Badgerati,
we're using Pode on many servers as agent to publish metrics and monitoring data for PRTG (a monitoring solution) so we don't have to put highly privileged credentials into our monitoring system, this works out great for us.
With every Pode Agent we're deploying, we publish all routes with it and have some logic at the start of the route that checks if it shall actually publish this route or not (e.g. check if node is part of a cluster, if so, publish cluster related checks). We then have another script that loops through all hosts, checks if Pode is running and creates the checks in PRTG based on the OpenAPI Definition.
We sometimes face the issue that the Pode Agent starts up too early while other services are not yet initialized (like on Windows the Failover Cluster Manager) and therefor the detection methods fails, resulting in the Route not being published. I tried setting the Pode Agent (ran by NSSM) to delayed start, however that doesn't really solve it in all cases..
So my idea was to just run
Use-PodeRoutes
as Pode schedule, but it doesn't seem to be working during the runtime of Pode.Is it possible to publish routes after the actual startup?
For reference, here is the code:
Example Route under /routes/:
And the
Write-MonitoringResult
Function used above:Thanks already. :)
The text was updated successfully, but these errors were encountered: