tasks_scheduler 0.4.2 → 0.5.4

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
  SHA256:
3
- metadata.gz: 9a16067c62acba647e2e5d6b0ba72aefd8e394766242c7aa7222cdc26efa515d
4
- data.tar.gz: 15605017849c697fe146a8ac1ad69981846c5ebb1aa4b54fc8d0695d555f498c
3
+ metadata.gz: 75a6de697f21d110f7bd19830666b84ebc8f6bceddebfe7b5690b7fcbfc362d0
4
+ data.tar.gz: 59ca3d0f8830902424d1a3ff3927d16b1b1a13513b3f9b7f1d02865e07e64c90
5
5
  SHA512:
6
- metadata.gz: f850e1b47685482e850d93b61a49339fae6f508f25b042e960d8da8f9fb78f50b3d46f84acf8049db43b0a675de91485335f3f04df3575b9345f6fb58a652be0
7
- data.tar.gz: d0d33e8ba43ca019a9f4ec70aeb614cfd53c3693f1f5b86c4cf705ef69a62e98ec9d90e11ec7654fc5573e8c61fbd2e943fc1571ec66d9877133823e7ff97022
6
+ metadata.gz: fb5b96594aec114c1e8f3f08ed6fa03d638eb869fc9ef8c4cec3fb7b24f765945e879cf97597142726746a2709bf65733b800454477da2dd8378a419c6882376
7
+ data.tar.gz: 38f1f53610c2830ba8e2deeed0ad32bd9a21165926cf92bc898291303829bd3843917c83c647e667478361540b59dfd3bed1dbc4482fc3a4342dda5c818d3f0c
@@ -1,115 +1,4 @@
1
1
  //= require active_scaffold
2
2
  //= require js-routes
3
-
4
- function TasksScheduler() {
5
- }
6
-
7
- TasksScheduler.Status = function () {
8
- };
9
-
10
- // Shortcut
11
- var _S = TasksScheduler.Status;
12
-
13
- _S.initialized = false;
14
-
15
- _S.init = function (url, interval_max) {
16
- if (!_S.initialized) {
17
- _S.initialized = true;
18
- _S.url = url;
19
- _S.interval_max = interval_max;
20
- _S.update();
21
- }
22
- };
23
-
24
- _S.content = function () {
25
- return $('#TaskScheduler_Status_Content');
26
- };
27
-
28
- _S.status = function () {
29
- return $('#TaskScheduler_Status_Status');
30
- };
31
-
32
- _S.update_status = function () {
33
- _S.status().html(
34
- "Updating in " + _S.interval + " seconds..."
35
- );
36
- };
37
-
38
- _S.check = function () {
39
- if (_S.interval <= 0) {
40
- _S.update();
41
- } else {
42
- _S.interval--;
43
- _S.update_status();
44
- setTimeout(_S.check, 1000);
45
- }
46
- };
47
-
48
- _S.update = function () {
49
- $.ajax({
50
- url: _S.url,
51
- success: function (result) {
52
- _S.content().html(result);
53
- },
54
- complete: function (result) {
55
- _S.interval = _S.interval_max + 1;
56
- _S.last_update = new Date();
57
- _S.check();
58
- }
59
- });
60
- };
61
-
62
- TasksScheduler.Alert = function () {
63
- };
64
-
65
- _A = TasksScheduler.Alert;
66
-
67
- _A.DEFAULT_REFRESH_INTERVAL = 5000;
68
- _A.DEFAULT_ELEMENT_SELECTOR = '#tasks_scheduler_alert';
69
- _A.CSS_CLASSES_PREFIX = 'alert_';
70
- _A.url = Routes.status_tasks_scheduler_daemon_path();
71
-
72
- _A.init = function (options) {
73
- options = typeof options !== 'undefined' ? options : {};
74
- $(document).ready(function () {
75
- _A.options = options;
76
- if (!_A.options.refresh_interval) {
77
- _A.options.refresh_interval = _A.DEFAULT_REFRESH_INTERVAL;
78
- }
79
- if (!_A.options.element_selector) {
80
- _A.options.element_selector = _A.DEFAULT_ELEMENT_SELECTOR;
81
- }
82
- _A.refresh();
83
- });
84
- };
85
-
86
- _A.setNextRefresh = function () {
87
- setTimeout(_A.refresh, _A.options.refresh_interval);
88
- };
89
-
90
- _A.refresh = function () {
91
- $.ajax({
92
- url: _A.url,
93
- success: function (result) {
94
- var alert = $(_A.options.element_selector);
95
- var pattern = new RegExp('(^|\\s)' + _A.CSS_CLASSES_PREFIX + "\\S+", 'g');
96
- alert.removeClass (function (index, className) {
97
- return (className.match (pattern) || []).join(' ');
98
- });
99
- alert.addClass(_A.resultToCssClass(result));
100
- },
101
- complete: function (result) {
102
- _A.setNextRefresh();
103
- }
104
- });
105
- };
106
-
107
- _A.resultToCssClass = function(result) {
108
- var suffix = "ok"
109
- if (!result.daemon_running) {
110
- suffix = "daemon_stopped";
111
- } else if (!result.tasks_all_ok) {
112
- suffix = "task_failed";
113
- }
114
- return _A.CSS_CLASSES_PREFIX + suffix;
115
- };
3
+ //= require tasks_scheduler/alert
4
+ //= require tasks_scheduler/status
@@ -0,0 +1,62 @@
1
+ if (typeof TasksScheduler == "undefined") {
2
+ TasksScheduler = function() {};
3
+ }
4
+
5
+ TasksScheduler.Alert = function () {
6
+ };
7
+
8
+ _A = TasksScheduler.Alert;
9
+
10
+ _A.DEFAULT_REFRESH_INTERVAL = 5000;
11
+ _A.DEFAULT_ELEMENT_SELECTOR = '#tasks_scheduler_alert';
12
+ _A.CSS_CLASSES_PREFIX = 'alert_';
13
+ _A.url = Routes.status_tasks_scheduler_daemon_path();
14
+
15
+ _A.init = function (options) {
16
+ options = typeof options !== 'undefined' ? options : {};
17
+ $(document).ready(function () {
18
+ _A.options = options;
19
+ if (!_A.options.refresh_interval) {
20
+ _A.options.refresh_interval = _A.DEFAULT_REFRESH_INTERVAL;
21
+ }
22
+ if (!_A.options.element_selector) {
23
+ _A.options.element_selector = _A.DEFAULT_ELEMENT_SELECTOR;
24
+ }
25
+ _A.refresh();
26
+ });
27
+ };
28
+
29
+ _A.setNextRefresh = function () {
30
+ setTimeout(_A.refresh, _A.options.refresh_interval);
31
+ };
32
+
33
+ _A.refresh = function () {
34
+ $.ajax(_A.refreshAjaxData());
35
+ };
36
+
37
+ _A.refreshAjaxData = function () {
38
+ return {
39
+ url: _A.url,
40
+ success: function (result) {
41
+ var alert = $(_A.options.element_selector);
42
+ var pattern = new RegExp('(^|\\s)' + _A.CSS_CLASSES_PREFIX + "\\S+", 'g');
43
+ alert.removeClass (function (index, className) {
44
+ return (className.match (pattern) || []).join(' ');
45
+ });
46
+ alert.addClass(_A.resultToCssClass(result));
47
+ },
48
+ complete: function (result) {
49
+ _A.setNextRefresh();
50
+ }
51
+ };
52
+ };
53
+
54
+ _A.resultToCssClass = function(result) {
55
+ var suffix = "ok"
56
+ if (!result.daemon_running) {
57
+ suffix = "daemon_stopped";
58
+ } else if (!result.tasks_all_ok) {
59
+ suffix = "task_failed";
60
+ }
61
+ return _A.CSS_CLASSES_PREFIX + suffix;
62
+ };
@@ -0,0 +1,62 @@
1
+ if (typeof TasksScheduler == "undefined") {
2
+ TasksScheduler = function() {};
3
+ }
4
+
5
+ TasksScheduler.Status = function () {
6
+ };
7
+
8
+ // Shortcut
9
+ var _S = TasksScheduler.Status;
10
+
11
+ _S.initialized = false;
12
+
13
+ _S.init = function (url, interval_max) {
14
+ if (!_S.initialized) {
15
+ _S.initialized = true;
16
+ _S.url = url;
17
+ _S.interval_max = interval_max;
18
+ _S.update();
19
+ }
20
+ };
21
+
22
+ _S.content = function () {
23
+ return $('#TaskScheduler_Status_Content');
24
+ };
25
+
26
+ _S.status = function () {
27
+ return $('#TaskScheduler_Status_Status');
28
+ };
29
+
30
+ _S.update_status = function () {
31
+ _S.status().html(
32
+ "Updating in " + _S.interval + " seconds..."
33
+ );
34
+ };
35
+
36
+ _S.check = function () {
37
+ if (_S.interval <= 0) {
38
+ _S.update();
39
+ } else {
40
+ _S.interval--;
41
+ _S.update_status();
42
+ setTimeout(_S.check, 1000);
43
+ }
44
+ };
45
+
46
+ _S.update = function () {
47
+ $.ajax(_S.updateAjaxData());
48
+ };
49
+
50
+ _S.updateAjaxData = function() {
51
+ return {
52
+ url: _S.url,
53
+ success: function (result) {
54
+ _S.content().html(result);
55
+ },
56
+ complete: function (result) {
57
+ _S.interval = _S.interval_max + 1;
58
+ _S.last_update = new Date();
59
+ _S.check();
60
+ }
61
+ };
62
+ };
@@ -39,6 +39,10 @@
39
39
  td.status_disabled {
40
40
  color: lightgrey;
41
41
  }
42
+
43
+ td.status_task_not_found {
44
+ color: violet;
45
+ }
42
46
  }
43
47
 
44
48
  .last_run {
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/core_ext'
3
4
  require 'rake'
4
5
 
5
6
  class ScheduledTask < ActiveRecord::Base
@@ -29,14 +30,11 @@ class ScheduledTask < ActiveRecord::Base
29
30
  end
30
31
  end
31
32
 
32
- STATUS_RUNNING = 'running'
33
- STATUS_FAILED = 'failed'
34
- STATUS_WAITING = 'waiting'
35
- STATUS_ABORTED = 'aborted'
36
- STATUS_TIMEOUT = 'timeout'
37
- STATUS_DISABLED = 'disabled'
33
+ enable_listable
34
+ lists.add_string :status, 'aborted', 'disabled', 'failed', 'running', 'task_not_found', 'timeout',
35
+ 'waiting'
38
36
 
39
- LAST_FAIL_STATUSES = [STATUS_FAILED, STATUS_ABORTED, STATUS_TIMEOUT].freeze
37
+ LAST_FAIL_STATUSES = [STATUS_FAILED, STATUS_ABORTED, STATUS_TASK_NOT_FOUND, STATUS_TIMEOUT].freeze
40
38
 
41
39
  validates :scheduling, presence: true, 'tasks_scheduler/cron_scheduling': true
42
40
  validates :task, presence: true
@@ -45,6 +45,12 @@ class ScheduledTask < ActiveRecord::Base
45
45
  end
46
46
  end
47
47
 
48
+ def check_on_task_not_exist
49
+ message = "Task does not exist: #{task}"
50
+ check_log(message)
51
+ on_end_running(::StandardError.new(message), STATUS_TASK_NOT_FOUND)
52
+ end
53
+
48
54
  def check_log(message, method = :info)
49
55
  Rails.logger.send(method, "TASK_CHECK(#{id}): #{message}")
50
56
  end
@@ -65,7 +71,7 @@ class ScheduledTask < ActiveRecord::Base
65
71
 
66
72
  def check_task_with_next_run
67
73
  if !task_exist?
68
- check_log("Task does not exist: #{task}")
74
+ check_on_task_not_exist
69
75
  elsif next_run < Time.zone.now
70
76
  check_log('Next run reached. Running...')
71
77
  spawn_task
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Rails.application.routes.draw do
4
- resources(:scheduled_tasks) do
5
- as_routes
4
+ concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)
5
+ resources(:scheduled_tasks, concerns: :active_scaffold) do
6
6
  collection do
7
7
  get :status
8
8
  get :status_content
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class CreateScheduledTasks < (
4
- Rails.version < '5.2' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
4
+ Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
5
5
  )
6
6
  def change
7
7
  create_table :scheduled_tasks do |t|
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AddStatusAttributesToScheduledTasks < (
4
- Rails.version < '5.2' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
4
+ Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
5
5
  )
6
6
  def change
7
7
  add_column :scheduled_tasks, :last_run_start, :datetime
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AddPidToScheduledTasks < (
4
- Rails.version < '5.2' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
4
+ Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
5
5
  )
6
6
  def change
7
7
  add_column :scheduled_tasks, :pid, :integer
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AddArgsToScheduledTasks < (
4
- Rails.version < '5.2' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
4
+ Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
5
5
  )
6
6
  def change
7
7
  add_column :scheduled_tasks, :args, :string
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AddLastFailStatusToScheduledTasks < (
4
- Rails.version < '5.2' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
4
+ Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
5
5
  )
6
6
  def change
7
7
  add_column :scheduled_tasks, :last_fail_status, :string
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AddEnabledToScheduledTasks < (
4
- Rails.version < '5.2' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
4
+ Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
5
5
  )
6
6
  def change
7
7
  add_column :scheduled_tasks, :enabled, :boolean, null: false, default: true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TasksScheduler
4
- VERSION = '0.4.2'
4
+ VERSION = '0.5.4'
5
5
  end
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -2,3 +2,5 @@ test_scheduling:
2
2
  scheduling: 0 0 * * *
3
3
  task: test
4
4
  next_run: 2016-11-22 09:38:28
5
+ created_at: 2016-11-20 00:00:00
6
+ updated_at: 2016-11-20 00:00:00
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.4.2
4
+ version: 0.5.4
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: 2020-07-26 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_scaffold
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 0.4.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: eac_ruby_utils
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.43'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.43'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: js-routes
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +161,8 @@ files:
147
161
  - README.rdoc
148
162
  - Rakefile
149
163
  - app/assets/javascripts/tasks_scheduler.js
164
+ - app/assets/javascripts/tasks_scheduler/alert.js
165
+ - app/assets/javascripts/tasks_scheduler/status.js
150
166
  - app/assets/stylesheets/tasks_scheduler.scss
151
167
  - app/assets/stylesheets/tasks_scheduler/alert.scss
152
168
  - app/controllers/scheduled_tasks_controller.rb
@@ -192,6 +208,7 @@ files:
192
208
  - lib/tasks_scheduler/version.rb
193
209
  - test/dummy/README.rdoc
194
210
  - test/dummy/Rakefile
211
+ - test/dummy/app/assets/config/manifest.js
195
212
  - test/dummy/app/assets/javascripts/application.js
196
213
  - test/dummy/app/assets/stylesheets/application.css
197
214
  - test/dummy/app/controllers/application_controller.rb
@@ -228,7 +245,7 @@ files:
228
245
  - test/fixtures/scheduled_tasks.yml
229
246
  - test/models/scheduled_task_test.rb
230
247
  - test/test_helper.rb
231
- homepage:
248
+ homepage: https://github.com/esquilo-azul/tasks_scheduler
232
249
  licenses:
233
250
  - MIT
234
251
  metadata: {}
@@ -247,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
264
  - !ruby/object:Gem::Version
248
265
  version: '0'
249
266
  requirements: []
250
- rubygems_version: 3.0.6
267
+ rubygems_version: 3.0.8
251
268
  signing_key:
252
269
  specification_version: 4
253
270
  summary: Scheduler for Rake tasks.
@@ -277,6 +294,7 @@ test_files:
277
294
  - test/dummy/app/views/layouts/application.html.erb
278
295
  - test/dummy/app/controllers/application_controller.rb
279
296
  - test/dummy/app/helpers/application_helper.rb
297
+ - test/dummy/app/assets/config/manifest.js
280
298
  - test/dummy/app/assets/stylesheets/application.css
281
299
  - test/dummy/app/assets/javascripts/application.js
282
300
  - test/dummy/public/422.html