tasks_scheduler 0.0.8 → 0.0.9
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1b92e7a9bc9fb0c7c43ef5a11422b51858a0466
|
4
|
+
data.tar.gz: af726dd48df8fec1ab31289023bbdad82b5dc3f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e46f79d1e2fdf7fef088126b0c2cefc2af3437a383e5ed1250c73a9a305f3d502e55684a2141712c752d33c5988bba969d83b0f9d1343e8cd5542172b84d552
|
7
|
+
data.tar.gz: 748695d547d7b1126263c00628233f5a1cb8beed84ef164d67b4e50fc99ee8638b68b0e39c48ee88a8923516c7e71dfe94cce677c0ca4073c6c0e416a3a80530
|
@@ -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
|
-
|
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
|
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
|
@@ -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
|