# Alternatives to script/runner?

**URL:** <https://www.ruby-forum.com/t/alternatives-to-script-runner/70839>\
**Category:** Rails\
**Created:** [October 3, 2006, 12:28pm UTC](https://www.ruby-forum.com/t/alternatives-to-script-runner/70839 "2006-10-03T12:28:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [October 3, 2006, 12:28pm UTC](https://www.ruby-forum.com/t/alternatives-to-script-runner/70839/1 "2006-10-03T12:28:58Z")

</div>

I’ve been using script/runner to add and delete files from the  
database in response to inotify events. This works in theory, but is  
too slow to keep up with a large number of events in succession; I’m  
suspecting that the bottleneck is that script/runner has a huge  
startup cost.

One thing I thought of was to queue inotify events, and call  
script/runner once a minute to clear the queue, but that seems a bit  
inelegant - ideally, what I’d like to do is have a persistent process  
that is aware of my rails models, and which I can just keep sending  
events to and have it process them as they come in. Any thoughts on  
strategies to accomplish this?

martin

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [October 3, 2006, 1:03pm UTC](https://www.ruby-forum.com/t/alternatives-to-script-runner/70839/2 "2006-10-03T13:03:05Z")

</div>

On 3 October 2006 14:20, Martin DeMello wrote:

> One thing I thought of was to queue inotify events, and call  
> script/runner once a minute to clear the queue, but that seems a bit  
> inelegant - ideally, what I’d like to do is have a persistent process  
> that is aware of my rails models, and which I can just keep sending  
> events to and have it process them as they come in. Any thoughts on  
> strategies to accomplish this?

You can set up a separate process with DRB server on a well known  
address/port. Then, you can manage it through DRB.

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [October 3, 2006, 2:44pm UTC](https://www.ruby-forum.com/t/alternatives-to-script-runner/70839/3 "2006-10-03T14:44:08Z")

</div>

An simpler solution might be to use an obfuscated url and a wget  
cronjob.

crontab:

- 
  - 
    - 
      - 
        - wget [http://localhost/inotify/delete\_events/AS4LINAW4](http://localhost/inotify/delete_events/AS4LINAW4)

> /dev/null 2\>&1

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [October 5, 2006, 8:58am UTC](https://www.ruby-forum.com/t/alternatives-to-script-runner/70839/4 "2006-10-05T08:58:04Z")

</div>

On 10/3/06, Jon C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> An simpler solution might be to use an obfuscated url and a wget  
> cronjob.
> 
> crontab:
> 
> - 
> - 
> - 
> - 
> - wget [http://localhost/inotify/delete\_events/AS4LINAW4](http://localhost/inotify/delete_events/AS4LINAW4)
> 
> > /dev/null 2\>&1

Won’t that incur the extra overhead of a controller call? All I really  
need is activerecord and access to the models. I’m trying to do this  
in realtime (i.e. insert a file into the db as soon as inotify detects  
it) rather than via a cron job, and I have a feeling that if I can get  
rid of the script/runner startup time, the rest of the process will be  
able to keep up nicely.

martin

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [October 5, 2006, 9:00am UTC](https://www.ruby-forum.com/t/alternatives-to-script-runner/70839/5 "2006-10-05T09:00:05Z")

</div>

On 10/3/06, Maxim K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> address/port. Then, you can manage it through DRB.  
> Can you point me to some resources on running a DRB server from within  
> my rails app? Everything I’ve seen works the other way, with rails  
> acting as the DRB client.

martin

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [October 5, 2006, 10:53am UTC](https://www.ruby-forum.com/t/alternatives-to-script-runner/70839/6 "2006-10-05T10:53:04Z")

</div>

Martin DeMello wrote:

> Won’t that incur the extra overhead of a controller call? All I really  
> need is activerecord and access to the models. I’m trying to do this  
> in realtime (i.e. insert a file into the db as soon as inotify detects  
> it) rather than via a cron job, and I have a feeling that if I can get  
> rid of the script/runner startup time, the rest of the process will be  
> able to keep up nicely.

While backgroundrb is certainly the most elegant way to go, if you just  
want access to your model in a script without the whole Rails framework,  
just write a ruby script and require ActiveRecord and your model.  
Something like:

#!/usr/bin/ruby

# require AR and gems

require ‘rubygems’  
require ‘active\_record’  
require ‘…/app/models/event’

db\_config = YAML::load(File.open("…/config/database.yml"))  
ActiveRecord::Base.establish\_connection(db\_config[‘production’])

You can then acccess the Event model as normal. Hope it helps.

Alan

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [October 5, 2006, 12:50pm UTC](https://www.ruby-forum.com/t/alternatives-to-script-runner/70839/7 "2006-10-05T12:50:29Z")

</div>

On 10/5/06, Alan B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> want access to your model in a script without the whole Rails framework,  
> just write a ruby script and require ActiveRecord and your model.  
> Something like:

[…]

Thanks - that worked beautifully. I did have a look at backgroundrb,  
but I had the same problem with it as with regular drb - as far as I  
could make out, all the documentation assumed that Rails was running  
the client, not the server.

martin

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [October 5, 2006, 10:44am UTC](https://www.ruby-forum.com/t/alternatives-to-script-runner/70839/8 "2006-10-05T10:44:13Z")

</div>

On Thu, Oct 05, 2006 at 12:27:06PM +0530, Martin DeMello wrote:

> > You can set up a separate process with DRB server on a well known  
> > address/port. Then, you can manage it through DRB.
> 
> Can you point me to some resources on running a DRB server from within  
> my rails app? Everything I’ve seen works the other way, with rails  
> acting as the DRB client.

google for the nice backgroundrb plugin.

Jens

–  
Jens Krämer  
removed\_email\_address@domain.invalid
