Skip to content

Instantly share code, notes, and snippets.

@bradleybuda
Last active December 13, 2015 22:59
Show Gist options
  • Select an option

  • Save bradleybuda/4988223 to your computer and use it in GitHub Desktop.

Select an option

Save bradleybuda/4988223 to your computer and use it in GitHub Desktop.
Meldium base class for Resque jobs
class ExpensiveJob < Job
def perform
user = Service.find(options['id']).create_user
write_result(user.account_id)
end
end
# Usage
job_id, cache_key = ExpensiveJob.create
result = Rails.cache.read(cache_key) # Poll until non-nil
class Job
include Resque::Plugins::Status
def self.create(options)
cache_key = "JobResult/#{SecureRandom.hex}"
job_id = super(options.merge('cache_key' => cache_key))
[job_id, cache_key]
end
def write_result(result)
Rails.cache.write(options['cache_key'], result, expires_in: 10.minutes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment