Sha256: f2203c74a9c4fe803dea4ec14a8b2057fe003f698504baf3d5713532377479d7

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

#
# Create a client or a worker showing the serialization process.
#
# To run this example you should start a worker, then a client in a separate
# shell. Of course you'll also need a running RabbitMQ server.
#
# Use RABBITMQ_URL environment variable if you need to customize the RabbitMQ
# address.
#

$LOAD_PATH.unshift("./lib")

require "tennis"

require_relative "example"

class Model
  include Tennis::Worker::Deferable

  attr_reader :id

  def initialize(id)
    @id = id
  end

  def method(numbers)
    puts "At #{Time.now}, Model##{id} run method with #{numbers.inspect}\n"
  end

  # Usually the ORM provides this method. Here we're just faking it.
  def self.find(id)
    new(id)
  end

  # Usually the ORM provides this method. Here we're faking it too.
  def attributes
    { id: @id }
  end
end

Example.new(__FILE__, Model).run do |i|
  array = Array.new(5) { 1 + rand(5) }
  print "Press enter to enqueue a random array..." ; gets
  puts "Calling <Model##{i}>.method(#{array.inspect})"
  Model.new(i).defer.method(array)
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tennis-jobs-0.3.1 examples/deferable.rb
tennis-jobs-0.3.0 examples/deferable.rb
tennis-jobs-0.2.0 examples/deferable.rb
tennis-jobs-0.1.0 examples/deferable.rb