Created
August 7, 2017 17:02
-
-
Save EastResident/e20af7d59f746e229de6c1d1fd931a91 to your computer and use it in GitHub Desktop.
ARオブジェクトをURI化する`ActiveJob::Arguments#serialize`が色々と使えそう ref: http://qiita.com/EastResident/items/41a016ac97b8691a2aa3
This file contains 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
user = User.find(5) | |
SampleJob.perform_later(user) |
This file contains 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
serialized_args = ActiveJob::Arguments.serialize([user]) | |
〜〜〜 | |
略 | |
〜〜〜 | |
args = ActiveJob::Arguments.deserialize(serialized_args) |
This file contains 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
[{"_aj_globalid"=>"gid://project_name/User/5"}] |
This file contains 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
require 'active_job/arguments' |
This file contains 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
def store_sample(*args) | |
key = SecureRandom.hex(12) | |
serialized_args = ActiveJob::Arguments.serialize(args) | |
Rails.cache.fetch(key.to_s) { serialized_args } | |
end | |
store_sample(User.find(4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment