resque-job_history 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74efd65b38f6d08e25d24bce58b4fafa97e3136df8c0cef2b10177af4f85f17d
4
- data.tar.gz: 96e82ad40c7bd5d0371e6dc975296235e04a2e71eec4cb0646bd1f876f7cc24d
3
+ metadata.gz: 272a762705e9396cae975b8113183ae579557cf0e77412b6f4c1cb609ff0ff96
4
+ data.tar.gz: c9e0df1f067302a22ee086413f9fa57ae7a56f84cef52d29c27e5dc372336112
5
5
  SHA512:
6
- metadata.gz: 82be65f4e0c8e1dbe91b237b135f1cd375c22240849cc16a549cde3481681106a126988af8c4674c6c834efa139ca48193ab0240603a1eb89a84f4d66965aaaa
7
- data.tar.gz: 2de10d9d4f626e8d1ae32e1a3d4f589290badcf71979c846d353ab4b4eac7ecc183d8ebf0c97e750f85e15b95185c876f92738487aa22d3e46bd328435eedae4
6
+ metadata.gz: c5cb6a16f6808621408467ed6658822394c1b0eb395589dad5d41657747877b032dc17a12efea5915b8d4ea046b3d95c1af03db36d14b847a33b2b442b95dbe2
7
+ data.tar.gz: df26c5d144fd44da9f331399cd57e71fc9e0972fee60d7c304a5ed5a08eb2fa6599814870f1027d4263839c16620ee222358e6d1995c4e4c1c5f311f443c2332
@@ -51,6 +51,7 @@ module Resque
51
51
  end
52
52
 
53
53
  def around_perform_job_history(*args)
54
+ start_time = Time.now
54
55
  running_job = Resque::Plugins::JobHistory::Job.new(active_job_class_name(*args), SecureRandom.uuid)
55
56
  self.most_recent_job = running_job
56
57
 
@@ -59,12 +60,12 @@ module Resque
59
60
 
60
61
  yield if block_given?
61
62
 
62
- running_job.finish
63
+ running_job.finish(start_time, *args)
63
64
  rescue StandardError => exception
64
- running_job.failed exception
65
+ running_job.failed exception, start_time, *args
65
66
  raise
66
67
  ensure
67
- running_job.cancel unless running_job.finished? || running_job.error
68
+ running_job.cancel(" Job did not signal completion on finish.", start_time, *args) unless running_job.finished? || running_job.error
68
69
  self.most_recent_job = nil
69
70
  end
70
71
  end
@@ -99,18 +100,9 @@ module Resque
99
100
 
100
101
  private
101
102
 
102
- def job_class_has_history?(*args)
103
- if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper") &&
104
- self >= ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper
105
- args[-1]["job_class"].constantize.included_modules.include? Resque::Plugins::JobHistory
106
- else
107
- true
108
- end
109
- end
110
-
111
103
  def active_job_class_name(*args)
112
104
  if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper") &&
113
- self >= ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper
105
+ self >= "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize
114
106
  args[-1]["job_class"]
115
107
  else
116
108
  name
@@ -119,7 +111,7 @@ module Resque
119
111
 
120
112
  def active_job_args(*args)
121
113
  if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper") &&
122
- self >= ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper
114
+ self >= "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize
123
115
  args[-1]["arguments"]
124
116
  else
125
117
  args
@@ -144,8 +136,7 @@ module Resque
144
136
  end
145
137
 
146
138
  if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper")
147
- unless ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper.included_modules.
148
- include? Resque::Plugins::JobHistory
149
- ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper.include Resque::Plugins::JobHistory
139
+ unless "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize.included_modules.include? Resque::Plugins::JobHistory
140
+ "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize.include Resque::Plugins::JobHistory
150
141
  end
151
142
  end
@@ -109,8 +109,8 @@ module Resque
109
109
  running_jobs.jobs.each do |job|
110
110
  job_start = job.start_time
111
111
 
112
- if job_start.blank? || job_start.to_time < too_old_time
113
- job.cancel
112
+ if job_start.present? && job_start.to_time < too_old_time
113
+ job.cancel " Job timed out."
114
114
  end
