Sha256: 320a2896a9e1d252a131f750c26b41124ae7360fc0c42fd8ab9e427a7d576490

Contents?: true

Size: 523 Bytes

Versions: 13

Compression:

Stored size: 523 Bytes

Contents

module CruLib
  module Async

    # This will be called by a worker when a job needs to be processed
    def perform(id, method, *args)
      if id
        begin
          self.class.find(id).send(method, *args)
        rescue ActiveRecord::RecordNotFound
          # If the record was deleted after the job was created, swallow it
        end
      else
        self.class.send(method, *args)
      end
    end

    def async(method, *args)
      Sidekiq::Client.enqueue(self.class, id, method, *args)
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cru_lib-0.1.2 lib/cru_lib/async.rb
cru_lib-0.1.1 lib/cru_lib/async.rb
cru_lib-0.1.0 lib/cru_lib/async.rb
cru_lib-0.0.2.4 lib/cru_lib/async.rb
cru_lib-0.0.2.3 lib/cru_lib/async.rb
cru_lib-0.0.2.2 lib/cru_lib/async.rb
cru_lib-0.0.2.1 lib/cru_lib/async.rb
cru_lib-0.0.6 lib/cru_lib/async.rb
cru_lib-0.0.5 lib/cru_lib/async.rb
cru_lib-0.0.4 lib/cru_lib/async.rb
cru_lib-0.0.3 lib/cru_lib/async.rb
cru_lib-0.0.2 lib/cru_lib/async.rb
cru_lib-0.0.1 lib/cru_lib/async.rb