Solved

Is it possible to setup a polling procedure to update the status bar?


Userlevel 1
Badge

I was wondering if the following workflow is possible in AIMMS WebUI.

  • User runs a procedure - this could include a web::request_invoke_async() or Execute(), for example
  • User can continue other work
  • Status bar procedure polls for an update and displays status

Currently, I could setup a manual polling procedure that the user can click and run to check the status. 

I imagine one can setup a separate app that gets an ID and details of user request and polls for the status and runs an AIMMS procedure using AIMMS PRO API to update the status bar. (Is it even possible to run a procedure in an active AIMMS session/job through the PRO API?) It is a little too convoluted to setup simple use cases.

icon

Best answer by gdiepen 5 June 2021, 09:18

Do you mean you want to periodically scheduling the running of a procedure?

If so, you could try to use the ScheduleAt function. An example using this function can be found at https://how-to.aimms.com/Articles/404/404-clock.html

 

View original

9 replies

Userlevel 4
Badge +2

HI @Sree,

 

I don’t completely understand what you mean by a “Poll Procedure”. Could you please help me understand?

 

If I read your workflow, would it be correct to assume that you want the Status Bar to update after a certain procedure or action is complete?

 

Just to clarify, the status bar is updated anytime the data in the string parameter used to specify the option is updated. You do not need to wait for any action as such. If the data in the string parameter is updated the Status Bar is also updated, just like any widget in the WebUI.

 

Hope this helps. 

 

Thanks,

Pratap

Userlevel 1
Badge

Hey @Pratap Kumble, assume we are consuming a k-means clustering procedure via a REST API asynchronously -- we submit an async request with data using web::request_invoke_async() and get a response with ID or URL to query the k-means clustering status and results.

After receiving the response for initial request, we could update the string parameter corresponding to the Status Bar to indicate “Submitted Job”. To check if the k-means procedure has finished running, the user would have to run the callback/polling procedure using the ID/URL, correct? I was wondering if there is a way to setup a polling procedure that queries every X seconds for status and indicates it in the Status Bar as “Completed Job”. Does this help clarify?

Thanks,
Sree

 

Userlevel 5
Badge +2

@Sree are you looking for functionality similar to the iteration or time callbacks in MIP solves where  a procedure is executed periodically ?

Userlevel 4
Badge +2

Do you mean you want to periodically scheduling the running of a procedure?

If so, you could try to use the ScheduleAt function. An example using this function can be found at https://how-to.aimms.com/Articles/404/404-clock.html

 

Userlevel 1
Badge

@mohansx, no, I wasn’t referring to MIP callback polling.

@gdiepen, ScheduleAt function is what I was looking for!

Userlevel 5
Badge +2

Hi @sree, yes ! I was asking to confirm my understanding, if you are looking for a similar functionality but with AIMMS procedures instead. The ScheduleAt example would’ve been my next response but Guido beat me to it :D 

 

Take note that StringToCurrent and MomentToString return times in UTC timezone in AIMMS versions over 4.74 - AIMMS Release Notes — AIMMS Documentation

Userlevel 1
Badge

Thanks, @mohansx. I do have couple of quick follow ups after experimenting with ScheduleAt.

My polling procedure is as follows:

Procedure myPollingProcedure {
Body: {

prCheckStatus ;

if spStatus <> "Completed" then

ScheduleAt(MomentToString("%c%y-%m-%d %H:%M:%S", [s], CurrentToString("%c%y-%m-%d %H:%M:%S"), pPollInterval), 'myPollingProcedure') ;

pPollInterval := Min(30, 1.6 * pPollInterval) ;

else
// do other stuff
endif;

}
}

Basically, at the first call to myPollingProcedure, it checks the status and schedules another polling call in some interval. It seems to work fine. I hope scheduling the procedure that contains ScheduleAt() statement is not an issue.

I am not sure of any edge cases. I believe as long as I have ScheduleAt at the end of myPollingProcedure and pPollInterval is not smaller than time to execute statements that follow it (here, pPollInterval assignment), there shouldn’t be an issue. Is that right?

Also, I noticed that AIMMS queues the myPollingProcedure if AIMMS is busy running another procedure. If this is right, it may be worthwhile to update the documentation with this info. I observed this by adding another procedure with Delay(10) to mimic some busy set of operations or control flow and triggering its run before the next scheduled call of myPollingProcedure - AIMMS was waiting until Delay is complete. I am not sure if this behaviour is due to how Delay itself works though.

Userlevel 3
Badge +2

There is only a single thread in AIMMS that can execute procedures in the model, protected by a global AIMMS lock. So if some procedure is activated from within the IDE or the WebUI, and is still running, the scheduled procedure will wait until it can acquire the AIMMS lock, i.e. when the other procedure has completed.

Otherwise, your procedure looks just fine.

Userlevel 5
Badge +2

@sree

 

Marcel already confirmed that your procedure looks good. Both the concerns you raised (scheduling the procedure itself and waiting while something is being executed) have been addressed in the Note at the bottom of the documentation. 

ScheduleAt — AIMMS Function Reference

Can you let me know if something is still missing and we can update the docs ?

Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator