Remote require

J

James Britt

Assume there is actual code underneath (probably involving open-uri),
and that I've got soul.rb, and I'm superbad.com

# File soul.rb lives on a remote Web server
$:.push( 'http://www.superbad.com' )

require 'soul' # Fetch from server if not found locally


Has anyone already implemented something like (I expect why_ to speak up
here)?

I should probably use hack 'require' to use open-uri, and play around,
but it's late and just wanted to toss this out.

What are the less-obvious issues with this way of fetching code? Let's
assume crypto code signing and authentication and the like.


James

--

http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
 
D

Daniel Amelang

I've got soul.rb, and I'm superbad.com

I hear ya brotha!

Um, it's really late here.

Dan
 
T

Trans

I believe somthing like that was done years ago, but haven't heard
about it since. Think it was on the RAA.... Ah, here it is. I even
remembered the name correctly!

http://raa.ruby-lang.org/project/net-require/

Even so, it's easy enough to hack asimple version together, but the key
would be caching (and checking for updates periodically?)

T
 
P

Phil Tomson

Assume there is actual code underneath (probably involving open-uri),
and that I've got soul.rb, and I'm superbad.com

# File soul.rb lives on a remote Web server
$:.push( 'http://www.superbad.com' )

require 'soul' # Fetch from server if not found locally


Has anyone already implemented something like (I expect why_ to speak up
here)?

I should probably use hack 'require' to use open-uri, and play around,
but it's late and just wanted to toss this out.

What are the less-obvious issues with this way of fetching code? Let's
assume crypto code signing and authentication and the like.


James

Did something like this long ago in TaskMaster (Warning: I haven't
touched that code in years and as far as I know it doesn't work in 1.8.x).
Wasn't a webserver, but a drb server. Sent the code over via drb as I
recall.

One issue to consider (which I did not solve) is the issue of extensions
- you should probably send the C code over (or C++ if that's what you're
using) and compile it on the machine doing the require in case it has a
different processor/OS (as opposed to sending the .so file). It would be
cool if remote require worked with extensions as well.

We could really use something like this packaged up seperately in a
library/module - [I would recommend not using the code from TaskMaster as
an example it was written early on in my Ruby career and that was also
prior to the existence of open-uri.]

Phil
 
J

James Britt

Trans said:
I believe somthing like that was done years ago, but haven't heard
about it since. Think it was on the RAA.... Ah, here it is. I even
remembered the name correctly!

http://raa.ruby-lang.org/project/net-require/
Thanks!


Even so, it's easy enough to hack asimple version together, but the key
would be caching (and checking for updates periodically?)

I figure whenever the code is run it would just fetches the remote file
and get the latest version. Different story for long-running apps and
processes.


James
--

http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
 
K

Kirk Haines

I figure whenever the code is run it would just fetches the remote file
and get the latest version. Different story for long-running apps and
processes.

Caching isn't a hard problem to solve. I have a Webcache class in my current
IOWA source that should do the trick. It is based off of an LRU cache. It's
not packaged seperately, but you're welcome to take it and modify as
necessary, or you can tell me what you would like to see changed and I can
seperate it into it's own mini-project. Current usage looks like this:

cache_size = 20
webcache = Iowa::Webcache.new(cache_size) # defaults to 100
url = 'http://www.superbad.com/rubylib/soul.rb'
content = webcache

It makes use of 'etag', 'last-modified', and 'expires' headers on content in
order to try to do the correct thing regarding caching, and when asked for
something it has already retrieved, just does a HEAD request on that item in
order to try to determine if the content has changed.

It was written for a specific purpose (a smart <img> tag that automagically
determines height and width of the image and puts that into the generated
HTML), so it has a default or two that probably should become configurable
items, such as the default time-to-live on content that doesn't have an
'expires' header.


Thanks,

Kirk Haines
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top