Usage question: Button on_click kicks off longish job, how to handle nicely

Jul 18, 2011 at 8:08 PM

I have a status widget for our app servers that wraps up the process of adding/removing the server from the virtual IP pool.

Works great and was super easy with ShowUI except for the click handler to put the server back into the VIP pool. When that happens I kick off a simple get request to warm up the caches on our application before putting into the VIP to get hammered by production traffic. The basic code on this handler is:

-on_click { $mylabel.content = "warming up server..."; WarmupServer; $mylabel.content = "Server in VIP" }

The 'WarmupServer' call there is just a simple function that uses system.net.webclient to hit our homepage, with internal logic to keep trying on timeout so it doesn't exit until it gets a 200 response code. What actually happens on this handler is the whole UI 'freezes' on the button down effect and nothing is updated until the entire on_click block is done executing. So the functionality is there, but the UI experience is bad.

I can think of some methods to do this nicely, mainly kicking off a background job to do the actual work, but I don't know how to come back and update the label after it's all done. There are a couple other labels that show perf counter information so the user can see some metrics while the server is coming into or out of the VIP pool and I would like those to continue running while the server is primed.

thanks,

Paul

Developer
Jul 22, 2011 at 12:29 AM

Paul, this seems to simulate what you need. Let us know how it goes.

 

UniformGrid -Columns 1 -Show {    
    Label -Margin 5 -Name lbl        

    Button _Go -Margin 5 -On_Click {
         $lbl.Content = "warming up server..."        

         Get-PowerShellDataSource -On_OutputChanged {
             $lbl.Content = "done"
          } -Script {sleep 2; get-date}
    }
}

 

Doug

Jul 22, 2011 at 7:27 PM

That works perfect, thanks.