I was wondering if there is a way to prevent users from executing a method until it's queue/threaded has stopped running.
Asked
Active
Viewed 97 times
1
-
It might be worth mentioning if this is MRI Ruby (which? 1.8 or 1.9) or JRuby, etc. since it makes a difference. The GIL prevents parallel execution in MRI Ruby 1.8 anyway so it's not actually possible to execute the same model method at the same time within the same process. – Nick Jan 06 '12 at 01:19
-
It is on Ruby 1.8.7....when the job runs, I don't want other user with a different session to execute the same job again. Please assist. – oprogfrogo Jan 06 '12 at 01:50
-
@ryan-bigg has the right idea with basically creating a semaphore lock on the method but you'll need to use a file based semaphore (with a reasonably long timeout) since the lock needs to prevent multiple processes from interacting at once. – Nick Jan 06 '12 at 02:11
-
Nick & Ryan, thanks for your replies. I suppose the examples in http://stackoverflow.com/questions/1461253/mutex-for-rails-processes would be the way to use filelocking. I'll give that a try. – oprogfrogo Jan 06 '12 at 06:18
1 Answers
3
You could define the method to check for the presence of another attribute, such as a running
boolean attribute. If this attribute is true
, then the method is un-usable.

Ryan Bigg
- 106,965
- 23
- 235
- 261
-
Ryan, please elaborate on this idea of using a running boolean. Are you referring to setting a global constant as a boolean and toggling it to false as soon as the job is done? – oprogfrogo Jan 05 '12 at 21:28