2

How to trigger any action, when the session[1] is idle for particular time (eg:10mins).

I'm doing one web application using Grails. If the system is idle for sometime, I need to hold some particular task. Is it possible to trigger any action when system is idle?

Note: I'm not asking about session timeout. By default, it should logout, if session is idle for 30mins.

[1] : Here session in the sense System. My web application is hosted in one server, Where many user can access the application. If one user's system is idle for some time, then I need to hold the task of that particular user. How can i do this?

Florent
  • 12,310
  • 10
  • 49
  • 58
Arivabi
  • 21
  • 2

1 Answers1

1

Based on the nature of the HTTP request-response pattern you are not able to trigger any server side tasks according to user (non-)interaction.

You could "watch" the user session on client side using JavaScript and trigger any tasks on client and/or server side. I have used the jQuery idleTimer to detect if the user is active or not.

With this plugin you could bind to several events to detect idle and reactivation of user. If the idle event is fired you could do an AJAX call to trigger any server side tasks like this:

$.idleTimer(10000);

$(document).bind("idle.idleTimer", function(){
    // function you want to fire when the user goes idle (e.g. do an AJAX call)

    $.post('${yourActionURL}', function(data) {
        // handle response
    });
});

Hope that helps!

aiolos
  • 4,637
  • 1
  • 23
  • 28
  • I want to capture system idle time. But my application is hosted in one server. So how can i get each and every user's system idle time? – Arivabi Sep 17 '12 at 09:08
  • It would be easier to answer if you could give some more details. What do you mean with "i need to hold the task of that particular user"? What do you want to achieve? – aiolos Sep 17 '12 at 10:50
  • I'm doing timesheet management project. In which, Project manager will assign some task to emp. if the emp wants to start the task, then they will click start. if they want to go for break, then they have to put the task to hold. If they complete it, they have to click complete. If the system is idle for sometime, then it also means, the emp not doing any work. so system should automatically put the task to hold. I want to acheive this. Pls give any solution – Arivabi Sep 17 '12 at 12:58
  • 1
    If the employer not doing any work (in the browser) you could detect it with jQuery idleTimer and call the according "breakTask" action on server. If the employer is generally not working within the browser (especially in your app) I don't know any solution to detect client system idle time. I think you have to use flash or JavaApplet to achieve that: http://stackoverflow.com/q/11291040/1230366 – aiolos Sep 17 '12 at 13:46
  • Ya i tried jQuery idleTimer, it works fine if the employee not using my application. But my application tracks only whether the employee is working in system or not. so i need to capture system idle time. Anyway Thanks for ur information. I'll try JavaApplet – Arivabi Sep 17 '12 at 13:54