lib/rocket_job/plugins/job/model.rb in rocketjob-2.0.0.rc2 vs lib/rocket_job/plugins/job/model.rb in rocketjob-2.0.0.rc3
- old
+ new
@@ -185,10 +185,11 @@
@rocket_job_properties ||= (self == RocketJob::Job ? [] : superclass.rocket_job_properties)
end
# Add to user definable properties in Dirmon Entry
def self.public_rocket_job_properties(*properties)
+ properties.each { |property| raise("Invalid public_rocket_job_property: #{property.inspect}") unless key?(property)}
rocket_job_properties.concat(properties).uniq!
end
# User definable properties in Dirmon Entry
public_rocket_job_properties :description, :priority, :log_level, :arguments
@@ -235,20 +236,24 @@
# Returns [Hash] status of this job
def as_json
attrs = serializable_hash(methods: [:seconds, :duration])
attrs.delete('result') unless collect_output?
+ attrs.delete('failure_count') unless failure_count > 0
case
when queued?
attrs.delete('started_at')
attrs.delete('completed_at')
attrs.delete('result')
attrs
when running?
attrs.delete('completed_at')
attrs.delete('result')
attrs
+ when completed?
+ attrs.delete('percent_complete')
+ attrs
when paused?
attrs.delete('completed_at')
attrs.delete('result')
# Ensure 'paused_at' appears first in the hash
{'paused_at' => completed_at}.merge(attrs)
@@ -267,11 +272,9 @@
# Returns [Hash] the status of this job
def status(time_zone = 'Eastern Time (US & Canada)')
h = as_json
h.delete('seconds')
- h.delete('percent_complete') if completed?
- h.delete('failure_count') unless failure_count > 0
h.dup.each_pair do |k, v|
case
when v.is_a?(Time)
h[k] = v.in_time_zone(time_zone).to_s
when v.is_a?(BSON::ObjectId)