145
Views
15
Comments
Solved
BPT for asynchronous calculations?
Question

Hi

I am looking at my options to optimise the home screen of an application and I would like to know if BPT is a possible solution for my use case.

The home screen has links to 20 screens ('milestones'). Beside each Milestone is shown total of the number of items that are in that screen and these totals are calculated via a large SQL query in the preparation. This makes the screen a bit slow. 

I am wondering if I can split this SQL to individual queries and run them asynchronously. I understand the only way this is possible in Web App is via BPT..

Does it make sense to create a BPT process just for calculating these totals for a home screen? We have not implemented BPT in our application anywhere else.


e.g.

- Preparation creates a record containing some required session parameters 

- Creation of new record in this entity starts a BPT process

- asynchronous activities to calculate totals for each 'Milestone' and save to db

- somehow refresh screen to display the Milestone totals from db (how can I notify the screen??)


So is this possible, or is there a better way?


mvp_badge
MVP
Rank: #171
Solution

Craig Duggan wrote:

Daniël Kuhlmann wrote:

Yes it is perfectly possible to do this with BPT if the SQL finishes within the max time out of bpt which is 5 minutes. If SQL take longer than 5 minute you need to use timers.

You can do a auto refresh of your screen using JavaScript interval to refresh the calculated totals on your screen. Alternatively you could use a notification system like pusher to have your screen updated when a total is calculated.

Also the web event extensibility component in the forge does also work I think on OS10

Thanks - thats good to hear. Yes we are talking seconds, not minutes, so it wont get near to the BPT max time out.

I will look into the two suggestions you have provided for notifying the screen.

Events are new to OS11 so I wouldnt have thought the component would work with OS10.


If you are just talking seconds, you could always create a screen action to perform the calculations and AJAX Refresh the appropriate components.  Then, add JavaScript when your screen loads to immediately fire the AJAX call.  It's not ideal to call AJAX the moment your screen loads, but for this use case it seems like the most straight forward way.

Staff
Rank: #175

Another possible approach would be to use the Web Event JavaScript Extensibility component from the Forge.

Using that, you could create a small Web Block to add to your home screen, which would be responsible for calling one or more screen actions to perform the queries. The Web Event JavaScript Extensibility component would allow you to use JavaScript on the home screen (perhaps using jQuery's .ready event) to call an event on the web block, triggering the call to the screen action(s). Then you can just use AJAX refresh of the UI components with the updated values.


Rank: #50

BPT process run on a different thread than the web session. It would not have access to any of the session variables. As far as how to notifiy the user, you have a number of options:

  • send an email to the person that started the process that the calculations are complete
  • udpate a status flag on some table. That would drive behavior on a page

I am sure that there are other ways, but those are the 1st two that come to mind.

Rank: #50

The email was letting the user that the calculations were complete. In either case, you would need to store the results somewhere. You could email the results to the user, or just store the results that its complete and the page then would view the values

mvp_badge
MVP
Rank: #18

Yes it is perfectly possible to do this with BPT if the SQL finishes within the max time out of bpt which is 5 minutes. If SQL take longer than 5 minute you need to use timers.

You can do a auto refresh of your screen using JavaScript interval to refresh the calculated totals on your screen. Alternatively you could use a notification system like pusher to have your screen updated when a total is calculated.

Also the web event extensibility component in the forge does also work I think on OS10

Rank: #50

The solution would be to have a javacsript timer that activates an event on the page to check for data or a flag. once it finds it, then it does the appropriate ui refreshes

mvp_badge
MVP
Rank: #18

Hi Craig,

I am sorry the component is indeed for OS11 but should be to difficult to change it to work for OS10,

You only have to replace the event and calling the event handler on the one weblock in the module to use a notify and get notify message.

Regards,

Daniel

Staff
Rank: #175

Just a gentle reminder, if you mention in your initial post which version of the platform you are running, it's easier for folks to ensure their answers are relevant for your version.