Schedled endpoints not firing

Hey everyone

I have the below code in my dashboard config,

Snippet from dashboard init script and the second section is from a downloads page.

$cache:yestedayssentmail and $cache:yesterdaysreceivedmail both populate properly every 24 hours, as they display their data on a separate page totally fine, however in the endpoint $exportcsvs I’m trying to output them to csv followed by grabbing them in $UpdateDownloadLinks to display them on the downloads page.

  1. My first issue is that for some reason $exportcsvs doesn’t seem to fire off and export the data to csv’s, but if i grab the 3 lines that are inside that endpoint and paste them into the active powershell console thats running the dashbaord the files export totally fine.

  2. my second issue is that $UpdateDownloadLinks doesn’t seem to fire off either. But again if i grab the 2 lines inside the endpoint and run them manually they pick up the csv’s as I’d have expected.

I’ve double and triple checked that all my endpoints are initialized and they definitely are, the other endpoints I have are firing off fine but i can’t seem to figure out where i’ve went wrong.

Code from my dashboard init file

    $fiveminutescheule = New-UDEndpointSchedule -Every 5 -Minute
    $exportcsvschedule = New-UDEndpointSchedule -Cron '0 30 10 ? * *'
    $downloads = Publish-UDFolder -Path "$PSScriptRoot\downloads" -RequestPath "/files"

    $exportcsvs = New-UDEndpoint -Schedule $exportcsvschedule -Endpoint {
        $yesterdaysdate = (get-date).AddDays(-1).tostring("ddMMyyyy")
        $Cache:YesterdaysSentMail | Export-Csv -Path .\downloads\"Sent - $yesterdaysdate.csv"
        $Cache:YesterdaysReceivedMail | Export-Csv -Path .\downloads\"Received - $yesterdaysdate.csv"
    }

    $UpdateDownloadLinks = New-UDEndpoint -Schedule $fiveminutescheule -Endpoint {
        $Cache:sentdownloadlinks = get-childitem ".\downloads" -recurse -Filter "Sent*.csv"
        $Cache:receiveddownloadlinks = get-childitem ".\downloads" -recurse -Filter "Received*.csv"
    }

Code from downloads page

New-UDPage -Name "Downloads" -Icon home -Endpoint { 
    New-UDCollapsible -Items {
        New-UDCollapsibleItem -Title "Sent Emails" -Icon arrow_right -Content {
            foreach ($link in $Cache:sentdownloadlinks) {
                $sentfilename = $link | % { $_.BaseName }
                $sentdownloadlink = "https://localhost/files/" + $sentfilename + ".csv"
                New-UDElement -Tag 'a' -Attributes @{
                    'href'     = $sentdownloadlink
                    'download' = $sentfilename
                } -Content {
                    "$sentfilename.csv"
                }
                New-UDElement -Tag 'br'
            }
        }
        New-UDCollapsibleItem -Title "Received Emails" -Icon arrow_right -Content {
            foreach ($link in $Cache:receiveddownloadlinks) {
                $receivedfilename = $link | % { $_.BaseName }
                $receiveddownloadlink = "https://localhost/files/" + $receivedfilename + ".csv"
                New-UDElement -Tag 'a' -Attributes @{
                    'href'     = $receiveddownloadlink
                    'download' = $receivedfilename
                } -Content {
                    "$receivedfilename.csv"
                }
                New-UDElement -Tag 'br'
            }
        }
    }
}

Have these scheduled endpoints ever worked? if yes, try troubleshooting one at once, comment one of them out, try it, then swap it around.
if no, how are you passing them into your start-uddashboard -endpoint parameter? can we see that code?
For mine, I just add them all to an array:

$endpoints = @()
$endpoints += new-udendpoint -id "endpoint1".....
$endpoints += new-udendpoint -id "endpoint2".....
Start-UDDashboard -endpoint $endpoints ....

If I type $endpoints in my dashboard console I can then see them with all their properties.
Are yours showing in the same way from the admin console when you type the variable name?

Hey @insomniacc thanks for the response! :slight_smile:

So no, neither of them have ever worked. I only added them in yesterday, but all the other scheduled endpoints I have work fine.

Here’s my start-uddashboard code

function Start-Dashboard {
    [CmdletBinding()]
    $ConfigurationFile = Get-Content (Join-Path $PSScriptRoot dbconfig.json) | ConvertFrom-Json

    . (Join-Path $PSScriptRoot "themes\*.ps1")

    $PageFolder = Get-ChildItem (Join-Path $PSScriptRoot pages)

    $Pages = Foreach ($Page in $PageFolder) {
        . $Page.Fullname
    }

    $Initialization = New-UDEndpointInitialization -Module @(Get-ChildItem (Join-Path $PSScriptRoot modules) -Filter *.ps1 -Recurse)

    $Cache:Mailboxes = Get-Content(Join-Path $PSScriptRoot ".\modules\mailboxes.txt")
    $Cache:Servers = Get-Content(Join-Path $PSScriptRoot ".\modules\servers.txt")
    $dailyschedule = New-UDEndpointSchedule -Every 1 -Day
    $hourlyschedule = New-UDEndpointSchedule -Every 1 -Hour
    $fiveminutescheule = New-UDEndpointSchedule -Every 5 -Minute
    $exportcsvschedule = New-UDEndpointSchedule -Cron '0 30 10 ? * *'
    $downloads = Publish-UDFolder -Path "$PSScriptRoot\downloads" -RequestPath "/files"

    $YesterdaysEndpoint = New-UDEndpoint -Schedule $dailyschedule -Endpoint {
        Connect-Exchange -SessionName "YesterdaysEndpoint"
        $Cache:YesterdaysSentMail = @()
        $Cache:YesterdaysSentMail = Search-YesterdaysSentMail -Mailboxes $Cache:Mailboxes -Servers $Cache:Servers
        $Cache:YesterdaysReceivedMail = @()
        $Cache:YesterdaysReceivedMail = Search-YesterdaysReceivedMail -Mailboxes $Cache:Mailboxes -Servers $Cache:Servers
    }

    $TodaysEndpoint = New-UDEndpoint -Schedule $hourlyschedule -Endpoint {
        Connect-Exchange -SessionName "TodaysEndpoint"
        $Cache:TodaysReceivedMail = @()
        $Cache:TodaysSentMail = @()
        $Cache:TodaysReceivedMail = Search-TodaysReceivedMail -Mailboxes $Cache:Mailboxes -Servers $Cache:Servers
        $Cache:TodaysSentMail = Search-TodaysSentMail -Mailboxes $Cache:Mailboxes -Servers $Cache:Servers
    }

    $exportcsvs = New-UDEndpoint -Schedule $exportcsvschedule -Endpoint {
        $yesterdaysdate = (get-date).AddDays(-1).tostring("ddMMyyyy")
        $Cache:YesterdaysSentMail | Export-Csv -Path .\downloads\"Sent - $yesterdaysdate.csv"
        $Cache:YesterdaysReceivedMail | Export-Csv -Path .\downloads\"Received - $yesterdaysdate.csv"
    }

    $UpdateDownloadLinks = New-UDEndpoint -Schedule $fiveminutescheule -Endpoint {
        $Cache:sentdownloadlinks = get-childitem ".\downloads" -recurse -Filter "Sent*.csv"
        $Cache:receiveddownloadlinks = get-childitem ".\downloads" -recurse -Filter "Received*.csv"
    }

    $Navigation = New-UDSideNav -Content {
        New-UDSideNavItem -Text "Home" -PageName "Home" -Icon home
        New-UDSideNavItem -Text "Downloads" -PageName "Downloads" -Icon Download
    }

    $DashboardParams = @{
        Title                  = $ConfigurationFile.dashboard.title
        Theme                  = $DarkTheme
        Pages                  = $Pages
        EndpointInitialization = $Initialization
        Navigation             = $Navigation
    }

    $Dashboard = New-UDDashboard @DashboardParams
    $Certificate = ( Get-ChildItem -Path cert:\LocalMachine\My\ )
    $EndPoints = @(      
        $YesterdaysEndpoint
        $TodaysEndpoint
        $UpdateDownloadLinks
        $exportcsvs
    )

    $PublishedFolders = @(
        $downloads
    )

    Start-UDDashboard -Port $ConfigurationFile.dashboard.port -HttpsPort $ConfigurationFile.dashboard.httpsport -Dashboard $Dashboard -Certificate $Certificate -Endpoint $EndPoints -PublishedFolder $PublishedFolders -AutoReload
}

Break it down to its basic, then see if it runs:

Comment out your code inside the endpoint and just doing something simple like:
$cache:mytestvar = “just testing”

And then inspect your $cache variable in your admin console to see if it’s been populated when expected.

If it does, the likley hood is theres something inside your endpoint breaking it.
If it doesn’t, something else is probably going on outside of your endpoint scriptblock.

Stab in the dark, but have you tried providing literal paths to ensure there’s no issue with the filepath under the scope of your endpoint?

Hey

thanks for coming back to me on this.

I tried enabling the admin console, but the version of UD that I’m running doesn’t seem to recognize -AdminMode, is that specific to a certain version?
** EDIT ** from looking at the features page, AdminMode is a feature in the licensed version, although that page does seem broken

I tried using absolute paths, similar to the rest of my UD but had no joy with that either.

Apologies, yes admin mode is not part of the community edition. (at least as far as I’m aware on 2.9 and less.)

I was basically trying to get at an easy way to inspect if the endpoint is running or not. Instead of using the admin console, why not write something to file “test” | out-file -path “c:\temp\test.txt” -force
Stick the same line into another scheduled endpoint you know is working, test it, then take it out and stick it in your ‘broken’ endpoint. Just try to identify if the endpoint is self is actually triggering or not.

Ah ok I follow :slight_smile:

Looking at picking up the licensed edition anyway, feel it would be useful! I’ll try out your suggestion and let you know :slight_smile:

So it seems like the endpoint using the cron schedule is firing fine as its outputting the txt file to c:\temp as expected, but the one using -every 5 -minutes isn’t firing at all.

So it looks like I have 1 duff scheduled endpoint and my export CSV stuff just isn’t working at all :laughing:

Hmmmm, I think I may have had something similar in the past… I seem to remember having problems with my scheduled endpoints when I mixed the schedule types, e.g some using cron, others just using params.
Try use all one type, either just -every x -minutes switches or all using cron but just dont mix them. I have a feeling that may work. If it does I’ll do a bit more testing to double check and log it as an issue as it could be a bug.

Will do! can you do set times with -every ? The main reason i did cron on that one was because it was only needed once per day but ideally at a set time

I don’t think so, I think if you do -every 1 -day for example, it will just run as soon as the app pool starts and then run the next day from there, at least that’s how i understand it.
Either way, let me know how you get on, if it turns out to be a bug it’ll need fixing :slight_smile:

sure thing :slight_smile: I’ve just changed the cron endpoint to use the $fiveminuteschedule, will let you know shortly :slight_smile:

So whats really interesting is one of these works and 1 doesn’t.

$fiveminutescheule = New-UDEndpointSchedule -Every 5 -Minute

This endpoint seems to work totally fine using the above schedule

 $exportcsvs = New-UDEndpoint -Schedule $fiveminutescheule -Endpoint {
        "test" | out-file -path "c:\temp\testexportcsvs.txt" -force
    }

This one doesn’t seem to work using the same schedule as the one that works.

$UpdateDownloadLinks = New-UDEndpoint -Schedule $fiveminutescheule -Endpoint {
        "test" | out-file -path "c:\temp\testUpdateDownloadLinks.txt" -force
    }

and $YesterdaysEndpoint and $TodaysEndpoint are still working too?
Just trying to eliminate it only running the last endpoint in your endpoint array, but yeah thats weird.

Yeah they’re both working fine too

its not even the last endpoint in my array that isn’t working, its the 2nd last one

$EndPoints = @(
    
    $YesterdaysEndpoint
    $TodaysEndpoint
    $UpdateDownloadLinks
    $exportcsvs
)

Oh i updated from not v2.9 to be v2.9, not sure if that makes a difference :slight_smile:

Just reading through this post for a good read…and I always use commas to seperate the array you passing…I hope this helps :slight_smile:

Yeah, I noticed that although still odd that some trigger while others don’t from the same array.
I tested an array in this way and it seemed fine.
I was planning to replicate his code fully and test but haven’t got round to it yet, maybe tomorrow, I need to spin up the new version of universal anyway :slight_smile:

Hey

thanks for that, I’ll keep it in mind :slight_smile:

I’ve toyed about with it a bit over the last couple days but so far haven’t had any luck.

waiting on my license key coming through and I can check it out in admin mode and see whats going on