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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48b30c798060f58365bfc12beb93db3972b529d9
4
- data.tar.gz: 2b875abb3eb4984f7a3a59590a0911c5cefb48fc
3
+ metadata.gz: 92bc6ed859a0f11435e932c9e9d2054c53c1067e
4
+ data.tar.gz: acdf9fe30cbeb5a1f3cb7c74e4ffca03ecff4734
5
5
  SHA512:
6
- metadata.gz: f7a07ad30c4510c9318231162c5c1f785ba398ab141e3bca282cac4d7560eca290aa450f1e7d4c181775679587637af36d1e3b0b56ed44d18005cb6304e15d93
7
- data.tar.gz: 205d290aef278c20bfa4e57ec279f00ab7d54ff7ded576d8b23221e0aedb87c079175e8fbca9b8391e9e2bdb1d74cd320881f46e5796da6048b81ec6fed05863
6
+ metadata.gz: d96061f6d2ddda365979479751fdc427783d337ae8040b67203e5112be67015aa5b850f289eaa0b5ace1743bfe4811fb594d0898c338737820628cd7dd426095
7
+ data.tar.gz: fd2e663c7f5a202972116057e345b6a67c3f66feb15422a2ffc0ddb39eb421646c9a4f2880b5aa0c94187663a49ac13fb1b7b408bed6293c78b2b125353527a2
@@ -26,6 +26,10 @@
26
26
  td.status_failed {
27
27
  color: red;
28
28
  }
29
+
30
+ td.status_aborted {
31
+ color: magenta;
32
+ }
29
33
  }
30
34
 
31
35
  .last_run {
@@ -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("Already running (PID: #{pid})")
9
- return
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
- run_log(message.backtrace.join("\n"))
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 STATUS_FAILED if failed?
7
- fail "Unknown status (#{status_attributes_values})"
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
- def failed?
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'
@@ -0,0 +1,5 @@
1
+ class AddLastFailStatusToScheduledTasks < ActiveRecord::Migration
2
+ def change
3
+ add_column :scheduled_tasks, :last_fail_status, :string
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module TasksScheduler
2
- VERSION = '0.0.7'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
@@ -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: 20161128163702) do
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.7
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-01-05 00:00:00.000000000 Z
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.6.12
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/dummy/Rakefile
193
- - test/dummy/README.rdoc
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/db/schema.rb
214
- - test/dummy/app/views/layouts/application.html.erb
215
- - test/dummy/app/controllers/application_controller.rb
216
- - test/dummy/app/helpers/application_helper.rb
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