tasks_scheduler 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/tasks_scheduler.js +44 -0
- data/app/assets/stylesheets/tasks_scheduler.scss +8 -0
- data/app/controllers/scheduled_tasks_controller.rb +0 -1
- data/app/controllers/tasks_scheduler_daemon_controller.rb +13 -0
- data/app/views/scheduled_tasks/list.html.erb +2 -0
- data/app/views/scheduled_tasks/status.html.erb +2 -0
- data/app/views/scheduled_tasks/status_content.html.erb +2 -0
- data/app/views/tasks_scheduler/_navbar.html.erb +5 -0
- data/app/views/tasks_scheduler_daemon/_running_status.html.erb +6 -0
- data/app/views/tasks_scheduler_daemon/index.html.erb +19 -0
- data/config/locales/en.yml +3 -1
- data/config/locales/pt-BR.yml +3 -1
- data/config/routes.rb +5 -0
- data/lib/tasks_scheduler.rb +1 -0
- data/lib/tasks_scheduler/daemon.rb +33 -0
- data/lib/tasks_scheduler/version.rb +1 -1
- data/test/dummy/app/views/layouts/application.html.erb +9 -11
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d55cf267a17b9745518a4c84e1cfc2aef077840
|
4
|
+
data.tar.gz: c76a8903f97bff753eec0794c1d51d2305501843
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 915274287591f4c7fc5dc286c18e9c9b085d3b15b33d8d9fe3f1571a02028a4f31d6ce3e406de66c2eb79b5cf7a49b90d34ad83e3f59d45a9c049e7e6faae638
|
7
|
+
data.tar.gz: d3495bd1fbe9de29057e14f7f2aae07ddfc116f9e292ff752c60b51235131671f51c361bfd43bb4d840516c3d89826bd1672710593604ff3db6e1fbf170cbb14
|
@@ -57,3 +57,47 @@ _S.update = function () {
|
|
57
57
|
}
|
58
58
|
});
|
59
59
|
};
|
60
|
+
|
61
|
+
TasksScheduler.Alert = function () {
|
62
|
+
};
|
63
|
+
|
64
|
+
_A = TasksScheduler.Alert;
|
65
|
+
|
66
|
+
_A.DEFAULT_REFRESH_INTERVAL = 60000;
|
67
|
+
_A.DEFAULT_ELEMENT_SELECTOR = '#tasks_scheduler_alert';
|
68
|
+
_A.url = null;
|
69
|
+
|
70
|
+
_A.init = function (url, options = {}) {
|
71
|
+
$(document).ready(function () {
|
72
|
+
_A.url = url;
|
73
|
+
_A.options = options;
|
74
|
+
if (!_A.options.refresh_interval) {
|
75
|
+
_A.options.refresh_interval = _A.DEFAULT_REFRESH_INTERVAL;
|
76
|
+
}
|
77
|
+
if (!_A.options.element_selector) {
|
78
|
+
_A.options.element_selector = _A.DEFAULT_ELEMENT_SELECTOR;
|
79
|
+
}
|
80
|
+
_A.refresh();
|
81
|
+
});
|
82
|
+
};
|
83
|
+
|
84
|
+
_A.setNextRefresh = function () {
|
85
|
+
setTimeout(_A.refresh, _A.options.refresh_interval);
|
86
|
+
};
|
87
|
+
|
88
|
+
_A.refresh = function () {
|
89
|
+
$.ajax({
|
90
|
+
url: _A.url,
|
91
|
+
success: function (result) {
|
92
|
+
var alert = $(_A.options.element_selector);
|
93
|
+
if (result === 'true') {
|
94
|
+
alert.hide();
|
95
|
+
} else {
|
96
|
+
alert.show();
|
97
|
+
}
|
98
|
+
},
|
99
|
+
complete: function (result) {
|
100
|
+
_A.setNextRefresh();
|
101
|
+
}
|
102
|
+
});
|
103
|
+
};
|
@@ -17,7 +17,6 @@ class ScheduledTasksController < ApplicationController
|
|
17
17
|
conf.columns[:task].form_ui = :select
|
18
18
|
conf.columns[:task].options ||= {}
|
19
19
|
conf.columns[:task].options[:options] = task_column_options
|
20
|
-
conf.action_links.add :status, label: I18n.t(:tasks_scheduler_status), position: true
|
21
20
|
conf.action_links.add :run_now, label: I18n.t(:run_now), type: :member,
|
22
21
|
crud_type: :update, method: :put, position: false
|
23
22
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class TasksSchedulerDaemonController < ApplicationController
|
2
|
+
def index
|
3
|
+
end
|
4
|
+
|
5
|
+
def execute
|
6
|
+
@result = ::TasksScheduler::Daemon.execute(params[:tasks_scheduler_execute_action])
|
7
|
+
render 'index'
|
8
|
+
end
|
9
|
+
|
10
|
+
def running
|
11
|
+
render plain: (::TasksScheduler::Daemon.running? ? 'true' : 'false'), layout: false
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%= render partial: '/tasks_scheduler/navbar' %>
|
2
|
+
<h2><%= I18n.t(:tasks_scheduler_daemon) %></h2>
|
3
|
+
<p>
|
4
|
+
<%= render partial: '/tasks_scheduler_daemon/running_status' %>
|
5
|
+
<br/>
|
6
|
+
<strong>Actions: </strong>
|
7
|
+
<%= safe_join(::TasksScheduler::Daemon::ACTIONS.map do |action|
|
8
|
+
link_to action, execute_tasks_scheduler_daemon_path(action), method: :post
|
9
|
+
end, ' | ') %>
|
10
|
+
</p>
|
11
|
+
<% if @result %>
|
12
|
+
<h3>Results</h3>
|
13
|
+
<dl>
|
14
|
+
<% @result.each do |k, v| %>
|
15
|
+
<dt><%= k %></dt>
|
16
|
+
<dd><%= v.present? ? v : '-' %></dd>
|
17
|
+
<% end %>
|
18
|
+
</dl>
|
19
|
+
<% end %>
|
data/config/locales/en.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
en:
|
1
|
+
en:
|
2
2
|
activerecord:
|
3
3
|
models:
|
4
4
|
scheduled_task:
|
@@ -19,4 +19,6 @@ en:
|
|
19
19
|
log: Log
|
20
20
|
run_now: Run now
|
21
21
|
start: Start
|
22
|
+
scheduled_tasks: Scheduled tasks - Edit
|
23
|
+
tasks_scheduler_daemon: Scheduled tasks - Daemon
|
22
24
|
tasks_scheduler_status: Scheduled tasks - Status
|
data/config/locales/pt-BR.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
pt-BR:
|
1
|
+
pt-BR:
|
2
2
|
activerecord:
|
3
3
|
models:
|
4
4
|
scheduled_task:
|
@@ -19,4 +19,6 @@ pt-BR:
|
|
19
19
|
log: Log
|
20
20
|
run_now: Executar agora
|
21
21
|
start: Início
|
22
|
+
scheduled_tasks: Tarefas agendadas - Edição
|
23
|
+
tasks_scheduler_daemon: Tarefas agendadas - Daemon
|
22
24
|
tasks_scheduler_status: Tarefas agendadas - Status
|
data/config/routes.rb
CHANGED
@@ -10,4 +10,9 @@ Rails.application.routes.draw do
|
|
10
10
|
put :run_now
|
11
11
|
end
|
12
12
|
end
|
13
|
+
get '/tasks_scheduler_daemon', to: 'tasks_scheduler_daemon#index', as: :tasks_scheduler_daemon
|
14
|
+
post '/tasks_scheduler_daemon/:tasks_scheduler_execute_action',
|
15
|
+
to: 'tasks_scheduler_daemon#execute', as: :execute_tasks_scheduler_daemon
|
16
|
+
get '/tasks_scheduler_daemon/running', to: 'tasks_scheduler_daemon#running',
|
17
|
+
as: :running_tasks_scheduler_daemon
|
13
18
|
end
|
data/lib/tasks_scheduler.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module TasksScheduler
|
4
|
+
class Daemon
|
5
|
+
ACTIONS = %w(status start stop restart).freeze
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def run(rails_root)
|
9
|
+
dir = File.expand_path('tmp/pids', rails_root)
|
10
|
+
FileUtils.mkdir_p(dir)
|
11
|
+
Daemons.run_proc 'tasks_scheduler', dir_mode: :normal, dir: dir do
|
12
|
+
require File.join(rails_root, 'config', 'environment')
|
13
|
+
::TasksScheduler::Checker.instance.run
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(action)
|
18
|
+
raise "Action not allowed: #{action} (Allowed: #{ACTIONS})" unless ACTIONS.include?(action)
|
19
|
+
command = ['bundle', 'exec', 'tasks_scheduler', action]
|
20
|
+
Dir.chdir(Rails.root) do
|
21
|
+
Open3.popen3(*command) do |_stdin, stdout, stderr, wait_thr|
|
22
|
+
{ action: action, command: command.join(' '), status: wait_thr.value.to_i,
|
23
|
+
stdout: stdout.read, stderr: stderr.read }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def running?
|
29
|
+
execute('status')[:status].zero?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
</body>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<%= yield %>
|
11
|
+
</body>
|
14
12
|
</html>
|
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.5
|
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:
|
11
|
+
date: 2017-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_scaffold
|
@@ -95,15 +95,20 @@ files:
|
|
95
95
|
- app/assets/javascripts/tasks_scheduler.js
|
96
96
|
- app/assets/stylesheets/tasks_scheduler.scss
|
97
97
|
- app/controllers/scheduled_tasks_controller.rb
|
98
|
+
- app/controllers/tasks_scheduler_daemon_controller.rb
|
98
99
|
- app/helpers/scheduled_tasks_helper.rb
|
99
100
|
- app/models/scheduled_task.rb
|
100
101
|
- app/models/scheduled_task/checker.rb
|
101
102
|
- app/models/scheduled_task/log.rb
|
102
103
|
- app/models/scheduled_task/runner.rb
|
103
104
|
- app/models/scheduled_task/status.rb
|
105
|
+
- app/views/scheduled_tasks/list.html.erb
|
104
106
|
- app/views/scheduled_tasks/log.html.erb
|
105
107
|
- app/views/scheduled_tasks/status.html.erb
|
106
108
|
- app/views/scheduled_tasks/status_content.html.erb
|
109
|
+
- app/views/tasks_scheduler/_navbar.html.erb
|
110
|
+
- app/views/tasks_scheduler_daemon/_running_status.html.erb
|
111
|
+
- app/views/tasks_scheduler_daemon/index.html.erb
|
107
112
|
- config/initializers/assets.rb
|
108
113
|
- config/locales/en.yml
|
109
114
|
- config/locales/pt-BR.yml
|
@@ -118,6 +123,7 @@ files:
|
|
118
123
|
- lib/tasks_scheduler/checker.rb
|
119
124
|
- lib/tasks_scheduler/cron_parser_patch.rb
|
120
125
|
- lib/tasks_scheduler/cron_scheduling_validator.rb
|
126
|
+
- lib/tasks_scheduler/daemon.rb
|
121
127
|
- lib/tasks_scheduler/engine.rb
|
122
128
|
- lib/tasks_scheduler/version.rb
|
123
129
|
- test/dummy/README.rdoc
|