Class: Que::Job
Direct Known Subclasses
Constant Summary collapse
- MAXIMUM_TAGS_COUNT =
5
- MAXIMUM_TAG_LENGTH =
100
Class Attribute Summary collapse
-
.maximum_retry_count ⇒ Object
Job class configuration options.
-
.priority ⇒ Object
Job class configuration options.
-
.queue ⇒ Object
Job class configuration options.
-
.retry_interval ⇒ Object
Job class configuration options.
-
.run_at ⇒ Object
Job class configuration options.
-
.run_synchronously ⇒ Object
Job class configuration options.
Instance Attribute Summary collapse
-
#que_attrs ⇒ Object
readonly
Returns the value of attribute que_attrs.
-
#que_error ⇒ Object
Returns the value of attribute que_error.
-
#que_resolved ⇒ Object
Returns the value of attribute que_resolved.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Job
constructor
A new instance of Job.
-
#run(*args) ⇒ Object
Subclasses should define their own run methods, but keep an empty one here so that Que::Job.enqueue can queue an empty job in testing.
Methods included from JobMethods
Constructor Details
#initialize(attrs) ⇒ Job
Returns a new instance of Job.
33 34 35 36 |
# File 'lib/que/job.rb', line 33 def initialize(attrs) @que_attrs = attrs Que.internal_log(:job_instantiate, self) { attrs } end |
Class Attribute Details
.maximum_retry_count ⇒ Object
Job class configuration options.
52 53 54 |
# File 'lib/que/job.rb', line 52 def maximum_retry_count @maximum_retry_count end |
.priority ⇒ Object
Job class configuration options.
52 53 54 |
# File 'lib/que/job.rb', line 52 def priority @priority end |
.queue ⇒ Object
Job class configuration options.
52 53 54 |
# File 'lib/que/job.rb', line 52 def queue @queue end |
.retry_interval ⇒ Object
Job class configuration options.
52 53 54 |
# File 'lib/que/job.rb', line 52 def retry_interval @retry_interval end |
.run_at ⇒ Object
Job class configuration options.
52 53 54 |
# File 'lib/que/job.rb', line 52 def run_at @run_at end |
.run_synchronously ⇒ Object
Job class configuration options.
52 53 54 |
# File 'lib/que/job.rb', line 52 def run_synchronously @run_synchronously end |
Instance Attribute Details
#que_attrs ⇒ Object (readonly)
Returns the value of attribute que_attrs.
30 31 32 |
# File 'lib/que/job.rb', line 30 def que_attrs @que_attrs end |
#que_error ⇒ Object
Returns the value of attribute que_error.
31 32 33 |
# File 'lib/que/job.rb', line 31 def que_error @que_error end |
#que_resolved ⇒ Object
Returns the value of attribute que_resolved.
31 32 33 |
# File 'lib/que/job.rb', line 31 def que_resolved @que_resolved end |
Class Method Details
.enqueue(*args) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/que/job.rb', line 60 def enqueue(*args) args, kwargs = Que.split_out_ruby2_keywords(args) = kwargs.delete(:job_options) || {} if [:tags] if [:tags].length > MAXIMUM_TAGS_COUNT raise Que::Error, "Can't enqueue a job with more than #{MAXIMUM_TAGS_COUNT} tags! (passed #{[:tags].length})" end [:tags].each do |tag| if tag.length > MAXIMUM_TAG_LENGTH raise Que::Error, "Can't enqueue a job with a tag longer than 100 characters! (\"#{tag}\")" end end end attrs = { queue: [:queue] || resolve_que_setting(:queue) || Que.default_queue, priority: [:priority] || resolve_que_setting(:priority), run_at: [:run_at] || resolve_que_setting(:run_at), args: Que.serialize_json(args), kwargs: Que.serialize_json(kwargs), data: [:tags] ? Que.serialize_json(tags: [:tags]) : "{}", job_class: \ [:job_class] || name || raise(Error, "Can't enqueue an anonymous subclass of Que::Job"), } if attrs[:run_at].nil? && resolve_que_setting(:run_synchronously) attrs[:args] = Que.deserialize_json(attrs[:args]) attrs[:kwargs] = Que.deserialize_json(attrs[:kwargs]) attrs[:data] = Que.deserialize_json(attrs[:data]) _run_attrs(attrs) else values = Que.execute( :insert_job, attrs.values_at(:queue, :priority, :run_at, :job_class, :args, :kwargs, :data), ).first new(values) end end |
.resolve_que_setting(setting, *args) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/que/job.rb', line 117 def resolve_que_setting(setting, *args) value = send(setting) if respond_to?(setting) if !value.nil? value.respond_to?(:call) ? value.call(*args) : value else c = superclass if c.respond_to?(:resolve_que_setting) c.resolve_que_setting(setting, *args) end end end |
.run(*args) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/que/job.rb', line 105 def run(*args) # Make sure things behave the same as they would have with a round-trip # to the DB. args, kwargs = Que.split_out_ruby2_keywords(args) args = Que.deserialize_json(Que.serialize_json(args)) kwargs = Que.deserialize_json(Que.serialize_json(kwargs)) # Should not fail if there's no DB connection. _run_attrs(args: args, kwargs: kwargs) end |
Instance Method Details
#run(*args) ⇒ Object
Subclasses should define their own run methods, but keep an empty one here so that Que::Job.enqueue can queue an empty job in testing.
40 41 |
# File 'lib/que/job.rb', line 40 def run(*args) end |