115
115
  end
116
116
  end
@@ -33,7 +33,7 @@ module Resque
33
33
  end
34
34
 
35
35
  def duration
36
- (end_time || Time.now) - start_time
36
+ (end_time || Time.now) - (start_time || Time.now)
37
37
  end
38
38
 
39
39
  def end_time
@@ -45,7 +45,7 @@ module Resque
45
45
  end
46
46
 
47
47
  def uncompressed_args
48
- return args if described_class.blank?
48
+ return args if described_class.blank? || args.blank?
49
49
  return args unless described_class.singleton_class.included_modules.map(&:name).include?("Resque::Plugins::Compressible")
50
50
  return args unless described_class.compressed?(args)
51
51
 
@@ -57,7 +57,7 @@ module Resque
57
57
  end
58
58
 
59
59
  def start(*args)
60
- record_job_start(*args)
60
+ record_job_start(Time.now.utc.to_s, *args)
61
61
 
62
62
  num_jobs = running_jobs.add_job(job_id, class_name)
63
63
  linear_jobs.add_job(job_id, class_name) unless class_exclude_from_linear_history
@@ -67,10 +67,16 @@ module Resque
67
67
  self
68
68
  end
69
69
 
70
- def finish
71
- redis.hset(job_key, "end_time", Time.now.utc.to_s)
70
+ def finish(start_time = nil, *args)
71
+ if start_time.present?
72
+ record_job_start(start_time, *args)
73
+ end
74
+
75
+ if redis.exists(job_key)
76
+ redis.hset(job_key, "end_time", Time.now.utc.to_s)
77
+ finished_jobs.add_job(job_id, class_name)
78
+ end
72
79
 
73
- finished_jobs.add_job(job_id, class_name)
74
80
  running_jobs.remove_job(job_id)
75
81
 
76
82
  reset
@@ -78,18 +84,34 @@ module Resque
78
84
  self
79
85
  end
80
86
 
81
- def failed(exception)
82
- redis.hset(job_key, "error", exception_message(exception))
87
+ def failed(exception, start_time = nil, *args)
88
+ if start_time.present?
89
+ record_job_start(start_time, *args)
90
+ end
91
+
92
+ redis.hset(job_key, "error", exception_message(exception)) if redis.exists(job_key)
83
93
  redis.incr(total_failed_key)
84
94
 
85
95
  finish
86
96
  end
87
97
 
88
- def cancel
89
- redis.hset(job_key,
90
- "error",
91
- "Unknown - Job failed to signal ending after the configured purge time or "\
92
- "was canceled manually.")
98
+ def abort
99
+ running_jobs.remove_job(job_id)
100
+
101
+ reset
102
+ end
103
+
104
+ def cancel(caller_message = nil, start_time = nil, *args)
105
+ if start_time.present?
106
+ record_job_start(start_time, *args)
107
+ end
108
+
109
+ if redis.exists(job_key)
110
+ redis.hset(job_key,
111
+ "error",
112
+ "Unknown - Job failed to signal ending after the configured purge time or was canceled manually.#{caller_message}")
113
+ end
114
+
93
115
  redis.incr(total_failed_key)
94
116
 
95
117
  finish
@@ -111,7 +133,7 @@ module Resque
111
133
 
112
134
  def purge
113
135
  # To keep the counts honest...
114
- cancel unless finished?
136
+ abort unless finished?
115
137
 
116
138
  remove_from_job_lists
117
139
 
@@ -136,8 +158,8 @@ module Resque
136
158
  linear_jobs.remove_job(job_id)
137
159
  end
138
160
 
139
- def record_job_start(*args)
140
- redis.hset(job_key, "start_time", Time.now.utc.to_s)
161
+ def record_job_start(start_time, *args)
162
+ redis.hset(job_key, "start_time", start_time)
141
163
  redis.hset(job_key, "args", encode_args(*args))
142
164
 
143
165
  reset
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-job_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - RealNobody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-30 00:00:00.000000000 Z
11
+ date: 2020-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque