Class: RudeQ::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/rude_q/worker.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.queueObject



57
58
59
# File 'lib/rude_q/worker.rb', line 57

def queue
  RudeQ::Scope.new(self.new.queue_name)
end

Instance Method Details

#do!Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/rude_q/worker.rb', line 33

def do!
  logger.info("starting up")
  if work = self.queue.get
    logger.info("found some work")
    do_work(work)
  else
    logger.info("couldn't find any work")
  end
  logger.info("finished for now")
end

#do_work(data) ⇒ Object

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/rude_q/worker.rb', line 29

def do_work(data)
  raise NotImplementedError
end

#loggerObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rude_q/worker.rb', line 44

def logger
  unless @logger
    @logger = Logger.new(RAILS_ROOT + "/log/#{self.class.to_s.underscore}_#{RAILS_ENV}.log")
    class << @logger
      def format_message(severity, timestamp, progname, msg)
        "#{timestamp.strftime('%Y%m%d-%H:%M:%S')} (#{$$}) #{msg}\n"
      end
    end
  end
  return @logger
end

#queueObject



62
63
64
# File 'lib/rude_q/worker.rb', line 62

def queue
  @queue ||= self.class.queue
end

#queue_nameObject

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/rude_q/worker.rb', line 25

def queue_name
  raise NotImplementedError
end