这些方法将被包含在任何 Active Job 对象中,提供用于作业实例的序列化/反序列化和创建的辅助方法。
方法
- D
- S
实例公共方法
deserialize(job_data) 链接
从 serialize 创建的哈希创建新的作业实例。
源: 显示 | 在 GitHub 上
# File activejob/lib/active_job/core.rb, line 69 def deserialize(job_data) job_class = job_data["job_class"].safe_constantize raise UnknownJobClassError, job_data["job_class"] unless job_class job = job_class.new job.deserialize(job_data) job end
set(options = {}) 链接
创建一个预先配置了给定选项的作业。您可以调用 perform_later 并传入作业参数,以带有预配置选项的作业进行排队。
选项¶ ↑
-
:wait- 延迟指定的时间安排作业入队。 -
:wait_until- 在指定的时间入队作业 -
:queue- 在指定的队列上入队作业 -
:priority- 以指定的优先级入队作业
示例¶ ↑
VideoJob.set(queue: :some_queue).perform_later(Video.last) VideoJob.set(wait: 5.minutes).perform_later(Video.last) VideoJob.set(wait_until: Time.now.tomorrow).perform_later(Video.last) VideoJob.set(queue: :some_queue, wait: 5.minutes).perform_later(Video.last) VideoJob.set(queue: :some_queue, wait_until: Time.now.tomorrow).perform_later(Video.last) VideoJob.set(queue: :some_queue, wait: 5.minutes, priority: 10).perform_later(Video.last)
源: 显示 | 在 GitHub 上
# File activejob/lib/active_job/core.rb, line 96 def set(options = {}) ConfiguredJob.new(self, options) end