run process asynchronously

  

Hello,

I want to run one process asynchronously at the end of login action to perform database synch of external db to outsytems db - connected using extension, does 'processes' in the outsystems support this? How to achieve this if not supported by processes ? Here in this case user should be able to continue the work and process must update/insert data asynchronously in the OS database.

Thanks,

Durgesh.

Hi Durgesh,

If you want to execute just some logic asynchronously then I would create a Timer to do that logic and then, on login, would call the WakeTimer Action for that timer. That would execute the logic assynchronously and the user can continue to work.

Is that enough?

Cheers,

José

Thank you José for quick reply. 

Synchronization is required in 5-6 screens and in the near future, I also want to show - screen is getting synch message at the top, say if one screen is still getting synch I need to show the message data is getting synch (this synch is with external database which is legacy system).

I need to write 5-6 timers which seems ok to me, how can I use session variable to notify some screen action about synch complete so that I can make ajax refresh and change message like "Synch Complete" in the screen ?

Thanks,

Durgesh.

Hi Durgesh,

In the Timers you don't have access to the session.

One option is:

  • Have an Entity that has a boolean saying if the process has finished or not
  • Create a record with the boolean value to True
  • When the Timer starts update the record to False
  • At the end of the process set the record to True
  • Add the FakeNotifyWidget from Richwidgets to your screen
  • Set the Destination of the Notify (of the FakeNotifyWidget) to check if the record has a True or False and refresh or not the parts of the screen using Ajax Refresh
  • In javascript add a function that calls the FakeNotifyWidget (instructions to do this are on the widget)
  • Add in your javascript a setInterval function to call the previous function from time to time

You can avoid the 4 first steps by using the Timer metadata entities.

Cheers,

José

Hi Durgesh,

Timers don't run in the same session as your end-user screens, and as such you cannot use session variables to share data between them...

Off the top of my head I'd say if you want that sort of behaviour you need to change something in an Entity to reflect the status of synchronisation (maybe create a specific Entity to represent the sync concept) and then either poll via JavaScript timer or use something like the In-App Notifications component to get that message through to your screens.

Can you elaborate a bit more on what kind of external data sync are you performing that only makes sense after a specific user logs in?

Hi Durgesh,

You can have a intermediate entity to keep the status\other details during your timer run and create a screen to show the status from this entity ,add java script to refresh your screen every few second to show the progress.

This is very generic idea to track asynchronous process progress.

Regards

-PJ-

Thank you all for your replies.

@Jorge - In our application most of the data comes through other system's database and those systems are legacy one. So we have to do this sync and proceed with other requirements with OS.

One more thing to mention, every user is going to perform sync with database so if 10 users make login at the same time how OS server will handle this and as we know that same timer has never more than one execution.

Any thoughts on this or can someone suggest any other approach to sync.

Thanks,

Durgesh.

Hi Durgesh,

When multiple user are performing sync with database and you have only one timer for this scenario dump all users data into a single staging table with user-id with a status like [Pending -initial status] and make your timer to run data from this table , so your timer will only pick record with status pending and when timer dumps that data to the actual entity you can change its status to [Processed\Complete] or can also delete this data.

Doing this you need only one timer and one source for your timer i.e. the staging entity.



Regards

-PJ-

Solution

Hi Durgesh,

Durgesh Rokade wrote:

Thank you all for your replies.

@Jorge - In our application most of the data comes through other system's database and those systems are legacy one. So we have to do this sync and proceed with other requirements with OS.

My question remains:

Why do you need to perform independent synchronisation for different users? why not just synchronise all the required data in the background, regardless of the user? that way when a user logs in the data is already there on the OutSystems side and the user will see fresh (depending on sync criteria) data.

One more thing to mention, every user is going to perform sync with database so if 10 users make login at the same time how OS server will handle this and as we know that same timer has never more than one execution.

It's not even just a matter of the timer not running multiple times, you want to provide it with the user logging in... and you cannot with Timers.

If you really need to sync different data dependent on user, you cannot use a Timer and will have to go with the alternative async mechanism provided by the platform: Business Processes or BPT for short.

Processes also run asynchronously, can be started programmatically but also allow for input parameters to be passed, which Timers don't.

Solution

Thanks Pramod, Jorge for your responses.

Jorge Martins wrote:

My question remains:

Why do you need to perform independent synchronisation for different users? why not just synchronise all the required data in the background, regardless of the user? that way when a user logs in the data is already there on the OutSystems side and the user will see fresh (depending on sync criteria) data.

because this is also possible that database from which we are pulling data may get changed by some external systems and we will not get updated/fresh data so 'one time all users data sync' will not work.

There are many users which are not using our web site daily, syncing those data on timely basis will not be useful.

Sync data logic is already present per screen I just want to move these actions after login so that I can sync users data asynchronously with OS db.

Can you please tell me more about how to use BPT.

Thanks,

Durgesh.


Durgesh,

You can check the Master Class on Modelling Business Processes (BPT).