tasks_scheduler 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/tasks_scheduler.scss +4 -0
- data/app/controllers/scheduled_tasks_controller.rb +1 -1
- data/app/models/scheduled_task/checker.rb +21 -5
- data/app/models/scheduled_task/runner.rb +12 -4
- data/app/models/scheduled_task/status.rb +6 -9
- data/app/models/scheduled_task.rb +7 -3
- data/db/migrate/20180223155025_add_last_fail_status_to_scheduled_tasks.rb +5 -0
- data/lib/tasks_scheduler/version.rb +1 -1
- data/test/dummy/db/schema.rb +2 -1
- data/test/models/scheduled_task_test.rb +5 -2
- metadata +31 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92bc6ed859a0f11435e932c9e9d2054c53c1067e
|
4
|
+
data.tar.gz: acdf9fe30cbeb5a1f3cb7c74e4ffca03ecff4734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d96061f6d2ddda365979479751fdc427783d337ae8040b67203e5112be67015aa5b850f289eaa0b5ace1743bfe4811fb594d0898c338737820628cd7dd426095
|
7
|
+
data.tar.gz: fd2e663c7f5a202972116057e345b6a67c3f66feb15422a2ffc0ddb39eb421646c9a4f2880b5aa0c94187663a49ac13fb1b7b408bed6293c78b2b125353527a2
|
@@ -9,7 +9,7 @@ class ScheduledTasksController < ApplicationController
|
|
9
9
|
|
10
10
|
active_scaffold :scheduled_task do |conf|
|
11
11
|
[:create, :update, :list].each do |action|
|
12
|
-
conf.send(action).columns.exclude(:next_run, :last_run_start,
|
12
|
+
conf.send(action).columns.exclude(:next_run, :last_fail_status, :last_run_start,
|
13
13
|
:last_run_successful_start, :last_run_unsuccessful_start,
|
14
14
|
:last_run_successful_end, :last_run_unsuccessful_end,
|
15
15
|
:pid)
|
@@ -4,10 +4,25 @@ class ScheduledTask < ActiveRecord::Base
|
|
4
4
|
module Checker
|
5
5
|
def check
|
6
6
|
check_banner
|
7
|
+
if pid.present?
|
8
|
+
check_on_pid_present
|
9
|
+
else
|
10
|
+
check_on_pid_not_present
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def check_on_pid_present
|
7
17
|
if process_running?
|
8
|
-
check_log(
|
9
|
-
|
18
|
+
check_log('Already running')
|
19
|
+
else
|
20
|
+
check_log('Aborted')
|
21
|
+
on_end_running(Exception.new("Aborted (PID: #{pid} not found)"), STATUS_ABORTED)
|
10
22
|
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_on_pid_not_present
|
11
26
|
if next_run.present?
|
12
27
|
check_task_with_next_run
|
13
28
|
else
|
@@ -15,14 +30,15 @@ class ScheduledTask < ActiveRecord::Base
|
|
15
30
|
end
|
16
31
|
end
|
17
32
|
|
18
|
-
private
|
19
|
-
|
20
33
|
def check_log(message, method = :info)
|
21
34
|
Rails.logger.send(method, "TASK_CHECK(#{id}): #{message}")
|
22
35
|
end
|
23
36
|
|
24
37
|
def check_banner
|
25
38
|
check_log("Task: #{self}")
|
39
|
+
check_log("PID: #{pid}")
|
40
|
+
check_log("Running? #{process_running?}")
|
41
|
+
check_log("Last fail status: #{last_fail_status}")
|
26
42
|
end
|
27
43
|
|
28
44
|
def check_task_without_next_run
|
@@ -48,7 +64,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
48
64
|
spawn_pid = Process.spawn(*params)
|
49
65
|
end
|
50
66
|
Process.detach(spawn_pid)
|
51
|
-
update_attributes!(pid: spawn_pid)
|
67
|
+
update_attributes!(pid: spawn_pid, last_fail_status: nil)
|
52
68
|
end
|
53
69
|
end
|
54
70
|
end
|
@@ -6,18 +6,26 @@ class ScheduledTask < ActiveRecord::Base
|
|
6
6
|
return if process_running? && pid != Process.pid
|
7
7
|
status_on_start
|
8
8
|
exception = invoke_task
|
9
|
+
on_end_running(exception, STATUS_FAILED)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def on_end_running(exception, last_fail_status)
|
9
15
|
run_log(exception, :fatal) if exception
|
10
|
-
status_on_end(exception)
|
16
|
+
status_on_end(exception, last_fail_status)
|
11
17
|
log_on_end(exception)
|
12
18
|
run_log("Next run: #{next_run.in_time_zone}")
|
13
19
|
end
|
14
20
|
|
15
|
-
private
|
16
|
-
|
17
21
|
def run_log(message, method = :info)
|
18
22
|
if message.is_a?(Exception)
|
19
23
|
run_log("#{message.class}: #{message.message}")
|
20
|
-
|
24
|
+
if message.backtrace.present?
|
25
|
+
run_log(message.backtrace.join("\n"))
|
26
|
+
else
|
27
|
+
run_log('No backtrace present')
|
28
|
+
end
|
21
29
|
else
|
22
30
|
Rails.logger.send(method, "TASK_RUN(#{id}): #{message}")
|
23
31
|
end
|
@@ -3,8 +3,8 @@ class ScheduledTask < ActiveRecord::Base
|
|
3
3
|
def status
|
4
4
|
return STATUS_RUNNING if running?
|
5
5
|
return STATUS_WAITING if waiting?
|
6
|
-
return
|
7
|
-
|
6
|
+
return last_fail_status if last_fail_status.present?
|
7
|
+
raise "Unknown status (#{status_attributes_values})"
|
8
8
|
end
|
9
9
|
|
10
10
|
def running?
|
@@ -16,27 +16,24 @@ class ScheduledTask < ActiveRecord::Base
|
|
16
16
|
status_attributes.all? { |a| send(a).blank? }
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
ended?(last_run_unsuccessful_end, last_run_successful_end)
|
21
|
-
end
|
19
|
+
private
|
22
20
|
|
23
21
|
def ended?(time, oposite_time)
|
24
22
|
!running? && time.present? && (oposite_time.blank? || oposite_time < time)
|
25
23
|
end
|
26
24
|
|
27
|
-
private
|
28
|
-
|
29
25
|
def status_on_start
|
30
26
|
update_attributes!(last_run_start: Time.zone.now)
|
31
27
|
end
|
32
28
|
|
33
|
-
def status_on_end(exception)
|
29
|
+
def status_on_end(exception, last_fail_status)
|
34
30
|
update_attributes!(
|
35
31
|
next_run: calculate_next_run,
|
36
32
|
(exception ? :last_run_unsuccessful_start : :last_run_successful_start) => last_run_start,
|
37
33
|
(exception ? :last_run_unsuccessful_end : :last_run_successful_end) => Time.zone.now,
|
38
34
|
last_run_start: nil,
|
39
|
-
pid: nil
|
35
|
+
pid: nil,
|
36
|
+
last_fail_status: exception ? last_fail_status : nil
|
40
37
|
)
|
41
38
|
end
|
42
39
|
|
@@ -15,12 +15,16 @@ class ScheduledTask < ActiveRecord::Base
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
validates :scheduling, presence: true, 'tasks_scheduler/cron_scheduling': true
|
19
|
-
validates :task, presence: true, inclusion: { in: rake_tasks }
|
20
|
-
|
21
18
|
STATUS_RUNNING = 'running'
|
22
19
|
STATUS_FAILED = 'failed'
|
23
20
|
STATUS_WAITING = 'waiting'
|
21
|
+
STATUS_ABORTED = 'aborted'
|
22
|
+
|
23
|
+
LAST_FAIL_STATUSES = [STATUS_FAILED, STATUS_ABORTED]
|
24
|
+
|
25
|
+
validates :scheduling, presence: true, 'tasks_scheduler/cron_scheduling': true
|
26
|
+
validates :task, presence: true, inclusion: { in: rake_tasks }
|
27
|
+
validates :last_fail_status, allow_blank: true, inclusion: { in: LAST_FAIL_STATUSES }
|
24
28
|
|
25
29
|
LOG_RUNNING = 'running'
|
26
30
|
LOG_SUCCESSFUL = 'successful'
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20180223155025) do
|
15
15
|
|
16
16
|
create_table "scheduled_tasks", force: :cascade do |t|
|
17
17
|
t.string "scheduling"
|
@@ -26,6 +26,7 @@ ActiveRecord::Schema.define(version: 20161128163702) do
|
|
26
26
|
t.datetime "last_run_unsuccessful_end"
|
27
27
|
t.integer "pid"
|
28
28
|
t.string "args"
|
29
|
+
t.string "last_fail_status"
|
29
30
|
end
|
30
31
|
|
31
32
|
end
|
@@ -40,14 +40,17 @@ class ScheduledTaskTest < ActiveSupport::TestCase
|
|
40
40
|
@scheduled_task.send('status_on_start')
|
41
41
|
assert_equal ScheduledTask::STATUS_RUNNING, @scheduled_task.status
|
42
42
|
|
43
|
-
@scheduled_task.send('status_on_end', nil)
|
43
|
+
@scheduled_task.send('status_on_end', nil, nil)
|
44
44
|
assert_equal ScheduledTask::STATUS_WAITING, @scheduled_task.status
|
45
45
|
|
46
46
|
@scheduled_task.send('status_on_start')
|
47
47
|
assert_equal ScheduledTask::STATUS_RUNNING, @scheduled_task.status
|
48
48
|
|
49
|
-
@scheduled_task.send('status_on_end', StandardError.new('Test!'))
|
49
|
+
@scheduled_task.send('status_on_end', StandardError.new('Test!'), ScheduledTask::STATUS_FAILED)
|
50
50
|
assert_equal ScheduledTask::STATUS_FAILED, @scheduled_task.status
|
51
|
+
|
52
|
+
@scheduled_task.send('status_on_end', StandardError.new('Test!'), ScheduledTask::STATUS_ABORTED)
|
53
|
+
assert_equal ScheduledTask::STATUS_ABORTED, @scheduled_task.status
|
51
54
|
end
|
52
55
|
|
53
56
|
test 'task in list' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tasks_scheduler
|
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
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_scaffold
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- db/migrate/20161123130153_add_status_attributes_to_scheduled_tasks.rb
|
118
118
|
- db/migrate/20161124200712_add_pid_to_scheduled_tasks.rb
|
119
119
|
- db/migrate/20161128163702_add_args_to_scheduled_tasks.rb
|
120
|
+
- db/migrate/20180223155025_add_last_fail_status_to_scheduled_tasks.rb
|
120
121
|
- exe/tasks_scheduler
|
121
122
|
- exe/tasks_scheduler_run_task
|
122
123
|
- lib/tasks_scheduler.rb
|
@@ -184,46 +185,46 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
185
|
version: '0'
|
185
186
|
requirements: []
|
186
187
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.
|
188
|
+
rubygems_version: 2.4.8
|
188
189
|
signing_key:
|
189
190
|
specification_version: 4
|
190
191
|
summary: Scheduler for Rake tasks.
|
191
192
|
test_files:
|
192
|
-
- test/
|
193
|
-
- test/
|
193
|
+
- test/fixtures/scheduled_tasks.yml
|
194
|
+
- test/models/scheduled_task_test.rb
|
194
195
|
- test/dummy/config.ru
|
196
|
+
- test/dummy/README.rdoc
|
197
|
+
- test/dummy/db/schema.rb
|
198
|
+
- test/dummy/app/views/layouts/application.html.erb
|
199
|
+
- test/dummy/app/assets/stylesheets/application.css
|
200
|
+
- test/dummy/app/assets/javascripts/application.js
|
201
|
+
- test/dummy/app/helpers/application_helper.rb
|
202
|
+
- test/dummy/app/controllers/application_controller.rb
|
203
|
+
- test/dummy/bin/bundle
|
204
|
+
- test/dummy/bin/rails
|
205
|
+
- test/dummy/bin/setup
|
206
|
+
- test/dummy/bin/rake
|
207
|
+
- test/dummy/Rakefile
|
208
|
+
- test/dummy/config/environments/production.rb
|
209
|
+
- test/dummy/config/environments/test.rb
|
210
|
+
- test/dummy/config/environments/development.rb
|
211
|
+
- test/dummy/config/application.rb
|
195
212
|
- test/dummy/config/boot.rb
|
196
|
-
- test/dummy/config/database.yml
|
197
|
-
- test/dummy/config/secrets.yml
|
198
213
|
- test/dummy/config/locales/en.yml
|
199
|
-
- test/dummy/config/application.rb
|
200
|
-
- test/dummy/config/environments/development.rb
|
201
|
-
- test/dummy/config/environments/test.rb
|
202
|
-
- test/dummy/config/environments/production.rb
|
203
|
-
- test/dummy/config/environment.rb
|
204
|
-
- test/dummy/config/routes.rb
|
205
|
-
- test/dummy/config/initializers/assets.rb
|
206
|
-
- test/dummy/config/initializers/cookies_serializer.rb
|
207
|
-
- test/dummy/config/initializers/inflections.rb
|
208
214
|
- test/dummy/config/initializers/session_store.rb
|
209
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
210
215
|
- test/dummy/config/initializers/filter_parameter_logging.rb
|
216
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
211
217
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
218
|
+
- test/dummy/config/initializers/inflections.rb
|
219
|
+
- test/dummy/config/initializers/assets.rb
|
220
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
212
221
|
- test/dummy/config/initializers/mime_types.rb
|
213
|
-
- test/dummy/
|
214
|
-
- test/dummy/
|
215
|
-
- test/dummy/
|
216
|
-
- test/dummy/
|
217
|
-
- test/dummy/app/assets/stylesheets/application.css
|
218
|
-
- test/dummy/app/assets/javascripts/application.js
|
222
|
+
- test/dummy/config/secrets.yml
|
223
|
+
- test/dummy/config/database.yml
|
224
|
+
- test/dummy/config/routes.rb
|
225
|
+
- test/dummy/config/environment.rb
|
219
226
|
- test/dummy/public/422.html
|
220
|
-
- test/dummy/public/404.html
|
221
227
|
- test/dummy/public/favicon.ico
|
228
|
+
- test/dummy/public/404.html
|
222
229
|
- test/dummy/public/500.html
|
223
|
-
- test/dummy/bin/bundle
|
224
|
-
- test/dummy/bin/setup
|
225
|
-
- test/dummy/bin/rails
|
226
|
-
- test/dummy/bin/rake
|
227
230
|
- test/test_helper.rb
|
228
|
-
- test/fixtures/scheduled_tasks.yml
|
229
|
-
- test/models/scheduled_task_test.rb
|