2

What selection of solution do I have if I want to launch particular piece of code for logged in user, but not more often then once per day (it can change in the future to run once per 6 hours though). I though about setting a cookie that will store a date when code was launched the last time, but I still have to check that cookie's value with every request in global.asax when request start event is raised. Are there any other more efficient solutions?

Ah, and also that event result is particular JavaScript code being rendered to user's page. So I need HttpResponse instance when the event is launched.

Thanks,Pawel

David Hoerster
  • 28,421
  • 8
  • 67
  • 102
dragonfly
  • 17,407
  • 30
  • 110
  • 219
  • Are just talking about a web project that will launch this code, or do you have some other process that can handle this? – David Hoerster Jan 18 '12 at 17:57
  • Cronjobs or their windows pendant come to mind. I don't recommend checking for the condition everytime a page is loaded, as it creates overhead. But to really help you here, we need to know which actions you want to take once a day! Do those actions interact with the client or are those just server-side actions? – yas4891 Jan 18 '12 at 18:00
  • I added some additional info in comment below - as this action will take advantage of HTML5 GeoLocation API, is has to be launched in browser -my first thought was to render appropriate javascript when request handler. But rangitatanz idea + discussion below seems to address my needs. – dragonfly Jan 18 '12 at 20:08

2 Answers2

2

You could use your cookie and a restful ajax call (back to the server to check for changes). Use HTTP Caching to ensure that it only happens at min once every 24 hrs (so set cache for +24hrs).

Everytime the result completes it will display the new text. Store a variable guid or somethign to ensure don't display the same one twice.

Dave Walker
  • 3,498
  • 1
  • 24
  • 25
  • Basically what I'm trying to achieve is to once per n hours send HTTP request to server with user's location (http://stackoverflow.com/questions/8914580/get-users-location-latitude-longitude-with-bing-or-google-maps-api) so that it's stored. So I think I will write JavaScript to my widget that will make RESTfull call, as you wrote... Could you elaborate a bit about HTTP Caching and how it can be employed, co I don't get it? – dragonfly Jan 18 '12 at 19:37
  • Righto then I get you. Just set a timeout and do a call. You can call the service http://www.server.com//location/set?location=. To find out about setTimeout look at http://www.w3schools.com/jsref/met_win_settimeout.asp to find out about using JQuery to do a html call see http://api.jquery.com/jQuery.post/ – Dave Walker Jan 18 '12 at 19:45
  • Build your own url or whatever you need to do. You can use your cookie data to work out if it hasnt' been sent on the page load of your site so when the user comes back they can send it off again. – Dave Walker Jan 18 '12 at 19:47
  • I think I can do without timer, it will satisfy my needs if the code that sends request (if needed) is executed when $(document).ready is called. Actually it doesn't have to be as accurate to do a request every exact 24 hours, cos user won't have their browser open on application all the time. Thanks! – dragonfly Jan 18 '12 at 20:14
1

quartz.net comes to mind (maybe overkill for you, but worth a look)

Quartz.NET is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems.

http://quartznet.sourceforge.net/

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116