From _ at whats-your.name Tue Apr 17 23:58:22 2007 From: _ at whats-your.name (carmen) Date: Tue, 17 Apr 2007 23:58:22 -0400 Subject: customizing global request handler Message-ID: <20070418035822.GE27643@replic.net> what is the cleanest way to do something for every request of a particular type (Verb, and Content-Type header)? i'm trying to figure out if shipping a custom camping.rb is avoidable, and if, how i should structure a patch my app http://whats-your.name/yard/ uses exclusively JSON based messaging between server and client. this means POST bodies are JSON, and not querystring.. camping assumes: elsif @method == "post" qs.merge!(C.qsp(@in.read)) if i patch to: elsif @method == "post" case e.CONTENT_TYPE when "application/x-www-form-urlencoded" qs.merge!(C.qsp(@in.read)) when "application/json" @input = JSON.parse(@in.read)) end theres two probs, 1) you now have to always make sure you send the x-www-form-urlencoded header (weird browsers, or XHR requests might not), 2) @input is overwritten by qs.dup, input isnt a query string! i tried using a custom verb, which works fine in firefox, but not WebKit-QT4-Linux.. RFC 2616 does not specify a format for the data in a POST body, and the overall function of the request is consistent with POST. what do i do? :) From zimbatm at oree.ch Wed Apr 18 12:05:09 2007 From: zimbatm at oree.ch (Jonas Pfenniger) Date: Wed, 18 Apr 2007 18:05:09 +0200 Subject: customizing global request handler In-Reply-To: <20070418035822.GE27643@replic.net> References: <20070418035822.GE27643@replic.net> Message-ID: 2007/4/18, carmen <_ at whats-your.name>: > what is the cleanest way to do something for every request of a particular type (Verb, and Content-Type header)? i'm trying to figure out if shipping a custom camping.rb is avoidable, and if, how i should structure a patch > > > my app http://whats-your.name/yard/ uses exclusively JSON based messaging between server and client. this means POST bodies are JSON, and not querystring.. camping assumes: > > elsif @method == "post" > qs.merge!(C.qsp(@in.read)) > > if i patch to: > > elsif @method == "post" > case e.CONTENT_TYPE > when "application/x-www-form-urlencoded" > qs.merge!(C.qsp(@in.read)) > when "application/json" > @input = JSON.parse(@in.read)) > end > > theres two probs, 1) you now have to always make sure you send the x-www-form-urlencoded header (weird browsers, or XHR requests might not), 2) @input is overwritten by qs.dup, input isnt a query string! > > i tried using a custom verb, which works fine in firefox, but not WebKit-QT4-Linux.. RFC 2616 does not specify a format for the data in a POST body, and the overall function of the request is consistent with POST. > > what do i do? :) Hi Carmen, to avoid patching Camping, I suggest you look into overriding the "service" method for the target controllers. You can do this in your main application module or by including a custom module in your controllers, as you prefer. Let me know if you need more hints. -- Cheers, zimbatm From tlockney at gmail.com Wed Apr 18 13:19:08 2007 From: tlockney at gmail.com (Thomas Lockney) Date: Wed, 18 Apr 2007 10:19:08 -0700 Subject: customizing global request handler In-Reply-To: References: <20070418035822.GE27643@replic.net> Message-ID: On 4/18/07, Jonas Pfenniger wrote: > > Hi Carmen, > > to avoid patching Camping, I suggest you look into overriding the > "service" method for the target controllers. You can do this in your > main application module or by including a custom module in your > controllers, as you prefer. Let me know if you need more hints. I was going to suggest the same thing, but when I looked at it, it wasn't clear if this would allow for grabbing data like the request headers (allowing you to determine what form the submitted data takes). Based on the code Carmen posted, it looks like the idea is to be able to use the same controllers whether the data comes in from regular requests or as JSON data. Granted, that could still be done in the controllers, but it does end up being a bit less elegant. -- Thomas Lockney | tlockney at gmail.com | http://opposable-thumbs.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/camping-list/attachments/20070418/bf3f649d/attachment.html From _ at whats-your.name Wed Apr 18 14:23:30 2007 From: _ at whats-your.name (carmen) Date: Wed, 18 Apr 2007 14:23:30 -0400 Subject: customizing global request handler In-Reply-To: References: <20070418035822.GE27643@replic.net> Message-ID: <20070418182330.GF27643@replic.net> > controllers whether the data comes in from regular requests or as JSON data. > Granted, that could still be done in the controllers, but it does end up > being a bit less elegant. the main idea is always get @input in the controller regardless of the format - currently it unnecessarily parses the POST data trying to get querystring values out of the JSON maybe that method should be split up? it already combines the file upload mangling, and GET and POST querystring parsing.. i will be using formats besides JSON to set @input too... Turtle, for example.. > > -- > Thomas Lockney | tlockney at gmail.com | http://opposable-thumbs.net > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list From zimbatm at oree.ch Wed Apr 18 14:38:30 2007 From: zimbatm at oree.ch (Jonas Pfenniger) Date: Wed, 18 Apr 2007 20:38:30 +0200 Subject: customizing global request handler In-Reply-To: References: <20070418035822.GE27643@replic.net> Message-ID: 2007/4/18, Thomas Lockney : > On 4/18/07, Jonas Pfenniger wrote: > > Hi Carmen, > > > > to avoid patching Camping, I suggest you look into overriding the > > "service" method for the target controllers. You can do this in your > > main application module or by including a custom module in your > > controllers, as you prefer. Let me know if you need more hints. > > I was going to suggest the same thing, but when I looked at it, it wasn't > clear if this would allow for grabbing data like the request headers > (allowing you to determine what form the submitted data takes). Based on the > code Carmen posted, it looks like the idea is to be able to use the same > controllers whether the data comes in from regular requests or as JSON data. > Granted, that could still be done in the controllers, but it does end up > being a bit less elegant. Yes, Camping could probably benefit from some method splitting here. I feel like this method is too big and not really correct. I don't think that it should put the posted data in a Tempfile, especially if your controller will never make a use of it. I'm not sure it follows the RFC too. Btw I've spotted some debug line here that could be removed : http://code.whytheluckystiff.net/camping/browser/trunk/lib/camping-unabridged.rb#L402 -- Cheers, zimbatm From _ at whats-your.name Wed Apr 18 14:53:54 2007 From: _ at whats-your.name (carmen) Date: Wed, 18 Apr 2007 14:53:54 -0400 Subject: customizing global request handler In-Reply-To: References: <20070418035822.GE27643@replic.net> Message-ID: <20070418185354.GG27643@replic.net> On Wed Apr 18, 2007 at 08:38:30PM +0200, Jonas Pfenniger wrote: > 2007/4/18, Thomas Lockney : > > On 4/18/07, Jonas Pfenniger wrote: > > > Hi Carmen, > > > > > > to avoid patching Camping, I suggest you look into overriding the > > > "service" method for the target controllers. You can do this in your > > > main application module or by including a custom module in your > > > controllers, as you prefer. Let me know if you need more hints. > > > > I was going to suggest the same thing, but when I looked at it, it wasn't > > clear if this would allow for grabbing data like the request headers > > (allowing you to determine what form the submitted data takes). Based on the > > code Carmen posted, it looks like the idea is to be able to use the same > > controllers whether the data comes in from regular requests or as JSON data. > > Granted, that could still be done in the controllers, but it does end up > > being a bit less elegant. > > Yes, Camping could probably benefit from some method splitting here. I perhaps, but > feel like this method is too big and not really correct. I don't think > that it should put the posted data in a Tempfile, especially if your > controller will never make a use of it. I'm not sure it follows the > RFC too. > > Btw I've spotted some debug line here that could be removed : > http://code.whytheluckystiff.net/camping/browser/trunk/lib/camping-unabridged.rb#L402 it appears -r188 added the patch i needed to use the service method without the unecessary parsing.. /me remembers what i was taught in first grade - always SVN up first! > > -- > Cheers, > zimbatm > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > From _ at whats-your.name Wed Apr 18 15:01:10 2007 From: _ at whats-your.name (carmen) Date: Wed, 18 Apr 2007 15:01:10 -0400 Subject: Gem broekn? In-Reply-To: <20070418185354.GG27643@replic.net> References: <20070418035822.GE27643@replic.net> <20070418185354.GG27643@replic.net> Message-ID: <20070418190110.GH27643@replic.net> gem install --source http://code.whytheluckystiff.net camping Need to update 3 gems from http://code.whytheluckystiff.net ... complete ERROR: While executing gem ... (TypeError) gem install camping-omnibus --source http://code.whytheluckystiff.net Install required dependency camping? [Yn] y ERROR: While executing gem ... (TypeError) can't convert Hash into String ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux] /me scurries off to manually check out From zimbatm at oree.ch Wed Apr 18 16:46:34 2007 From: zimbatm at oree.ch (Jonas Pfenniger) Date: Wed, 18 Apr 2007 22:46:34 +0200 Subject: Gem broekn? In-Reply-To: <20070418190110.GH27643@replic.net> References: <20070418035822.GE27643@replic.net> <20070418185354.GG27643@replic.net> <20070418190110.GH27643@replic.net> Message-ID: Try removing ~/.gem/source_cache first 2007/4/18, carmen <_ at whats-your.name>: > gem install --source http://code.whytheluckystiff.net camping > Need to update 3 gems from http://code.whytheluckystiff.net > ... > complete > ERROR: While executing gem ... (TypeError) > > > gem install camping-omnibus --source http://code.whytheluckystiff.net > Install required dependency camping? [Yn] y > ERROR: While executing gem ... (TypeError) > can't convert Hash into String > > ruby -v > ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux] > > /me scurries off to manually check out > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > -- Cheers, zimbatm From _ at whats-your.name Wed Apr 18 23:06:24 2007 From: _ at whats-your.name (carmen) Date: Wed, 18 Apr 2007 23:06:24 -0400 Subject: Gem broekn? In-Reply-To: References: <20070418035822.GE27643@replic.net> <20070418185354.GG27643@replic.net> <20070418190110.GH27643@replic.net> Message-ID: <20070419030624.GA1876@replic.net> On Wed Apr 18, 2007 at 10:46:34PM +0200, Jonas Pfenniger wrote: > Try removing ~/.gem/source_cache first that isnt it, rubygems just keeps on proving it hates me [1] SVN head didnt like me either: NoMethodError undefined method `capture' for # in #render so it was back to r180 cp -av'd from another machine since rubygems isnt working definitely investigating tiny lua httpds tho, since redland's bindings like to segfault the ruby interp (well, i dont know whose fault it is, other than it happens a lot) 1. http://rubyforge.org/pipermail/mongrel-users/2007-January/002753.html > > 2007/4/18, carmen <_ at whats-your.name>: > > gem install --source http://code.whytheluckystiff.net camping > > Need to update 3 gems from http://code.whytheluckystiff.net > > ... > > complete > > ERROR: While executing gem ... (TypeError) > > > > > > gem install camping-omnibus --source http://code.whytheluckystiff.net > > Install required dependency camping? [Yn] y > > ERROR: While executing gem ... (TypeError) > > can't convert Hash into String > > > > ruby -v > > ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux] > > > > /me scurries off to manually check out > > _______________________________________________ > > Camping-list mailing list > > Camping-list at rubyforge.org > > http://rubyforge.org/mailman/listinfo/camping-list > > > > > -- > Cheers, > zimbatm > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > From _ at whats-your.name Thu Apr 19 13:17:30 2007 From: _ at whats-your.name (carmen) Date: Thu, 19 Apr 2007 13:17:30 -0400 Subject: request in controller In-Reply-To: <20070418035822.GE27643@replic.net> References: <20070418035822.GE27643@replic.net> Message-ID: <20070419171730.GC1876@replic.net> in the service method (or any controller method), is there a way to access the incoming request headers? @headers is initialized to {'Content-Type'=>'text/html'} for the response at this point.. im wondering if the request is already sitting around in some instance var, or setting e to @e in initialize is the best solution.. From _ at whats-your.name Thu Apr 19 13:24:53 2007 From: _ at whats-your.name (carmen) Date: Thu, 19 Apr 2007 13:24:53 -0400 Subject: request in controller In-Reply-To: <20070419171730.GC1876@replic.net> References: <20070418035822.GE27643@replic.net> <20070419171730.GC1876@replic.net> Message-ID: <20070419172453.GD1876@replic.net> On Thu Apr 19, 2007 at 01:17:30PM -0400, carmen wrote: > in the service method (or any controller method), is there a way to access the incoming request headers? @headers is initialized to {'Content-Type'=>'text/html'} for the response at this point.. > > im wondering if the request is already sitting around in some instance var, or setting e to @e in initialize is the best solution.. nevermind, discovered @env about 30 seconds into the 300 second greylist period, and no idea to cancel the pending message in that time.. > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > From ml at beeblebrox.net Thu Apr 19 14:58:09 2007 From: ml at beeblebrox.net (Thomas Weibel) Date: Thu, 19 Apr 2007 20:58:09 +0200 Subject: Save sessions on file system instead of database table? Message-ID: <1177009089.12058.5.camel@marvin> Hi Is there a way to save session data on the file system (like in Rails) instead of a database table? The reason I'm asking is, that I'm writing a Camping application without using ActiveRecord (mostly for learning purposes) and I don't want to use ActiveRecord just for sessions. Thanks, Thomas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/camping-list/attachments/20070419/14ddcda0/attachment.bin From why at whytheluckystiff.net Thu Apr 19 17:14:27 2007 From: why at whytheluckystiff.net (why the lucky stiff) Date: Thu, 19 Apr 2007 16:14:27 -0500 Subject: Save sessions on file system instead of database table? In-Reply-To: <1177009089.12058.5.camel@marvin> References: <1177009089.12058.5.camel@marvin> Message-ID: <20070419211426.GN93610@beekeeper.hobix.com> On Thu, Apr 19, 2007 at 08:58:09PM +0200, Thomas Weibel wrote: > Is there a way to save session data on the file system (like in Rails) > instead of a database table? Well, you could probably use CGI::Session (which comes with Ruby) and try to tie together that and Camping::Session. Or you could write your own. I'd really like Camping::Session to start using shared memory, something like memcached. _why From dan at anotherdan.com Fri Apr 20 03:53:50 2007 From: dan at anotherdan.com (Dan Thrue) Date: Fri, 20 Apr 2007 09:53:50 +0200 Subject: Save sessions on file system instead of database table? In-Reply-To: <20070419211426.GN93610@beekeeper.hobix.com> References: <1177009089.12058.5.camel@marvin> <20070419211426.GN93610@beekeeper.hobix.com> Message-ID: <478a1cee0704200053y45fdefbeicb398751ef2041ff@mail.gmail.com> I have written a camping-session container for memcached - I can put it somewhere availible... I have never tried to compile a rubygem - and dont know if that is the way to put an extension like this? /Dan On 4/19/07, why the lucky stiff wrote: > On Thu, Apr 19, 2007 at 08:58:09PM +0200, Thomas Weibel wrote: > > Is there a way to save session data on the file system (like in Rails) > > instead of a database table? > > Well, you could probably use CGI::Session (which comes with Ruby) > and try to tie together that and Camping::Session. > > Or you could write your own. I'd really like Camping::Session to > start using shared memory, something like memcached. > > _why > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > From drnicwilliams at gmail.com Fri Apr 20 04:15:31 2007 From: drnicwilliams at gmail.com (Nic Williams) Date: Fri, 20 Apr 2007 10:15:31 +0200 Subject: Save sessions on file system instead of database table? In-Reply-To: <478a1cee0704200053y45fdefbeicb398751ef2041ff@mail.gmail.com> References: <1177009089.12058.5.camel@marvin> <20070419211426.GN93610@beekeeper.hobix.com> <478a1cee0704200053y45fdefbeicb398751ef2041ff@mail.gmail.com> Message-ID: <44b555bb0704200115l2ab928f0u78ae10973ce0d491@mail.gmail.com> Try http://newgem.rubyforge.org and see if that helps start your gem. Nic On 4/20/07, Dan Thrue wrote: > > I have written a camping-session container for memcached - I can put > it somewhere availible... > > I have never tried to compile a rubygem - and dont know if that is the > way to put an extension like this? > > /Dan > > On 4/19/07, why the lucky stiff wrote: > > On Thu, Apr 19, 2007 at 08:58:09PM +0200, Thomas Weibel wrote: > > > Is there a way to save session data on the file system (like in Rails) > > > instead of a database table? > > > > Well, you could probably use CGI::Session (which comes with Ruby) > > and try to tie together that and Camping::Session. > > > > Or you could write your own. I'd really like Camping::Session to > > start using shared memory, something like memcached. > > > > _why > > _______________________________________________ > > Camping-list mailing list > > Camping-list at rubyforge.org > > http://rubyforge.org/mailman/listinfo/camping-list > > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > -- Dr Nic Williams http://www.drnicwilliams.com - Ruby/Rails/Javascript/Web2.0 skype: nicwilliams (p) +61 7 3102 3237 (Finds me anywhere in the world, via Skype) (m) +4673 768 1389 (Swedish mobile) (f) +61 7 3305 7572 (sends fax to my email) Bj?rnsonsgatan 153, 16 844 Bromma, Sweden -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/camping-list/attachments/20070420/81bf5451/attachment-0001.html From dan at anotherdan.com Fri Apr 20 05:37:47 2007 From: dan at anotherdan.com (Dan Thrue) Date: Fri, 20 Apr 2007 11:37:47 +0200 Subject: Save sessions on file system instead of database table? In-Reply-To: <44b555bb0704200115l2ab928f0u78ae10973ce0d491@mail.gmail.com> References: <1177009089.12058.5.camel@marvin> <20070419211426.GN93610@beekeeper.hobix.com> <478a1cee0704200053y45fdefbeicb398751ef2041ff@mail.gmail.com> <44b555bb0704200115l2ab928f0u78ae10973ce0d491@mail.gmail.com> Message-ID: <478a1cee0704200237g5537ccb6me63e441c66b9b0d0@mail.gmail.com> It looks as if I can easily create a gem - I will try this tonight. Thanks... On 4/20/07, Nic Williams wrote: > Try http://newgem.rubyforge.org and see if that helps start your gem. > > Nic > > > On 4/20/07, Dan Thrue < dan at anotherdan.com> wrote: > > I have written a camping-session container for memcached - I can put > > it somewhere availible... > > > > I have never tried to compile a rubygem - and dont know if that is the > > way to put an extension like this? > > > > /Dan > > > > On 4/19/07, why the lucky stiff < why at whytheluckystiff.net> wrote: > > > On Thu, Apr 19, 2007 at 08:58:09PM +0200, Thomas Weibel wrote: > > > > Is there a way to save session data on the file system (like in Rails) > > > > instead of a database table? > > > > > > Well, you could probably use CGI::Session (which comes with Ruby) > > > and try to tie together that and Camping::Session. > > > > > > Or you could write your own. I'd really like Camping::Session to > > > start using shared memory, something like memcached. > > > > > > _why > > > _______________________________________________ > > > Camping-list mailing list > > > Camping-list at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/camping-list > > > > > _______________________________________________ > > Camping-list mailing list > > Camping-list at rubyforge.org > > http://rubyforge.org/mailman/listinfo/camping-list > > > > > > -- > Dr Nic Williams > http://www.drnicwilliams.com - Ruby/Rails/Javascript/Web2.0 > skype: nicwilliams > (p) +61 7 3102 3237 (Finds me anywhere in the world, via Skype) > (m) +4673 768 1389 (Swedish mobile) > (f) +61 7 3305 7572 (sends fax to my email) > Bj?rnsonsgatan 153, 16 844 Bromma, Sweden > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > From jeremy.burks at gmail.com Mon Apr 23 14:17:45 2007 From: jeremy.burks at gmail.com (Jeremy Burks) Date: Mon, 23 Apr 2007 13:17:45 -0500 Subject: X-Sendfile, static files, windows Message-ID: i wrote a little camping app which serves the css, js and images statically using the Static class example i found on the camping wiki. everything works perfectly on my mac. once on windows the static files don't get served. a 404 is returned. i have tried running the app using camping, webrick and mongrel, all give the same 404 response. here is an example value of X-Sendfile. I have verified that the path does exist. C:/work/camping_app/public/images/icons/feed.png does anyone have an idea on what i am missing? Thanks. From jeremy.burks at gmail.com Mon Apr 23 18:32:54 2007 From: jeremy.burks at gmail.com (Jeremy Burks) Date: Mon, 23 Apr 2007 17:32:54 -0500 Subject: X-Sendfile, static files, windows In-Reply-To: References: Message-ID: in Mongrel, CampingHandler defaults the DirHandler to "/". i was assigning X-Sendfile an absolute path. as a result an extra c:/ was getting tacked on to the path inside Mongrel's DirHandler. that made the path path look like c:/c:/path/file.png. Hence the 404. On 4/23/07, Jeremy Burks wrote: > i wrote a little camping app which serves the css, js and images > statically using the Static class example i found on the camping wiki. > everything works perfectly on my mac. once on windows the static files > don't get served. a 404 is returned. > > i have tried running the app using camping, webrick and mongrel, all > give the same 404 response. > > here is an example value of X-Sendfile. I have verified that the path > does exist. > C:/work/camping_app/public/images/icons/feed.png > > does anyone have an idea on what i am missing? > > Thanks. > From jonathan.stott at gmail.com Wed Apr 25 09:40:14 2007 From: jonathan.stott at gmail.com (Jonathan Stott) Date: Wed, 25 Apr 2007 14:40:14 +0100 Subject: Running something periodically. Message-ID: <14cf210a0704250640n1057f926jfcac0e71e9363d41@mail.gmail.com> Suppose, for a moment, that I have a Camping app. It looks at something, like an RSS feed of upcoming events, and displays them if they meet a specified criterion. I look at the index page, it fetches the feed items and then displays them. Yay. Maybe it also writes them to a database. Which is great, so long as I keep looking at the page every so often. But what do I do while I'm sleeping? or on holiday? Who will look at the page to fetch the feeds then? So, is there some way I can make Camping perform the fetch operation regularly, all internal to Camping? I know I could set up a cron job to grab the page via curl every hour or whatever, but can I do it just in Camping? Any pointers gratefully recieved, Jonathan From mark.m.fredrickson at gmail.com Wed Apr 25 09:57:29 2007 From: mark.m.fredrickson at gmail.com (Mark Fredrickson) Date: Wed, 25 Apr 2007 08:57:29 -0500 Subject: Running something periodically. In-Reply-To: <14cf210a0704250640n1057f926jfcac0e71e9363d41@mail.gmail.com> References: <14cf210a0704250640n1057f926jfcac0e71e9363d41@mail.gmail.com> Message-ID: <3db8a8970704250657r718c0d2m6872fa0100b60b72@mail.gmail.com> > Which is great, so long as I keep looking at the page every so often. > But what do I do while I'm sleeping? or on holiday? Who will look at > the page to fetch the feeds then? If a feed gets updated in the woods, but there's nobody there to read it, is there any new content? ;-) But I understand what you're saying: you want to fetch the feeds so you don't miss any items that fall off the bottom of the feed and/or the performance hit of fetching the feed each time is irritating. > > So, is there some way I can make Camping perform the fetch operation > regularly, all internal to Camping? I know I could set up a cron job > to grab the page via curl every hour or whatever, but can I do it just > in Camping? Two proposed solutions: 1. Threads: create a thread that just sleeps for an hour, then wakes up and fetches the feed. You can do this in your camping app. I'm not a threading expert, so I'll leave it to you to fill in the details. 2. External cron job: Every hour run something like `curl http://myapp.com/fetchfeeds > /dev/null` 2 is probably the quick and dirty fix. 1 is certainly more clever. Good luck -Mark From manfred at gmail.com Wed Apr 25 11:27:23 2007 From: manfred at gmail.com (Manfred Stienstra) Date: Wed, 25 Apr 2007 17:27:23 +0200 Subject: Running something periodically. In-Reply-To: <3db8a8970704250657r718c0d2m6872fa0100b60b72@mail.gmail.com> References: <14cf210a0704250640n1057f926jfcac0e71e9363d41@mail.gmail.com> <3db8a8970704250657r718c0d2m6872fa0100b60b72@mail.gmail.com> Message-ID: On Apr 25, 2007, at 3:57, Mark Fredrickson wrote: > > 2. External cron job: Every hour run something like `curl > http://myapp.com/fetchfeeds > /dev/null` I would recommend a cronjob, solving it with a long running process will likely get you in trouble with memory leaks and such. Manfred From jonathan.stott at gmail.com Wed Apr 25 15:02:06 2007 From: jonathan.stott at gmail.com (Jonathan Stott) Date: Wed, 25 Apr 2007 20:02:06 +0100 Subject: Running something periodically. In-Reply-To: References: <14cf210a0704250640n1057f926jfcac0e71e9363d41@mail.gmail.com> <3db8a8970704250657r718c0d2m6872fa0100b60b72@mail.gmail.com> Message-ID: <14cf210a0704251202g5950fc86sd9d9f4e535935256@mail.gmail.com> > I would recommend a cronjob, solving it with a long running process > will likely get you in trouble with memory leaks and such. > > Manfred I'm not quite sure how this is relevant (though I fully admit I might be missing some of the complexities of ruby, camping and/or threads), since I'd like the process to be part of a Camping App, which is presumably going to be running fairly consistently anyway. Unless you're suggesting an entirely external app that does the fetching and somehow pushes the results into the database of the camping application so it can display it? Anyway, I know I can set up a cronjob with curl to regularly get the page and thus make the controller logic fetch the feeds, I was just wondering if there was a way to do it in the app itself, since I like applications that are self-contained. Jonathan From rcoder at gmail.com Wed Apr 25 18:18:13 2007 From: rcoder at gmail.com (Lennon Day-Reynolds) Date: Wed, 25 Apr 2007 15:18:13 -0700 Subject: Running something periodically. In-Reply-To: <14cf210a0704251202g5950fc86sd9d9f4e535935256@mail.gmail.com> References: <14cf210a0704250640n1057f926jfcac0e71e9363d41@mail.gmail.com> <3db8a8970704250657r718c0d2m6872fa0100b60b72@mail.gmail.com> <14cf210a0704251202g5950fc86sd9d9f4e535935256@mail.gmail.com> Message-ID: <5d4c61240704251518w78db42d8h7c98d3db1e940390@mail.gmail.com> On 4/25/07, Jonathan Stott wrote: > > I would recommend a cronjob, solving it with a long running process > > will likely get you in trouble with memory leaks and such. > > > > Manfred > > I'm not quite sure how this is relevant (though I fully admit I might > be missing some of the complexities of ruby, camping and/or threads), > since I'd like the process to be part of a Camping App, which is > presumably going to be running fairly consistently anyway. Unless > you're suggesting an entirely external app that does the fetching and > somehow pushes the results into the database of the camping > application so it can display it? The problem with long-running multi-threaded Ruby processes tends to be that the threads themselves fail to be garbage collected, eventually resulting in memory problems. If you only have one background thread doing the updates, you really shouldn't have to worry about it as a major source of leaks. > Anyway, I know I can set up a cronjob with curl to regularly get the > page and thus make the controller logic fetch the feeds, I was just > wondering if there was a way to do it in the app itself, since I like > applications that are self-contained. It really shouldn't be hard. Something like the following in your application startup code should be enough: --- # Note: this line needs to come before Camping does its auto-magical SQLite # connection stuff, so you may need to experiment ActiveRecord::Base.allow_concurrency = true # This line just starts a background thread that will run once per hour in the # background, calling your refresh method each time Thread.new { loop { MyApp::Controllers::FeedReader.refresh; sleep 3600 } } --- -Lennon From zimbatm at oree.ch Thu Apr 26 09:11:48 2007 From: zimbatm at oree.ch (Jonas Pfenniger) Date: Thu, 26 Apr 2007 15:11:48 +0200 Subject: Running something periodically. In-Reply-To: <14cf210a0704250640n1057f926jfcac0e71e9363d41@mail.gmail.com> References: <14cf210a0704250640n1057f926jfcac0e71e9363d41@mail.gmail.com> Message-ID: 2007/4/25, Jonathan Stott : > Suppose, for a moment, that I have a Camping app. It looks at > something, like an RSS feed of upcoming events, and displays them if > they meet a specified criterion. I look at the index page, it fetches > the feed items and then displays them. Yay. Maybe it also writes them > to a database. > > Which is great, so long as I keep looking at the page every so often. > But what do I do while I'm sleeping? or on holiday? Who will look at > the page to fetch the feeds then? > > So, is there some way I can make Camping perform the fetch operation > regularly, all internal to Camping? I know I could set up a cron job > to grab the page via curl every hour or whatever, but can I do it just > in Camping? You can make use of the create method to initialize your thread. Just make sure that you store the thread's presence outside of the app's module to avoid problems when reloading.. module YourApp def self.create ::YOURAPP_FETCH_THREAD ||= Thread.new { ... } end end PS : I wouldn't use an external scheduler if the database is sqlite.. I had lots of problems with locking. -- Cheers, zimbatm From jonathan.stott at gmail.com Thu Apr 26 11:29:48 2007 From: jonathan.stott at gmail.com (Jonathan Stott) Date: Thu, 26 Apr 2007 16:29:48 +0100 Subject: Running something periodically. In-Reply-To: References: <14cf210a0704250640n1057f926jfcac0e71e9363d41@mail.gmail.com> Message-ID: <14cf210a0704260829w3292b186y67d477fe68715ed3@mail.gmail.com> > You can make use of the create method to initialize your thread. Just > make sure that you store the thread's presence outside of the app's > module to avoid problems when reloading.. > > module YourApp > def self.create > ::YOURAPP_FETCH_THREAD ||= Thread.new { ... } > end > end > > PS : I wouldn't use an external scheduler if the database is sqlite.. > I had lots of problems with locking. > > -- > Cheers, > zimbatm Thank you Lennon and Jonas, everything seems to be working as I wanted it to now :) Regards Jonathan From Bil.Kleb at NASA.gov Sat Apr 28 15:38:25 2007 From: Bil.Kleb at NASA.gov (Bil Kleb) Date: Sat, 28 Apr 2007 15:38:25 -0400 Subject: RESTful web service tutorial? Message-ID: <4633A2B1.1010107@NASA.gov> Hi, I would like to turn some of our simulation codes out to pasture and string some of them together by draping them in web services. I'm looking for a RESTful Camping tutorial to get started ... pointers appreciated. Some simple example applications: airfoil force calculator: feed it an airfoil geometry, an angle of attack, and a Mach number, and it returns the lift, drag, and pitching moment ablation: feed it surface temperature and thermal protection material properties, and it returns surface blowing rate and specie mass fractions. Thanks, -- Bil Kleb http://fun3d.larc.nasa.gov From Bil.Kleb at NASA.gov Sat Apr 28 16:39:22 2007 From: Bil.Kleb at NASA.gov (Bil Kleb) Date: Sat, 28 Apr 2007 16:39:22 -0400 Subject: RESTful web service tutorial? In-Reply-To: References: <4633A2B1.1010107@NASA.gov> Message-ID: <4633B0FA.9000306@NASA.gov> Someone asked: > Are you looking for a REST tutorial, or are you already familiar with > REST and just want to know how to use it with Camping? I am barely familiar with both REST and Camping, and I'd like to explore some RESTful Camping as a way to learn both. Kleb wrote: >> Some simple example applications: >> >> airfoil force calculator: feed it an airfoil >> geometry, an angle of attack, and a Mach number, >> and it returns the lift, drag, and pitching moment Where for the sake of argument, the "airfoil force calculator" is a executable on a *nix box that currently swallows input from standard input and dumps results to standard output. Later, -- Bil Kleb http://fun3d.larc.nasa.gov From me at cpb.ca Sat Apr 28 17:39:55 2007 From: me at cpb.ca (Caleb Buxton) Date: Sat, 28 Apr 2007 14:39:55 -0700 Subject: RESTful web service tutorial? In-Reply-To: <4633B0FA.9000306@NASA.gov> References: <4633A2B1.1010107@NASA.gov> <4633B0FA.9000306@NASA.gov> Message-ID: <60D02724-6117-4238-BC0D-D5E7FE9B6535@cpb.ca> On 28-Apr-07, at 1:39 PM, Bil Kleb wrote: > Someone asked: >> Are you looking for a REST tutorial, or are you already familiar with >> REST and just want to know how to use it with Camping? > > I am barely familiar with both REST and Camping, and I'd like > to explore some RESTful Camping as a way to learn both. > With regards to rest, the rails community has more tutorials. Infact, there is a peepcode screencast: http://nubyonrails.com/articles/2006/10/09/peepcode-rest-basics It also includes a free, rails specific, cheat sheet. From the perspective of services using your camping app, one of the most important things (as I understand it) is the URL of the action. The cheat sheet includes a table which matches up some rails methods with HTTP predicates and paths and software actions. With regards to implementing it in Camping... This thread includes discussion about getting Camping to recognize other predicates http://www.mail-archive.com/camping-list at rubyforge.org/msg00029.html Otherwise, some problems with using semicolons to access different aspects ( http://code.whytheluckystiff.net/camping/ticket/118 ) which is, according to the people talking there, a rails-ish thing anyways. Hope this helps, Caleb ps: is the airfoil calculator going to be publicly available...? :) > Later, > -- > Bil Kleb > http://fun3d.larc.nasa.gov > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list From _ at whats-your.name Sat Apr 28 18:08:34 2007 From: _ at whats-your.name (carmen) Date: Sat, 28 Apr 2007 18:08:34 -0400 Subject: RESTful web service tutorial? In-Reply-To: <4633B0FA.9000306@NASA.gov> References: <4633A2B1.1010107@NASA.gov> <4633B0FA.9000306@NASA.gov> Message-ID: <20070428220834.GC22812@replic.net> =begin > I am barely familiar with both REST and Camping, and I'd like > to explore some RESTful Camping as a way to learn both. i still don't know exactly what REST is (maybe there is no exact definition), part of it is mapping of methods to URIs for a HTTP RPC camping makes playing with all this easy some "REST" examples i see involve query strings, but these can become rather ugly and unreadable/hackable in camping you may do something like =end module Aero::Controllers class Foil < R '/foil/([^/]+)/([^/]+)/([^/]+)' def get geo, angle, mach # do some math here and return results end end =begin the last line in the 'get' method is implicitly returned, it can be text, or a call to a view method.. you would do something like GET /foil/1/90.000/3 in this case, or perhaps query string is more your type: GET /foil?mach=3&angle=37.000 =end class Foil def get lift = input.mach * input.angle # etc end end =begin i think the ST of REST stands for "state transfer" - which is more accurate and easy in JSON than query-string vars: in JS+jQuery: function rpc(o) { $.ajax($.extend({ url : '/foil', type : "post", contentType: 'application/json', dataType : 'json', data:$.toJSON({mach: 3, forces: [0.00024, 1.33343, 6.777156]}), processData: false, beforeSend: function(xml) { xml.setRequestHeader("Accept", "application/json"); } },o)) } in camping: =end class Foil def post @mach, @f = input.mach, input.forces end end end module Aero def service *a if @method == "post" and @env.CONTENT_TYPE == 'application/json' @input = JSON.parse(@in.read) end super *a end end =begin and now you can share any object between ECMAscript and Ruby, as long as you stick to floats, ints, strings, arrays, hashes.. what business does your REST server have generating HTML anwyays? its there just to provide calculating service.. =end module Aero::Controllers class Foil def post @headers['Content-Type'] = @env[:HTTP_ACCEPT] # do some heavy lifting {:lift => lift, :drag => drag, :pitch => pitch}.to_json end end end =begin because you set 'dataType' to 'json' in jQuery's AJAJ options, you get the object passed to the success callback: rpc({success: function(r){ $("#yaw").text(r.pitch * r.skew) }}) this gives you an overview of 1 old fashioned (querystring) 1 camping-fashioned (custom URIs defined via regex) and 1 neo-classical (JSON RPC via post) means to REST while camping. i've skipped over POST and HTML forms. since its identical to querystring except the string is in the POST body instead of appended to the URL. ive also skipped custom methods (you could 'def foil' in your controller if you only wanted it to respond to FOIL requests intead of GET requests) which may be useful if you dont want your app to appear to work to RFC compliant web browsers.. cheers! and happy camping. =end From Bil.Kleb at NASA.gov Sun Apr 29 05:13:13 2007 From: Bil.Kleb at NASA.gov (Bil Kleb) Date: Sun, 29 Apr 2007 05:13:13 -0400 Subject: RESTful web service tutorial? In-Reply-To: <60D02724-6117-4238-BC0D-D5E7FE9B6535@cpb.ca> References: <4633A2B1.1010107@NASA.gov> <4633B0FA.9000306@NASA.gov> <60D02724-6117-4238-BC0D-D5E7FE9B6535@cpb.ca> Message-ID: <463461A9.7030005@NASA.gov> Caleb Buxton wrote: > > With regards to implementing it in Camping... > > This thread includes discussion about getting Camping to recognize > other predicates > > http://www.mail-archive.com/camping-list at rubyforge.org/msg00029.html I had managed to find that (searching for "restful camping" is tricky), but I didn't make much sense of it yet... > Otherwise, some problems with using semicolons to access different > aspects ( http://code.whytheluckystiff.net/camping/ticket/118 ) which > is, according to the people talking there, a rails-ish thing anyways. Which is apparently gone for Rails 2.0: http://pragdave.pragprog.com/pragdave/2007/03/change_to_rest_.html > Hope this helps, Yes, thank you. > ps: is the airfoil calculator going to be publicly available...? :) Yes, if I can muscle my way past our layers of red tape. Thanks again, -- Bil Kleb http://fun3d.larc.nasa.gov From Bil.Kleb at NASA.gov Sun Apr 29 05:29:44 2007 From: Bil.Kleb at NASA.gov (Bil Kleb) Date: Sun, 29 Apr 2007 05:29:44 -0400 Subject: RESTful web service tutorial? In-Reply-To: <20070428220834.GC22812@replic.net> References: <4633A2B1.1010107@NASA.gov> <4633B0FA.9000306@NASA.gov> <20070428220834.GC22812@replic.net> Message-ID: <46346588.3030807@NASA.gov> carmen wrote: > > i still don't know exactly what REST is (maybe there is no exact definition), I suppose the definitive source is one of the few PhD dissertations that are worth something (mine wasn't): http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm > camping makes playing with all this easy That was my hypothesis, nice to have confirmation... > module Aero::Controllers > class Foil < R '/foil/([^/]+)/([^/]+)/([^/]+)' > def get geo, angle, mach > # do some math here and return results > end > end > > [..] > > you would do something like GET /foil/1/90.000/3 in this case, > > or perhaps query string is more your type: > > GET /foil?mach=3&angle=37.000 Simple enough, thanks. > [..] > > this gives you an overview of 1 old fashioned (querystring) 1 camping-fashioned > (custom URIs defined via regex) and 1 neo-classical (JSON RPC via post) means > to REST while camping. [..] You lost me with most of this, as I am not a hard-core web programmer, but it is comforting to see the similarities in the different tacks. Thanks again, -- Bil Kleb http://fun3d.larc.nasa.gov From michael.daines at gmail.com Sun Apr 29 13:34:09 2007 From: michael.daines at gmail.com (Michael Daines) Date: Sun, 29 Apr 2007 10:34:09 -0700 Subject: RESTful web service tutorial? In-Reply-To: <46346588.3030807@NASA.gov> References: <4633A2B1.1010107@NASA.gov> <4633B0FA.9000306@NASA.gov> <20070428220834.GC22812@replic.net> <46346588.3030807@NASA.gov> Message-ID: <21e451680704291034y1095c06yc63805f0fb6f9e22@mail.gmail.com> Just to chime in, this is related-but-not-quite, I've been working off and on on a little library for Rails-style RESTful controllers. It's called "Sleeping Bag": http://code.google.com/p/sleepingbag It's not quite ready yet, so don't expect it to work well, but I thought maybe someone would find it interesting. It basically just maps HTTP actions and the stuff in the path to methods on your controllers. You could have a controller like this: class Planes < R '/planes', '/planes/([^\/]+)', '/planes/([^\/]+)/([^\/]+)' include SleepingBag def index @planes = Plane.find(:all) render :planes_index end def show(id) @plane = Plane.find(id) render :show_plane end end "GET /planes" and "GET /planes/747" are mapped to the index and show methods, respectively, based on the methods' arity and the fact that index and show are defined by default to be "standard actions", those represented by just an HTTP method, not an aspect. (I'm doing aspects without semicolons, like Rails now is.) Aspects and other standard methods are defined by defining methods, mapped to GET by default. So, to continue with the Planes controller... def wingspan(id) @plane = Plane.find(id) render :plane_wingspan end This would map to "GET /planes/747/wingspan". To fly a plane: methods[:fly] = [:post] def fly(id) @plane = Plane.find(id) @plane.fly! "Bon voyage!" end This means that only "POST /planes/747/fly" will call the fly action. I want to make declaration of controllers simpler, like this: class Planes < ZZZ def index # ... end # ... end Coming soon, possibly... -- Michael Daines From jonathan.stott at gmail.com Sun Apr 29 18:47:34 2007 From: jonathan.stott at gmail.com (Jonathan Stott) Date: Sun, 29 Apr 2007 23:47:34 +0100 Subject: URL question Message-ID: <14cf210a0704291547sa18ec16yd9fe892d9a29f53f@mail.gmail.com> Well, this is more of an apache question, but... I'm running a nice little 'cluster' of camping apps and I've recently started proxying them through apache with mod_proxy, since I found I was forwarding a lot of ports via ssh otherwise. But anyway, enough of that. One of the apps I use to view logs from IRC (with formatting and highlighting!). But occasionally, there are +s in the channel name (and I can't just remove them, as sometimes the name exists without the + as well). And this works fine, with camping on it's own. But apache rewrites the + to %2B and it all falls apart. So if there are any apache gurus on the list, could they let me know how to stop this? Regards Jonathan From michael.gorsuch at gmail.com Mon Apr 30 10:22:49 2007 From: michael.gorsuch at gmail.com (Michael Gorsuch) Date: Mon, 30 Apr 2007 10:22:49 -0400 Subject: URL question In-Reply-To: <14cf210a0704291547sa18ec16yd9fe892d9a29f53f@mail.gmail.com> References: <14cf210a0704291547sa18ec16yd9fe892d9a29f53f@mail.gmail.com> Message-ID: <2a3f927b0704300722n53bf6be2t4a764966d1d16271@mail.gmail.com> Jonathan - I may be blowing smoke, but what about taking advantage of CGI's escape and unescape methods? irb(main):009:0> CGI.escape "ruby+talk" => "ruby%2Btalk" irb(main):010:0> CGI.unescape "ruby%2Btalk" => "ruby+talk" Would that do the trick? Just run CGI.unescape on your paramaters? On 4/29/07, Jonathan Stott wrote: > Well, this is more of an apache question, but... > > I'm running a nice little 'cluster' of camping apps and I've recently > started proxying them through apache with mod_proxy, since I found I > was forwarding a lot of ports via ssh otherwise. But anyway, enough of > that. > > One of the apps I use to view logs from IRC (with formatting and > highlighting!). But occasionally, there are +s in the channel name > (and I can't just remove them, as sometimes the name exists without > the + as well). And this works fine, with camping on it's own. But > apache rewrites the + to %2B and it all falls apart. > > So if there are any apache gurus on the list, could they let me know > how to stop this? > > Regards > Jonathan > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >