Start function periodic when form is active

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Start function periodic when form is active

Postby svisser1448437380 » Thu Feb 16, 2017 11:25 am

Is there a way to run a function recurrent, let's say every 5 minuten when a form is active?

Situation is a summary / start form in servoy client, which shows some form variables containing data collected by a function. The function will be executed when the form shows, so if user is switching between forms, the form will be updated. But if user does not leave the summary form, he will not see updated data when for example an import has run via a batch job.
saNder Visser
IT2serve
Servoy 7.4.7 / Windows 8.1
User avatar
svisser1448437380
 
Posts: 10
Joined: Wed Nov 25, 2015 9:43 am
Location: Zoetermeer, Netherlands

Re: Start function periodic when form is active

Postby Bernd.N » Thu Feb 16, 2017 2:29 pm

I would look first to this problem from a users UX/UI view.
When I am the user and know that the form gets updated only every 5 minutes, I would prefer to have an explicit refresh button that will show me the exact data situation at every time that I want to know about it.
Because otherwise I never know if the data is actual to the current moment or not.
This solves also the problem to refresh the data automatically.

In case you need the functionality as described and there are no other ways, you could create a permanent table that always holds the needed precalculated data.
That information could then be shown to the user and will get updated automatically by the Servoy data broadcasting mechanism.
https://wiki.servoy.com/display/DOCS/Databroadcasting

That table could be updated every 5 minutes with help of the Servoy Batch Processor (scheduler plugin).
In case there are several users who need to know that information, this solution should even be more efficient as it will trigger the calculation only once (server-side) every 5 minutes, instead of being triggered every 5 min by each client/user.
Last edited by Bernd.N on Thu Feb 16, 2017 7:36 pm, edited 1 time in total.
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 544
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Scheduler Plugin

Postby Bernd.N » Thu Feb 16, 2017 2:39 pm

The doc about the scheduler plugin says:
"The scheduled methods are executed in the client in which they are started. This means that if the client is closed, the scheduled method(s) will not run anymore."
So I assume that could run the needed function every 5 minutes.

When you close the form or another form gets active, you could deactivate the job with removeJob() in the onHide() event of the form.

https://wiki.servoy.com/display/public/DOCS/scheduler
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 544
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Re: Start function periodic when form is active

Postby patrick » Thu Feb 16, 2017 7:40 pm

Not sure what your function does exactly, but you could also consider using onDatabroadcast. Suppose you want to show something like number of open tasks and these change you could use the onDatabroadcast event to capture changes in the tasks you are interested in and fire a method to update your counter. That way you don't have to pull, but get a push.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 11 guests

cron