librelist archives

« back to archive

Writing to disk

Writing to disk

From:
Jonas Galvez
Date:
2009-11-07 @ 04:56
class SampleJob
  @queue = :test_queue
  def perform()
    handle = open('/tmp/counter.txt', 'a+')
    handle.seek(0)
    handle.write(handle.read.to_i.succ.to_s)
    handle.close()
  end
end

I'm trying Resque with the sample job above. I put that into the queue
and Resque's admin UI says it has processed without failing. Yet, I
see no /tmp/counter.txt file. If I run the same snippet off irb, it
works. Any clues? Just wondering if Resque's workers deliberately
disallow filesystem writing for whatever reason, or if I'm really
missing something.

Jonas Galvez

=-
http://jonasgalvez.com.br
http://github.com/galvez

Re: Writing to disk

From:
Chris Wanstrath
Date:
2009-11-07 @ 19:29
On Friday, November 6, 2009, Jonas Galvez <jonas@codeazur.com.br> wrote:

> class SampleJob
>   @queue = :test_queue
>   def perform()
>     handle = open('/tmp/counter.txt', 'a+')
>     handle.seek(0)
>     handle.write(handle.read.to_i.succ.to_s)
>     handle.close()
>   end
> end

I was just thinking about this today on an airplane.

The problem is this: Resque is looking for a class level 'perform'
method but you have defined an instance level method. If it can't find
the class method, it doesn't run the job.

I think Resque should raise an error if it can't find a class level
'perform' method. That would make this problem easier to debug.

So, basically, do this:

def self.perform
  blah
end

Chris

-- 
Chris Wanstrath
http://github.com/defunkt

Re: Writing to disk

From:
Chris Wanstrath
Date:
2009-11-11 @ 23:47
On Sat, Nov 7, 2009 at 11:29 AM, Chris Wanstrath <chris@ozmm.org> wrote:

> The problem is this: Resque is looking for a class level 'perform'
> method but you have defined an instance level method. If it can't find
> the class method, it doesn't run the job.
>
> I think Resque should raise an error if it can't find a class level
> 'perform' method. That would make this problem easier to debug.

Resque now behaves this way in Git:
http://github.com/defunkt/resque/commit/05bcde28e3f072c7048c2b68ab688e0c5a9c0379

-- 
Chris Wanstrath
http://github.com/defunkt

Re: Writing to disk

From:
Jonas Galvez
Date:
2009-11-07 @ 12:40
Figured it out, it should be self.perform(), not perform(), duh.

Sorry for the noise :)

--Jonas

On Sat, Nov 7, 2009 at 2:56 AM, Jonas Galvez <jonas@codeazur.com.br> wrote:
> class SampleJob
>   @queue = :test_queue
>   def perform()
>     handle = open('/tmp/counter.txt', 'a+')
>     handle.seek(0)
>     handle.write(handle.read.to_i.succ.to_s)
>     handle.close()
>   end
> end
>
> I'm trying Resque with the sample job above. I put that into the queue
> and Resque's admin UI says it has processed without failing. Yet, I
> see no /tmp/counter.txt file. If I run the same snippet off irb, it
> works. Any clues? Just wondering if Resque's workers deliberately
> disallow filesystem writing for whatever reason, or if I'm really
> missing something.
>
> Jonas Galvez
>
> =-
> http://jonasgalvez.com.br
> http://github.com/galvez
>