Last active
December 13, 2015 22:59
-
-
Save bradleybuda/4988223 to your computer and use it in GitHub Desktop.
Meldium base class for Resque jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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