Refresh browser or restart dashboard?

Hi guys

I wrote an endpoint that reloads functions and pages in memory after it detects changes. It works great, but for pages I need to manually refresh browser to see changes. I can work with this, but I’d like this one last step automated, too.

Solution 1:
Is it possible to refresh/redirect all user sessions from a dashboard endpoint?
Invoke-UDRedirect only works when initiated by a user.

Solution 2:
Worst case scenario, can I restart dashboard from within a dashboard?

Thank you

P.S. Yes I am aware of AutoReload feature in v3, it’s a bit too brutal for my needs so I have it disabled.

Hey, I’m a little confused by what you mean an endpoint that reloads functions and pages in memory after it detects changes - can you elaborate or provide examples on that?

Personally, in my UD 2.9.0 dash, i use -endpoint pages, and simply dot source a file.
So i’ll have this:

page_pagename.ps1 :

New-UDPage -id "pagename" -name "pagename" -AuthorizationPolicy @("admin","policy1","policy2") -Icon link -endpoint {
    . "$psscriptroot\dashboard\pages\test\content_pagename.ps1"
}

content_pagename.ps1 :

new-udhtml -markup "pagecontent goes here"

That way, with it being dotsourced, it loads each time it’s refreshed, bringing any new changes with it.

But I may be misunderstanding what you’re trying to acheive here, as for your potential solutions, I’m not sure about #1. But #2 I actually do at the moment with Restart-WebAppPool “app pool name”, I really only use this when I’m making changes that i need to restart the site from outside of my dot sourced pages. I have a button on an ‘admin’ page which checks for active connections and restarts the app pool if there are none (so i’m not killing anyones session if theyre using the site).

Hi @insomniacc
Sorry if I made it sound confusing, here’s a little explanation:
When dashboard scripts loads, everything is loaded into RAM, hence the “memory” part. The difference from your script is that I have endpoint actively checking for changes in function or page files and this endpoint reloads them in background without taking anything down. I’ll admit it’s an overengineered version of your elegant solution lol. Here’s an example from my v2 to give you an idea.

But that’s beside the point.
Just like your solution, mine requires me to refresh browser page to see the changes. I was hoping I could redirect my user session from within endpoint to the updated page. This way I can see the changes happening on second monitor without ever leaving code to refresh my browser.

Restarting apppool is a great suggestion for plan B, but it’s still like taking a sledgehammer so I am still hoping there is a way to somehow send a browser refresh to all sessions (eventually hitting my session, too)

edit: I just thought of a potential solution:
Endpoint writes request path of the page to cache variable
I could have a dynamic element on page that refreshes every second to see if this variable is not null. If it detects variable changed, it will clear the var and invoke-udredirect to this path, essentially refreshing the page. This would work because it all happens within user’s session.
What do you think? I know this is such a first world problem lol.

Yeah i was going to say something along those lines, you can just push something to cache that you have an endpoint checking.
Then an element on that page which is synced with -broadcast and an invoke-udredirect.

What’s the requirement for this though?
If you just want to have it up on a monitor and see changes etc, couldnt you just use the -CyclePages & CyclePagesInterval parameter of new-uddashboard?

There is also Update-UDDashboard although i’ve never personally used it.

Thanks for your input @insomniacc

If you just want to have it up on a monitor and see changes etc, couldnt you just use the -CyclePages & CyclePagesInterval parameter of new-uddashboard?

The V3 is a bit different (and resources are a bit scarce), the params you suggested no longer exists. Although this one could be replicated with some auto-refresh chrome plugin

There is also Update-UDDashboard although i’ve never personally used it.

Removed :slight_smile:

Yeah i was going to say something along those lines, you can just push something to cache that you have an endpoint checking.
Then an element on that page which is synced with -broadcast and an invoke-udredirect.

Yep, I think this is my best bet for now, I’ll see if I can come up with something later.

What’s the requirement for this though?

I know this whole thing might sound a bit crazy, but the problem with V3 is that you can’t run dashboard in VSCode anymore and you can’t check variables live in terminal below either. The only way to check variables now involves a lot of steps:

  • Set a break point in scrip with Wait-Debugger
  • find processID for dashboard you’re working on
  • open a separate PS terminal because the one integrated in VSCode freezes
  • enter-pshostprocess
  • get-runspace
  • find ID of runspace in breakpoint
  • debug-runspace in breakpoint
  • print the variable to terminal
  • step out couple of times until page finishes loading

Yeah, ain’t nobody got time for that.

So I built an automatic script reloader that is only used in local dev environment, but disabled in production for security reasons using a json config file (Devops). All I want on top of this reloader is browser auto-refresh for faster visual feedback and I’m golden :slight_smile:

Sorry I must have missed that you were using V3, thought you were using V2.
Why not use the console if you want to check variables in your live dash? - I’ve got PSU running V3 and have access to the console in PSU.

The console doesn’t seem to work with $cache: variables for me and copy/paste doesn’t work. I think it’s nice tool for quick lookup when live, but I wouldn’t consider it for development at this stage.

This does work in UD 2.9 both copy/paste and $cache + $session variables.
For me its a really good feature and I use it all the time while developing or just to issue commands to the dash during normal use.
I noticed there are behavioural differences with V3 / PSU admin console and I’m wondering if this is a bug since the console has been shifted from inside the dash to the PSU UI - @adam any ideas?
I’m also noticing the same behaviour when using the console in PSU.

maybe for pages we could implement background refetch data from endpoints, we need to talk about it with adam, and see where it will fit in our backlog

1 Like

Glad to hear it works on v2, that means there’s a good chance this is something devs already know about and might fix in future releases :+1:

image

Just want to let you know this works in 1.3.2 now :slight_smile:
Not sure if bug or feature lol, but when my endpoint detects changes in file hash, it will reload the page on my user session now:

Invoke-UDRedirect -Url $livePageObj.url -Verbose

I am guessing below from changelog relates to this:

Fixed an issue where the broadcast parameter would not work on cmdlets