incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amine BENHAMZA <amine.benha...@gmail.com>
Subject Re: External process - Having trouble Half the time
Date Sun, 13 Feb 2011 18:25:43 GMT
Thanks Guys for you response.

That's my code :
require "rubygems"
require "resque"
require "tweetstream"
require 'job'

STDOUT.puts "{" + '"code":200' + "," + '"headers":{"Content-Type":""}' + ","
+ '"json":{}' + "}"

module Demo
  Resque.enqueue(Job, 'egypt')
end

STDOUT.flush

The next version of the code is to parameter the keyword (brought for form)
from STDIN. So I'll run this instead Resque.enqueue(Job, keyword). The Job
I'm putting in queue is Twitter Streaming for a given keyword(s).

At the origin, my script was :

require 'rubygems'
require 'tweetstream'
require 'couchrest'

STDOUT.puts "{" + '"code":200' + "," + '"headers":{"Content-Type":""}' + ","
+ '"json":{}' + "}"

@db = CouchRest::database!('trends_monitoring_bis')

#This will pull a sample of all tweets based on your Twitter account's
Streaming API role.
TweetStream::Client.new('aminedigirep','password').track('algerie') do
|status|
   puts "#{status.user.screen_name} : #{status.text}"

   @db.save_doc(status)
end

STDOUT.flush

This script works fine for the first call, once you run the script for
another keyword, It blocks the first call. So I decided to put my job in
queue and get back to couchdb to end the external process, so doing away
from couchdb.

*"the most common mistake is to forget to loop. an external handler is
expected to stay running for lots of requests, not exit on every
request like CGI."* I didn't know that. It make sens.

The "_changes" is good option. Do you know a good way to implement it ?
Node.js ? Another option ?
I found this example :
http://www.joeandmotorboat.com/2010/01/01/fun-with-the-couchdb-_changes-feed-and-rabbitmq/I
didn't get it very well. It uses Yajl and RabittMQ. I'll try to
combine
Yajl and Resque (very accessible a MQ engine).

Cheers !

On 13 February 2011 18:01, Robert Newson <robert.newson@gmail.com> wrote:

> I'd completely missed that content-type was set to "Content-Type". :)
>
> On 13 February 2011 16:40, Martin Hilbig <blueonyx@gmx.net> wrote:
> > hi,
> >
> > On 13.02.2011 16:55, Amine BENHAMZA wrote:
> >>
> >> Hello Guys,
> >>
> >> I'm working to launch an external process (ruby script) from couchdb.
> Half
> >> the time, I have this error : "error":"{noproc,{gen_server,call, (i omit
> >> the
> >> rest). The full log is here : https://gist.github.com/824762
> >>
> >> I'm launching the external process this way :
> >> http://127.0.0.1:5984/trends_monitoring3/_rts
> >>
> >> The code I'm running aims to add a Job to Resque queue (
> >> https://github.com/defunkt/resque) as done below :
> >>
> >> STDOUT.puts "{" + '"code":200' + "," +
> >> '"headers":{"Content-Type":"Content-Type"}' + "," + '"json":{}' + "}"
> >
> > i don't know whether this is a problem, but are you sure to set a
> > Content-Type header with value Content-Type not application/json? but
> then
> > you send a json body, i think you can simple omit the header.
> >
> > on the other hand your log suggests, that the caller expects
> text/html/xml
> > but not json, so maybe you want to change the "json":{} to "body":"".
> >
> > the last point: this script exits after it handled one request right? but
> > couchdb expects the _external to continue running and handlich more
> > requests, so you should put some loop around your code.
> >
> > others maybe would also suggest to use the _changes api instead ;)
> >
> > have fun
> > martin
> >
> >> module Demo
> >>   Resque.enqueue(Job, params)
> >> end
> >>
> >> STDOUT.flush
> >>
> >> Did someone face this issue ? Have you any idea about what could cause
> >> this
> >> ?
> >>
> >> Thanks
> >>
> >> Amine.
> >>
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message