Sha256: ee7ee752df70c5b6cb593d87c8471ee6b6aef031f53a87fc5a509cfb6e81129b

Contents?: true

Size: 848 Bytes

Versions: 28

Compression:

Stored size: 848 Bytes

Contents

# If you want to just call a method on an object in the background,
# we can easily add that functionality to Resque.
#
# This is similar to DelayedJob's `send_later`.
#
# Keep in mind that, unlike DelayedJob, only simple Ruby objects
# can be persisted.
#
# If it can be represented in JSON, it can be stored in a job.

# Here's our ActiveRecord class
class Repository < ActiveRecord::Base
  # This will be called by a worker when a job needs to be processed
  def self.perform(id, method, *args)
    find(id).send(method, *args)
  end

  # We can pass this any Repository instance method that we want to
  # run later.
  def async(method, *args)
    Resque.enqueue(Repository, id, method, *args)
  end
end

# Now we can call any method and have it execute later:

@repo.async(:update_disk_usage)

# or

@repo.async(:update_network_source_id, 34)

Version data entries

28 entries across 28 versions & 6 rubygems

Version Path
opengotham_resque-1.8.2 examples/async_helper.rb
resque-mongo-1.8.1 examples/async_helper.rb
resque-1.8.0 examples/async_helper.rb
resque-1.7.1 examples/async_helper.rb
resque-1.7.0 examples/async_helper.rb
resque-1.6.1 examples/async_helper.rb
resque-1.6.0 examples/async_helper.rb
resque-1.5.2 examples/async_helper.rb
resque-1.5.1 examples/async_helper.rb
scotttam-resque-0.0.5 examples/async_helper.rb
scotttam-resque-0.0.4 examples/async_helper.rb
scotttam-resque-0.0.3 examples/async_helper.rb
scotttam-resque-0.0.2 examples/async_helper.rb
scotttam-resque-0.0.1 examples/async_helper.rb
grockit-resque-1.5.0 examples/async_helper.rb
resque-1.5.0 examples/async_helper.rb
resque-mongo-1.4.0 examples/async_helper.rb
resque-1.4.0 examples/async_helper.rb
resque-mongo-1.3.1 examples/async_helper.rb
resque-1.3.1 examples/async_helper.rb