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

Azure Function Add-PodeTimer exception even though it's not being used. #1435

Closed
mdg-pnw opened this issue Oct 24, 2024 · 1 comment · Fixed by #1439
Closed

Azure Function Add-PodeTimer exception even though it's not being used. #1435

mdg-pnw opened this issue Oct 24, 2024 · 1 comment · Fixed by #1439
Assignees
Labels
Milestone

Comments

@mdg-pnw
Copy link

mdg-pnw commented Oct 24, 2024

Describe the Bug

I'm following: https://badgerati.github.io/Pode/Hosting/AzureFunctions/#the-server

When I run this, I am getting an exception even though I don't have Add-PodeTimers in my script. It seems like it's not recognizing that it's serverless.

Steps To Reproduce

using namespace System.Net

    param($Request, $TriggerMetadata)

    $endpoint = '/api/isops'

    Start-PodeServer -Request $TriggerMetadata -ServerlessType AzureFunctions -RootPath '../www' {
        # get route that can return data
        Add-PodeRoute -Method Get -Path $endpoint -ScriptBlock {
            Write-PodeJsonResponse -Value @{ 'Data' = 'some random data' }
        }

        # post route to create some data
        Add-PodeRoute -Method Post -Path $endpoint -ScriptBlock {
            New-Thing -Name $WebEvent.Data['Name']
        }

        # put route to update some data
        Add-PodeRoute -Method Put -Path $endpoint -ScriptBlock {
            Update-Thing -Name $WebEvent.Data['Name']
        }
    }

When I run this in VSCode using the Azure Core Tools, I'm getting an exception:

EXCEPTION: The Add-PodeTimer function is not supported in a serverless context.

ScriptName       : [path]]\ManagedDependencies\2410241931327472642.r\Pode\2.11.0\Private\Server.ps1
Line             : throw $_.Exception
Statement        : throw $_.Exception
PositionMessage  : At [path]]\ManagedDependencies\2410241931327472642.r\Pode\2.11.0\Private\Server.ps1:213 char:9
                   +         throw $_.Exception
                   +         ~~~~~~~~~~~~~~~~~~
PSScriptRoot     : [path]]\ManagedDependencies\2410241931327472642.r\Pode\2.11.0\Private
PSCommandPath    : [path]]\ManagedDependencies\2410241931327472642.r\Pode\2.11.0\Private\Server.ps1
CommandOrigin    : Internal
ScriptStackTrace      : at Start-PodeInternalServer, [path]]\ManagedDependencies\2410241931327472642.r\Pode\2.11.0\Private\Server.ps1: line 213
                    at Start-PodeServer<End>, [path]]\ManagedDependencies\2410241931327472642.r\Pode\2.11.0\Public\Core.ps1: line 198
Executed 'Functions.isops' (Failed, Id=a4c589ca-0a50-440e-abdb-9ad49c7f7e62, Duration=1924ms)
                    at <ScriptBlock>, [path]\isops\run.ps1: line 7

Expected Behavior

I'm expecting the page to load.

Platform

  • OS: Windows
  • Browser: FireFox
  • Versions:
    • Pode: Pode v.2.11
    • PowerShell: [e.g. PS7.4.5]

Additional Context

I'm running this in VSCode before uploading it to Azure. I'm not sure if it's checking something on my local system to determine whether it's serverless or not. I would expect that if -ServerlessType is set, then that would be the context it would use.

@Badgerati
Copy link
Owner

Hi @mdg-pnw,

I've managed to reproduce the issue, and committed a fix for it just now.

The error was happening because Pode's caching feature configures a Timer to expire items, when running via Serverless this isn't needed.

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