Module: RocketJob::Plugins::Job::Model::ClassMethods
- Defined in:
- lib/rocket_job/plugins/job/model.rb
Instance Method Summary collapse
-
#collective_name ⇒ Object
Returns [String] the collective name for this job class.
-
#collective_name=(collective_name) ⇒ Object
Allow the collective name for this job class to be overridden.
-
#field(name, options) ⇒ Field
Defines all the fields that are accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
-
#from_properties(properties) ⇒ Object
Builds this job instance from the supplied properties hash.
-
#human_name ⇒ Object
Returns [String] the human readable name for this job class.
-
#human_name=(human_name) ⇒ Object
Allow the human readable job name for this job class to be overridden.
-
#queued_now ⇒ Object
Scope for queued jobs that can run now I.e.
-
#scheduled ⇒ Object
Scope for jobs scheduled to run in the future.
-
#underscore_name ⇒ Object
Returns [String] the singular name for this job class.
-
#underscore_name=(underscore_name) ⇒ Object
Allow the collective name for this job class to be overridden.
Instance Method Details
#collective_name ⇒ Object
Returns [String] the collective name for this job class
Example:
job = DataStudyJob.new
job.collective_name
# => "data_studies"
136 137 138 |
# File 'lib/rocket_job/plugins/job/model.rb', line 136 def collective_name @collective_name ||= name.sub(/Job$/, "").pluralize.underscore end |
#collective_name=(collective_name) ⇒ Object
Allow the collective name for this job class to be overridden
141 142 143 |
# File 'lib/rocket_job/plugins/job/model.rb', line 141 def collective_name=(collective_name) @collective_name = collective_name end |
#field(name, options) ⇒ Field
Defines all the fields that are accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/rocket_job/plugins/job/model.rb', line 173 def field(name, ) if (.delete(:user_editable) == true) && !user_editable_fields.include?(name.to_sym) self.user_editable_fields += [name.to_sym] end if .delete(:class_attribute) == true class_attribute(name, instance_accessor: false) public_send("#{name}=", [:default]) if .key?(:default) [:default] = -> { self.class.public_send(name) } end if (.delete(:copy_on_restart) == true) && !rocket_job_restart_attributes.include?(name.to_sym) self.rocket_job_restart_attributes += [name.to_sym] end super(name, ) end |
#from_properties(properties) ⇒ Object
Builds this job instance from the supplied properties hash. Overridden by batch to support child objects.
193 194 195 |
# File 'lib/rocket_job/plugins/job/model.rb', line 193 def from_properties(properties) new(properties) end |
#human_name ⇒ Object
Returns [String] the human readable name for this job class
Example:
job = DataStudyJob.new
job.human_name
# => "Data Study"
121 122 123 |
# File 'lib/rocket_job/plugins/job/model.rb', line 121 def human_name @human_name ||= name.sub(/Job$/, "").titleize end |
#human_name=(human_name) ⇒ Object
Allow the human readable job name for this job class to be overridden
126 127 128 |
# File 'lib/rocket_job/plugins/job/model.rb', line 126 def human_name=(human_name) @human_name = human_name end |
#queued_now ⇒ Object
Scope for queued jobs that can run now I.e. Queued jobs excluding scheduled jobs
152 153 154 |
# File 'lib/rocket_job/plugins/job/model.rb', line 152 def queued_now queued.and(RocketJob::Job.where(run_at: nil).or(:run_at.lte => Time.now)) end |
#scheduled ⇒ Object
Scope for jobs scheduled to run in the future
146 147 148 |
# File 'lib/rocket_job/plugins/job/model.rb', line 146 def scheduled queued.where(:run_at.gt => Time.now) end |
#underscore_name ⇒ Object
Returns [String] the singular name for this job class
Example:
job = DataStudyJob.new
job.underscore_name
# => "data_study"
106 107 108 |
# File 'lib/rocket_job/plugins/job/model.rb', line 106 def underscore_name @underscore_name ||= name.sub(/Job$/, "").underscore end |
#underscore_name=(underscore_name) ⇒ Object
Allow the collective name for this job class to be overridden
111 112 113 |
# File 'lib/rocket_job/plugins/job/model.rb', line 111 def underscore_name=(underscore_name) @underscore_name = underscore_name end |