tasks_scheduler 0.0.8 → 0.0.9

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
  SHA1:
3
- metadata.gz: 92bc6ed859a0f11435e932c9e9d2054c53c1067e
4
- data.tar.gz: acdf9fe30cbeb5a1f3cb7c74e4ffca03ecff4734
3
+ metadata.gz: f1b92e7a9bc9fb0c7c43ef5a11422b51858a0466
4
+ data.tar.gz: af726dd48df8fec1ab31289023bbdad82b5dc3f7
5
5
  SHA512:
6
- metadata.gz: d96061f6d2ddda365979479751fdc427783d337ae8040b67203e5112be67015aa5b850f289eaa0b5ace1743bfe4811fb594d0898c338737820628cd7dd426095
7
- data.tar.gz: fd2e663c7f5a202972116057e345b6a67c3f66feb15422a2ffc0ddb39eb421646c9a4f2880b5aa0c94187663a49ac13fb1b7b408bed6293c78b2b125353527a2
6
+ metadata.gz: 3e46f79d1e2fdf7fef088126b0c2cefc2af3437a383e5ed1250c73a9a305f3d502e55684a2141712c752d33c5988bba969d83b0f9d1343e8cd5542172b84d552
7
+ data.tar.gz: 748695d547d7b1126263c00628233f5a1cb8beed84ef164d67b4e50fc99ee8638b68b0e39c48ee88a8923516c7e71dfe94cce677c0ca4073c6c0e416a3a80530
@@ -30,6 +30,10 @@
30
30
  td.status_aborted {
31
31
  color: magenta;
32
32
  }
33
+
34
+ td.status_timeout {
35
+ color: orange;
36
+ }
33
37
  }
34
38
 
35
39
  .last_run {
@@ -6,6 +6,9 @@ class ScheduledTask < ActiveRecord::Base
6
6
  include ::ScheduledTask::Runner
7
7
  include ::ScheduledTask::Status
8
8
 
9
+ DEFAULT_TIMEOUT_ENVVAR_NAME = 'TASKS_SCHEDULER_TIMEOUT'.freeze
10
+ DEFAULT_TIMEOUT = 12.hours
11
+
9
12
  class << self
10
13
  def rake_tasks
11
14
  @rake_tasks ||= begin
@@ -13,14 +16,24 @@ class ScheduledTask < ActiveRecord::Base
13
16
  Rake.application.tasks.map(&:name)
14
17
  end
15
18
  end
19
+
20
+ def timeout
21
+ @timeout ||= begin
22
+ r = Integer(ENV[DEFAULT_TIMEOUT_ENVVAR_NAME])
23
+ r > 0 ? r.seconds : DEFAULT_TIMEOUT
24
+ rescue ArgumentError, TypeError
25
+ DEFAULT_TIMEOUT
26
+ end
27
+ end
16
28
  end
17
29
 
18
30
  STATUS_RUNNING = 'running'
19
31
  STATUS_FAILED = 'failed'
20
32
  STATUS_WAITING = 'waiting'
21
33
  STATUS_ABORTED = 'aborted'
34
+ STATUS_TIMEOUT = 'timeout'
22
35
 
23
- LAST_FAIL_STATUSES = [STATUS_FAILED, STATUS_ABORTED]
36
+ LAST_FAIL_STATUSES = [STATUS_FAILED, STATUS_ABORTED, STATUS_TIMEOUT]
24
37
 
25
38
  validates :scheduling, presence: true, 'tasks_scheduler/cron_scheduling': true
26
39
  validates :task, presence: true, inclusion: { in: rake_tasks }
@@ -15,7 +15,12 @@ class ScheduledTask < ActiveRecord::Base
15
15
 
16
16
  def check_on_pid_present
17
17
  if process_running?
18
- check_log('Already running')
18
+ if timeout?
19
+ check_log('Timeout')
20
+ on_end_running(StandardError.new("Timeout (PID: #{pid}. running time: #{running_time})"), STATUS_TIMEOUT)
21
+ else
22
+ check_log('Already running')
23
+ end
19
24
  else
20
25
  check_log('Aborted')
21
26
  on_end_running(Exception.new("Aborted (PID: #{pid} not found)"), STATUS_ABORTED)
@@ -44,7 +49,7 @@ class ScheduledTask < ActiveRecord::Base
44
49
  def check_task_without_next_run
45
50
  check_log('Next run blank')
46
51
  update_attributes!(next_run: calculate_next_run)
47
- check_log("Next run @scheduled_taskored: #{next_run.in_time_zone}")
52
+ check_log("Next run scheduled: #{next_run.in_time_zone}")
48
53
  end
49
54
 
50
55
  def check_task_with_next_run
@@ -66,5 +71,13 @@ class ScheduledTask < ActiveRecord::Base
66
71
  Process.detach(spawn_pid)
67
72
  update_attributes!(pid: spawn_pid, last_fail_status: nil)
68
73
  end
74
+
75
+ def timeout?
76
+ running_time >= ::ScheduledTask.timeout
77
+ end
78
+
79
+ def running_time
80
+ last_run_start.present? ? Time.zone.now - last_run_start : 0
81
+ end
69
82
  end
70
83
  end
@@ -1,3 +1,3 @@
1
1
  module TasksScheduler
2
- VERSION = '0.0.8'.freeze
2
+ VERSION = '0.0.9'.freeze
3
3
  end
@@ -51,6 +51,9 @@ class ScheduledTaskTest < ActiveSupport::TestCase
51
51
 
52
52
  @scheduled_task.send('status_on_end', StandardError.new('Test!'), ScheduledTask::STATUS_ABORTED)
53
53
  assert_equal ScheduledTask::STATUS_ABORTED, @scheduled_task.status
54
+
55
+ @scheduled_task.send('status_on_end', StandardError.new('Test!'), ScheduledTask::STATUS_TIMEOUT)
56
+ assert_equal ScheduledTask::STATUS_TIMEOUT, @scheduled_task.status
54
57
  end
55
58
 
56
59
  test 'task in list' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tasks_scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni