lib/rocket_job/plugins/job/model.rb in rocketjob-3.4.0 vs lib/rocket_job/plugins/job/model.rb in rocketjob-3.4.1

- old
+ new

@@ -43,11 +43,11 @@ # Whether to store the results from this job field :collect_output, type: Boolean, default: false, class_attribute: true # Run this job no earlier than this time - field :run_at, type: Time + field :run_at, type: Time, user_editable: true # If a job has not started by this time, destroy it field :expires_at, type: Time, copy_on_restart: true # Raise or lower the log level when calling the job @@ -241,9 +241,25 @@ end # Returns [true|false] whether the job is scheduled to run in the future def scheduled? queued? && run_at.present? && (run_at > Time.now) + 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) + end + + # Returns [Integer] the number of workers currently working on this job. + def worker_count + running? && worker_name.present? ? 1 : 0 + end + + # Returns [Array<String>] names of workers currently working this job. + def worker_names + running? && worker_name.present? ? [worker_name] : [] end # Returns [Hash] status of this job def as_json attrs = serializable_hash(methods: [:seconds, :duration])