web47command 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/app/models/command_job.rb +88 -42
- data/lib/web47command/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4c9af98c7b86e879a9885c598141652ba58bf95a2c356067d55e3af5e8178c3
|
4
|
+
data.tar.gz: cc1fcf8e729041d1273908c1da76bbd9810af5206d234335aab5b56fd7ff0587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d36c06edcaf174da4ff360a2842e86c6bd1c6c47ced6cb60567fa0623c279bbffda43bee966f479226b1928434aa62309964f5b7214d27236d232a86adb570c0
|
7
|
+
data.tar.gz: d4a92dd44cd66e1f352dcdc64bd076c32453c09989ef693d15601710584eec3d8f2b7e690ec4f636d0b2404013428c89510157f00597b3093a41374769c59b12
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ class CommandJob
|
|
41
41
|
# Who started this job
|
42
42
|
#
|
43
43
|
def display_started_by
|
44
|
-
started_by.present? ? started_by.
|
44
|
+
started_by.present? ? started_by.name : 'System'
|
45
45
|
end
|
46
46
|
|
47
47
|
#
|
@@ -62,113 +62,158 @@ class CommandJob
|
|
62
62
|
# True if in new status
|
63
63
|
#
|
64
64
|
def new_job?
|
65
|
-
|
65
|
+
job_state?(STATE_NEW)
|
66
66
|
end
|
67
67
|
|
68
68
|
#
|
69
69
|
# True if in WIP status
|
70
70
|
#
|
71
71
|
def work_in_progress?
|
72
|
-
[
|
72
|
+
job_state?([STATE_WIP, STATE_RETRYING])
|
73
73
|
end
|
74
74
|
|
75
75
|
#
|
76
76
|
# True if in success status
|
77
77
|
#
|
78
78
|
def succeeded?
|
79
|
-
|
79
|
+
job_state?(STATE_SUCCESS)
|
80
80
|
end
|
81
81
|
|
82
82
|
#
|
83
83
|
# True if in fail status
|
84
84
|
#
|
85
|
-
def
|
86
|
-
|
85
|
+
def failure?
|
86
|
+
job_state?(STATE_FAIL)
|
87
87
|
end
|
88
88
|
|
89
89
|
#
|
90
90
|
# If we is finished, failed or success
|
91
91
|
#
|
92
92
|
def completed?
|
93
|
-
[STATE_CANCELLED, STATE_FAIL, STATE_SUCCESS]
|
93
|
+
job_state?([STATE_CANCELLED, STATE_FAIL, STATE_SUCCESS])
|
94
94
|
end
|
95
95
|
|
96
96
|
#
|
97
97
|
# Job has not finished, failure or success
|
98
98
|
#
|
99
|
-
def
|
99
|
+
def running?
|
100
100
|
!completed?
|
101
101
|
end
|
102
102
|
|
103
|
-
alias
|
103
|
+
alias incomplete? running?
|
104
104
|
|
105
105
|
#
|
106
106
|
# If we are cancelled
|
107
107
|
#
|
108
108
|
def cancelled?
|
109
|
-
|
109
|
+
job_state?(STATE_CANCELLED)
|
110
110
|
end
|
111
111
|
|
112
|
-
def
|
113
|
-
|
114
|
-
job.cancelled?
|
115
|
-
rescue StandardError => error
|
116
|
-
App47Logger.log_warn "Unable to check job cancelled #{job}", error
|
117
|
-
true
|
112
|
+
def failure_or_cancelled?
|
113
|
+
job_state?([STATE_FAIL, STATE_CANCELLED], true)
|
118
114
|
end
|
119
115
|
|
120
|
-
|
121
|
-
|
122
|
-
|
116
|
+
#
|
117
|
+
# Fetch the latest version of this instance from the database and check the state against the required
|
118
|
+
# state. If there is a match, then return true, otherwise return false.
|
119
|
+
# If there is an error, return the default.
|
120
|
+
#
|
121
|
+
def job_state?(states, default = false)
|
122
|
+
states.is_a?(Array) ? states.include?(state) : states.eql?(state)
|
123
123
|
rescue StandardError => error
|
124
|
-
App47Logger.log_warn "Unable to check job cancelled #{
|
125
|
-
|
124
|
+
App47Logger.log_warn "Unable to check job failed or cancelled #{self.inspect}", error
|
125
|
+
default
|
126
126
|
end
|
127
127
|
|
128
128
|
#
|
129
129
|
# Return the job's status and information in a hash that could be used to return to a calling
|
130
130
|
# api
|
131
131
|
#
|
132
|
-
def
|
132
|
+
def current_status
|
133
133
|
status = { state: state }
|
134
134
|
status[:message] = error_message if error_message.present?
|
135
135
|
status
|
136
136
|
end
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
138
|
+
#
|
139
|
+
# Perform this job in the background
|
140
|
+
#
|
141
|
+
def perform_later
|
142
|
+
perform
|
143
|
+
end
|
144
|
+
|
145
|
+
handle_asynchronously :perform_later
|
146
|
+
|
147
|
+
#
|
148
|
+
# Steps to execute before a run
|
149
|
+
#
|
150
|
+
def before_run
|
151
|
+
case state
|
152
|
+
when STATE_NEW
|
153
|
+
set retries: 0,
|
154
|
+
started_at: Time.now.utc,
|
155
|
+
finished_at: nil,
|
156
|
+
error_message: nil,
|
157
|
+
result: nil,
|
158
|
+
state: STATE_WIP
|
159
|
+
when STATE_RETRYING
|
160
|
+
set retries: 0,
|
161
|
+
started_at: Time.now.utc,
|
162
|
+
finished_at: nil,
|
163
|
+
error_message: nil,
|
164
|
+
result: nil
|
165
|
+
else
|
166
|
+
set retries: 0, started_at: Time.now.utc, finished_at: nil, result: nil
|
142
167
|
end
|
168
|
+
end
|
143
169
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
170
|
+
#
|
171
|
+
# Steps to execute after a run
|
172
|
+
#
|
173
|
+
def after_run
|
174
|
+
case state
|
175
|
+
when STATE_RETRYING, STATE_WIP
|
176
|
+
set finished_at: Time.now.utc, error_message: nil, state: STATE_SUCCESS
|
177
|
+
when STATE_SUCCESS
|
178
|
+
set finished_at: Time.now.utc, error_message: nil
|
179
|
+
else
|
180
|
+
set finished_at: Time.now.utc
|
150
181
|
end
|
151
182
|
end
|
152
183
|
|
184
|
+
#
|
185
|
+
#
|
186
|
+
# Perform the command job
|
187
|
+
#
|
188
|
+
def perform
|
189
|
+
before_run
|
190
|
+
run
|
191
|
+
after_run
|
192
|
+
rescue StandardError => error
|
193
|
+
log_error 'Unable to start job', error
|
194
|
+
set state: STATE_FAIL, error_message: error.message
|
195
|
+
end
|
196
|
+
|
197
|
+
alias perform_now perform
|
198
|
+
|
199
|
+
|
200
|
+
#
|
201
|
+
# Run the job, handling any failures that might happen
|
202
|
+
#
|
153
203
|
def run
|
154
|
-
|
155
|
-
# Run the job
|
156
|
-
run!
|
157
|
-
set error_message: '', state: STATE_SUCCESS, finished_at: Time.now.utc
|
204
|
+
run! unless cancelled?
|
158
205
|
rescue StandardError => error
|
159
|
-
if retries >= max_retries
|
206
|
+
if (retries + 1) >= max_retries
|
160
207
|
log_error "Unable to run job id: #{id}, done retrying", error
|
161
|
-
set state: STATE_FAIL, error_message: "Failed final attempt: #{error.message}"
|
208
|
+
set state: STATE_FAIL, error_message: "Failed final attempt: #{error.message}"
|
162
209
|
else
|
163
210
|
log_error "Unable to run job id: #{id}, retrying!!", error
|
164
211
|
add_log "Unable to run job: #{error.message}, retrying!!"
|
165
|
-
set error_message: "Failed attempt # #{retries}: #{error.message}", retries: retries + 1
|
166
|
-
|
212
|
+
set error_message: "Failed attempt # #{retries}: #{error.message}", retries: retries + 1, state: STATE_RETRYING
|
213
|
+
run
|
167
214
|
end
|
168
215
|
end
|
169
216
|
|
170
|
-
handle_asynchronously :run if Delayed::Worker.delay_jobs
|
171
|
-
|
172
217
|
#
|
173
218
|
# Determine the correct action to take and get it started
|
174
219
|
#
|
@@ -311,4 +356,5 @@ class CommandJob
|
|
311
356
|
def sort_fields
|
312
357
|
%i[created_at]
|
313
358
|
end
|
359
|
+
|
314
360
|
end
|
data/lib/web47command/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web47command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Schroeder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|