lib/rocket_job/plugins/job/model.rb in rocketjob-3.4.3 vs lib/rocket_job/plugins/job/model.rb in rocketjob-3.5.0

- old
+ new

@@ -7,11 +7,11 @@ module Model extend ActiveSupport::Concern included do # Fields that are end user editable. - # For example are editable in Rocket Job Mission Control. + # For example are editable in Rocket Job Web Interface. class_attribute :user_editable_fields, instance_accessor: false self.user_editable_fields = [] # Attributes to include when copying across the attributes to a new instance on restart. class_attribute :rocket_job_restart_attributes @@ -154,11 +154,11 @@ end # Scope for queued jobs that can run now # I.e. Queued jobs excluding scheduled jobs def queued_now - queued.or({:run_at => nil}, {:run_at.lte => Time.now}) + queued.or({run_at: nil}, :run_at.lte => Time.now) end # 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. @@ -180,14 +180,12 @@ if options.delete(:user_editable) == true self.user_editable_fields += [name.to_sym] unless user_editable_fields.include?(name.to_sym) end if options.delete(:class_attribute) == true class_attribute(name, instance_accessor: false) - if options.has_key?(:default) - public_send("#{name}=", options[:default]) - end - options[:default] = lambda { self.class.public_send(name) } + public_send("#{name}=", options[:default]) if options.key?(:default) + options[:default] = -> { self.class.public_send(name) } end if options.delete(:copy_on_restart) == true self.rocket_job_restart_attributes += [name.to_sym] unless rocket_job_restart_attributes.include?(name.to_sym) end super(name, options) @@ -246,11 +244,11 @@ end # Return [true|false] whether this job is sleeping. # I.e. No workers currently working on this job even if it is running. def sleeping? - running? && (worker_count == 0) + running? && worker_count.zero? end # Returns [Integer] the number of workers currently working on this job. def worker_count running? && worker_name.present? ? 1 : 0 @@ -261,36 +259,35 @@ running? && worker_name.present? ? [worker_name] : [] end # Returns [Hash] status of this job def as_json - attrs = serializable_hash(methods: [:seconds, :duration]) + attrs = serializable_hash(methods: %i[seconds duration]) attrs.delete('result') unless collect_output? - attrs.delete('failure_count') unless failure_count > 0 - case - when queued? + attrs.delete('failure_count') unless failure_count.positive? + if queued? attrs.delete('started_at') attrs.delete('completed_at') attrs.delete('result') attrs - when running? + elsif running? attrs.delete('completed_at') attrs.delete('result') attrs - when completed? + elsif completed? attrs.delete('percent_complete') attrs - when paused? + elsif paused? attrs.delete('completed_at') attrs.delete('result') # Ensure 'paused_at' appears first in the hash {'paused_at' => completed_at}.merge(attrs) - when aborted? + elsif aborted? attrs.delete('completed_at') attrs.delete('result') {'aborted_at' => completed_at}.merge(attrs) - when failed? + elsif failed? attrs.delete('completed_at') attrs.delete('result') {'failed_at' => completed_at}.merge(attrs) else attrs @@ -300,14 +297,13 @@ # Returns [Hash] the status of this job def status(time_zone = 'Eastern Time (US & Canada)') h = as_json h.delete('seconds') h.dup.each_pair do |k, v| - case - when v.is_a?(Time) + if v.is_a?(Time) h[k] = v.in_time_zone(time_zone).to_s - when v.is_a?(BSON::ObjectId) + elsif v.is_a?(BSON::ObjectId) h[k] = v.to_s end end h end @@ -315,10 +311,9 @@ # Returns [Boolean] whether the worker runs on a particular server. def worker_on_server?(server_name) return false unless worker_name.present? && server_name.present? worker_name.start_with?(server_name) end - end end end end