Without your step through, I wouldn't have found it, thanks anyway!

Btw, isn't it a bit harsh to throw an error when puts is called in mongrel
service? Coz sometimes the 'puts' was called by core library, eg. This case
the Base64.

Right now, I'm applying a patch to my app to ignore the stderr/stdout, and
the app works fine now:

class StdOutLogger
  def write(s)
       # do nothing
    end
  end
end
  
before_filter {
  $stdout = $stderr = StdOutLogger.new
}

Was wondering, if there's variable to call to find out if the code is
running on mongrel_service? So I can do simple filtering only to ignore
sterr/out when running as a service.

If not is there a way to pass a variable when starting mongrel_service? I
tried 
mongrel_service console single -c
d:/rubywork/[appname]MONGREL_TYPE='service'

But no luck! :)

Herry

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Luis Lavena
Sent: 28 April 2007 12:06
To: mongrel-users@rubyforge.org
Subject: Re: [Mongrel] Win32 service - Errno::EINVAL
(Invalidargument)whenuploading image file

On 4/28/07, Herryanto Siatono <[EMAIL PROTECTED]> wrote:
> Thanks Luis, btw, I found some hints, it failed when the 'puts' statement
> was called.
>
> That's why the uploading of image failed, while other types are fine, when
I
> upload an image, I need to crop the image which instead call
> Base64.b64encode, in which "puts" was called to display the output on
> console.
>
> So I did a simple test, I added puts before the execution of anything, and
> it failed exactly at that line:
>
>   def with_image(file_data = nil, &block)
>     puts "testing"
>
>     img = Magick::Image::read_inline(Base64.b64encode(file_data ||
> self.data)).first
>     block.call(img)
>     img = nil
>     GC.start
>   end
>

Let me guess, the line :115 is actually... PUTS!

Err, a big problem with this. Let me explain.

A service, also known on *nix fields as "daemon", by default, lacks a
"console" attached to it. That means STDIN, STDOUT and STDERR.

These default "pipes" are used by sentences like puts, which "write"
data to the console.

Since you're inside a service... you don't have one! :-P

Also, lot of folks will correct me on this: adding puts in your code
for debugging purposes is a bad practice. Instead you should use
logger.debug/info/warn/error to log the event inside the
development/production log files.

So, replace puts "testing" with logger.debug "testing" and that should
work fine since is the only place you're using it ;-)

Anyway, next version of service add a workaround for this "bug by
design" of services.

>
> Now we are getting close, why puts failed when running as windows service?
> Note that it works fine when I'm running with "mongrel_rails start"
>
> And here are my answers to your questions. Thanks!
>
> [...]

Everything looks good, actually :-D

Your feedback allowed you to pinpoint where the problem lies, so you
almost solved the issue by yourself, so thank you instead! ;-)

Regards and good weekend.

-- 
Luis Lavena
Multimedia systems
-
Leaders are made, they are not born. They are made by hard effort,
which is the price which all of us must pay to achieve any goal that
is worthwhile.
Vince Lombardi
_______________________________________________
Mongrel-users mailing list
Mongrel-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-users

_______________________________________________
Mongrel-users mailing list
Mongrel-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-users

Reply via email to