whenever-web 0.0.4 → 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/README.md +33 -15
- data/app/controllers/whenever/jobs_controller.rb +5 -14
- data/app/controllers/whenever/logs_controller.rb +14 -0
- data/app/controllers/whenever/web_controller.rb +5 -0
- data/app/helpers/whenever/jobs_helper.rb +4 -0
- data/app/models/whenever/cron_tab.rb +0 -0
- data/app/models/whenever/log.rb +22 -0
- data/app/models/whenever/web_config.rb +15 -0
- data/app/models/whenever/web_job.rb +14 -9
- data/app/models/whenever/web_job_list.rb +29 -8
- data/app/services/whenever/job_runner.rb +25 -0
- data/app/views/whenever/jobs/index.html.erb +62 -39
- data/app/views/whenever/layouts/admin.html.haml +8 -0
- data/config/locales/en.yml +18 -0
- data/config/routes.rb +1 -0
- data/lib/whenever/patches/job.rb +1 -1
- data/lib/whenever/patches/job_list.rb +2 -0
- data/lib/whenever/web.rb +11 -1
- data/whenever-web.gemspec +1 -1
- metadata +12 -4
- data/app/controllers/whenever/application_controller.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bff8d51d0cc7b17cefe45c45cf5e4f4002ff6eb
|
4
|
+
data.tar.gz: 095e0103aa282daebf98852658fa82865f6dd35f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a23e505e1512327fbdf029a6a3055f9a4f1d74c537f12062bc80f50f9b272da79c30568f79f944a984b72bad2df254211e6ed655d6af376bbb1b7d2815bf4c2
|
7
|
+
data.tar.gz: b89f2f869524a4b8211a5ffd28b4ef6f4d6b6ff7f6bd6c609af81f21a3e25bd81e491f0a0690c41b06acd38c4506de9927816dd2fad379e5b376552f320c262b
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Whenever Web
|
2
2
|
|
3
|
+
Whenever Web is a Rails engine, that can be easily integrated with your admin panel layout.
|
4
|
+
|
5
|
+
![Whenever Web](http://i.imgur.com/d6whPlQ.png)
|
6
|
+
|
3
7
|
## Installation
|
4
8
|
|
5
9
|
Add this line to your application's Gemfile:
|
@@ -12,27 +16,29 @@ And then execute:
|
|
12
16
|
|
13
17
|
## Usage
|
14
18
|
|
15
|
-
Mount the engine in your `routes.rb`:
|
19
|
+
1. Mount the engine in your `routes.rb`:
|
16
20
|
|
17
|
-
```ruby
|
18
|
-
MyApp::Application.routes.draw do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
```
|
21
|
+
```ruby
|
22
|
+
MyApp::Application.routes.draw do
|
23
|
+
# ...
|
24
|
+
mount Whenever::Web, at: '/whenever'
|
25
|
+
# ...
|
26
|
+
end
|
27
|
+
```
|
24
28
|
|
25
|
-
|
29
|
+
2. Go to [localhost:3000/whenever](http://localhost:3000/whenever).
|
26
30
|
|
27
|
-
|
31
|
+
3. Add a link to the panel in your views:
|
28
32
|
|
29
|
-
```ruby
|
30
|
-
= link_to 'Cron Jobs', whenever_path
|
31
|
-
```
|
33
|
+
```ruby
|
34
|
+
= link_to 'Cron Jobs', whenever_path
|
35
|
+
```
|
32
36
|
|
33
|
-
|
37
|
+
## Optional usage
|
34
38
|
|
35
|
-
|
39
|
+
Describe your Cron jobs in `schedule.rb` by using `desc` method:
|
40
|
+
|
41
|
+
```ruby
|
36
42
|
require 'whenever/web'
|
37
43
|
|
38
44
|
every 1.day, at: '3:00 am' do
|
@@ -41,6 +47,18 @@ every 1.day, at: '3:00 am' do
|
|
41
47
|
end
|
42
48
|
```
|
43
49
|
|
50
|
+
## Custom configuration
|
51
|
+
|
52
|
+
Put this into `config/initializers/whenever_web.rb`:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
# Specify your own controller base eg. 'Admin::AdminController'
|
56
|
+
# Whenever::Web.config.parent_controller = 'Whenever::WebController'
|
57
|
+
|
58
|
+
# Change default schedule file path
|
59
|
+
# Whenever::Web.config.schedule_file = 'config/schedule.rb'
|
60
|
+
```
|
61
|
+
|
44
62
|
## Contributing
|
45
63
|
|
46
64
|
1. Fork it (http://github.com/bartoszkopinski/whenever-web/fork)
|
@@ -1,22 +1,13 @@
|
|
1
1
|
module Whenever
|
2
|
-
class JobsController <
|
3
|
-
before_filter :list_jobs
|
4
|
-
layout 'admin'
|
5
|
-
|
2
|
+
class JobsController < Web.config.parent_controller
|
6
3
|
def index
|
4
|
+
@crontab = CommandLine.new.send(:read_crontab)
|
7
5
|
end
|
8
6
|
|
9
7
|
def run
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
redirect_to jobs_path
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def list_jobs
|
19
|
-
@job_list = WebJobList.new(file: 'config/schedule.rb')
|
8
|
+
runner = JobRunner.new(params[:id])
|
9
|
+
runner.run
|
10
|
+
redirect_to jobs_path, notice: t('.success', command: runner.command)
|
20
11
|
end
|
21
12
|
end
|
22
13
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Whenever
|
2
|
+
class LogsController < Web.config.parent_controller
|
3
|
+
def clear
|
4
|
+
log.clear
|
5
|
+
redirect_to jobs_path, notice: t('.success', kind: log.kind)
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def log
|
11
|
+
@log ||= Web.job_list.logs.fetch(params[:kind])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Whenever
|
2
|
+
class Log
|
3
|
+
attr_reader :kind
|
4
|
+
|
5
|
+
def initialize kind, path
|
6
|
+
@kind = kind
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
"#{@kind}_log"
|
12
|
+
end
|
13
|
+
|
14
|
+
def tail
|
15
|
+
File.read(@path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear
|
19
|
+
File.write(@path, nil)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Whenever
|
2
|
+
class WebConfig
|
3
|
+
attr_accessor :schedule_file, :parent_controller, :layout
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@schedule_file = 'config/schedule.rb'
|
7
|
+
@parent_controller = 'Whenever::WebController'
|
8
|
+
@layout = 'admin'
|
9
|
+
end
|
10
|
+
|
11
|
+
def parent_controller
|
12
|
+
@parent_controller.to_s.constantize
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -3,26 +3,31 @@ require 'whenever/patches/job'
|
|
3
3
|
module Whenever
|
4
4
|
class WebJob
|
5
5
|
include ActionView::Helpers::DateHelper
|
6
|
-
attr_reader :interval
|
6
|
+
attr_reader :interval
|
7
7
|
|
8
8
|
def initialize job, interval
|
9
9
|
@job = job
|
10
10
|
@interval = interval
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
delegate :output, :at, to: :@job
|
14
|
+
|
15
|
+
def task
|
16
|
+
@job.options[:task]
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
@job.template.gsub(/:\w+/, replacements)
|
19
|
+
def description
|
20
|
+
@job.options.fetch(:description) { task }
|
22
21
|
end
|
23
22
|
|
24
23
|
def interval
|
25
|
-
distance_of_time_in_words(@interval)
|
24
|
+
distance_of_time_in_words(@interval).gsub('about', '')
|
25
|
+
rescue ArgumentError
|
26
|
+
@interval
|
27
|
+
end
|
28
|
+
|
29
|
+
def roles
|
30
|
+
@job.roles.join(', ')
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
@@ -2,22 +2,43 @@ require 'whenever/patches/job_list'
|
|
2
2
|
|
3
3
|
module Whenever
|
4
4
|
class WebJobList < JobList
|
5
|
-
|
5
|
+
include Enumerable
|
6
|
+
attr_reader :set_variables, :job_types
|
7
|
+
|
8
|
+
delegate :fetch, :each, to: :web_jobs
|
6
9
|
|
7
10
|
def web_jobs
|
8
|
-
@
|
9
|
-
jobs.
|
10
|
-
|
11
|
+
@web_jobs ||= begin
|
12
|
+
@jobs.flat_map do |interval, jobs|
|
13
|
+
jobs.map do |job|
|
14
|
+
WebJob.new(job, interval)
|
15
|
+
end
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
14
19
|
|
15
|
-
def
|
16
|
-
|
20
|
+
def logs
|
21
|
+
@logs ||= fetch_logs(@set_variables[:output])
|
22
|
+
end
|
23
|
+
|
24
|
+
alias_method :old_job_type, :job_type
|
25
|
+
|
26
|
+
def job_type name, template
|
27
|
+
(@job_types ||= {})[name] = template
|
28
|
+
old_job_type name, template
|
17
29
|
end
|
18
30
|
|
19
|
-
|
20
|
-
|
31
|
+
protected
|
32
|
+
|
33
|
+
def fetch_logs path, kind = 'standard'
|
34
|
+
case path
|
35
|
+
when Hash
|
36
|
+
path.map{ |k, v| fetch_logs(v, k) }.inject(:merge)
|
37
|
+
when String
|
38
|
+
{ kind.to_s => Log.new(kind, path) }
|
39
|
+
else
|
40
|
+
{}
|
41
|
+
end
|
21
42
|
end
|
22
43
|
end
|
23
44
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Whenever
|
2
|
+
class JobRunner
|
3
|
+
def initialize job_id
|
4
|
+
@job_id = job_id.to_i
|
5
|
+
end
|
6
|
+
|
7
|
+
def run
|
8
|
+
`#{environment_variables} #{command}`
|
9
|
+
end
|
10
|
+
|
11
|
+
def command
|
12
|
+
web_job.output
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def web_job
|
18
|
+
@web_job ||= Web.job_list.fetch(@job_id)
|
19
|
+
end
|
20
|
+
|
21
|
+
def environment_variables
|
22
|
+
@environment_variables ||= Web.job_list.environment_variables
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,70 +1,93 @@
|
|
1
1
|
<div class="panel panel-default">
|
2
|
-
<div class="panel-heading">
|
3
|
-
<div class="panel-title">
|
4
|
-
|
2
|
+
<div class="panel-heading clearfix">
|
3
|
+
<div class="panel-title pull-left">
|
4
|
+
<%= t('whenever.cron_jobs') %>
|
5
5
|
</div>
|
6
6
|
</div>
|
7
7
|
<table class="table">
|
8
8
|
<thead>
|
9
9
|
<tr>
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
<th><%= t('whenever.task') %></th>
|
11
|
+
<th><%= t('whenever.interval') %></th>
|
12
|
+
<th><%= t('whenever.hour') %></th>
|
13
|
+
<th><%= t('whenever.roles') %></th>
|
14
|
+
<th><%= t('whenever.action') %></th>
|
13
15
|
</tr>
|
14
16
|
</thead>
|
15
17
|
<tbody>
|
18
|
+
<% job_list.each_with_index do |job, i| %>
|
16
19
|
<tr>
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
<td><%= job.description %></td>
|
21
|
+
<td><%= job.interval %></td>
|
22
|
+
<td><%= job.at %></td>
|
23
|
+
<td><%= job.roles %></td>
|
24
|
+
<td><%= link_to t('whenever.run_now'), run_job_path(i), class: 'btn btn-danger', title: job.output %></td>
|
20
25
|
</tr>
|
26
|
+
<% end %>
|
21
27
|
</tbody>
|
22
28
|
</table>
|
23
29
|
</div>
|
30
|
+
<% job_list.logs.each do |_, log| %>
|
31
|
+
<div class="panel panel-default">
|
32
|
+
<div class="panel-heading clearfix">
|
33
|
+
<div class="panel-title pull-left">
|
34
|
+
<%= t("whenever.#{log.name}") %>
|
35
|
+
</div>
|
36
|
+
<div class="pull-right">
|
37
|
+
<%= link_to t('whenever.clear'), clear_log_path(log.kind), class: 'btn btn-xs btn-warning' %>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
<%= text_area_tag(log.name, log.tail, rows: 15, class: 'form-control', disabled: 'disabled') %>
|
41
|
+
</div>
|
42
|
+
<script type="text/javascript">
|
43
|
+
var <%= log.name %> = document.getElementById('<%= log.name %>');
|
44
|
+
<%= log.name %>.scrollTop = <%= log.name %>.scrollHeight;
|
45
|
+
</script>
|
46
|
+
<% end %>
|
24
47
|
<div class="panel panel-default">
|
25
|
-
<div class="panel-heading">
|
26
|
-
<div class="panel-title">
|
27
|
-
|
48
|
+
<div class="panel-heading clearfix">
|
49
|
+
<div class="panel-title pull-left">
|
50
|
+
<%= t('whenever.options') %>
|
28
51
|
</div>
|
29
52
|
</div>
|
30
53
|
<table class="table">
|
31
54
|
<thead>
|
32
55
|
<tr>
|
33
|
-
<th
|
34
|
-
<th
|
35
|
-
<th>Action</th>
|
56
|
+
<th><%= t('whenever.settings') %></th>
|
57
|
+
<th></th>
|
36
58
|
</tr>
|
37
59
|
</thead>
|
38
60
|
<tbody>
|
39
|
-
<%
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
61
|
+
<% job_list.set_variables.each do |k, v| %>
|
62
|
+
<tr>
|
63
|
+
<td><%= k %></td>
|
64
|
+
<td><%= v %></td>
|
65
|
+
</tr>
|
66
|
+
<% end %>
|
67
|
+
<thead>
|
68
|
+
<tr>
|
69
|
+
<th><%= t('whenever.job_types') %></th>
|
70
|
+
<th></th>
|
71
|
+
</tr>
|
72
|
+
</thead>
|
73
|
+
<% job_list.job_types.each do |k, v| %>
|
74
|
+
<tr>
|
75
|
+
<td><%= k %></td>
|
76
|
+
<td><%= v %></td>
|
77
|
+
</tr>
|
45
78
|
<% end %>
|
46
79
|
</tbody>
|
47
80
|
</table>
|
48
81
|
</div>
|
82
|
+
<% if @crontab.present? %>
|
49
83
|
<div class="panel panel-default">
|
50
|
-
<div class="panel-heading">
|
51
|
-
<div class="panel-title">
|
52
|
-
|
84
|
+
<div class="panel-heading clearfix">
|
85
|
+
<div class="panel-title pull-left">
|
86
|
+
<%= t('whenever.cron_tab') %>
|
53
87
|
</div>
|
54
88
|
</div>
|
55
|
-
|
89
|
+
<pre>
|
90
|
+
<%= @crontab %>
|
91
|
+
</pre>
|
56
92
|
</div>
|
57
|
-
|
58
|
-
<div class="panel-heading">
|
59
|
-
<div class="panel-title">
|
60
|
-
Standard log
|
61
|
-
</div>
|
62
|
-
</div>
|
63
|
-
<%= text_area(:job_list, :standard_log, rows: 15, class: 'form-control', disabled: 'disabled') %>
|
64
|
-
</div>
|
65
|
-
<script type="text/javascript">
|
66
|
-
var error_log = document.getElementById('job_list_error_log');
|
67
|
-
var standard_log = document.getElementById('job_list_standard_log');
|
68
|
-
error_log.scrollTop = error_log.scrollHeight;
|
69
|
-
standard_log.scrollTop = standard_log.scrollHeight;
|
70
|
-
</script>
|
93
|
+
<% end %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
en:
|
2
|
+
whenever:
|
3
|
+
logs:
|
4
|
+
clear:
|
5
|
+
success: "%{kind} log cleaned!"
|
6
|
+
jobs:
|
7
|
+
run:
|
8
|
+
success: "Task run: %{command}"
|
9
|
+
action: Action
|
10
|
+
cron_jobs: Cron jobs
|
11
|
+
error_log: Error log
|
12
|
+
hour: Hour
|
13
|
+
interval: Interval
|
14
|
+
roles: Roles
|
15
|
+
run_now: Run now
|
16
|
+
settings: Settings
|
17
|
+
standard_log: Standard log
|
18
|
+
task: Task
|
data/config/routes.rb
CHANGED
data/lib/whenever/patches/job.rb
CHANGED
data/lib/whenever/web.rb
CHANGED
@@ -5,7 +5,17 @@ require 'whenever/patches/job_list'
|
|
5
5
|
|
6
6
|
module Whenever
|
7
7
|
class Web < ::Rails::Engine
|
8
|
-
engine_name
|
8
|
+
engine_name self.name.deconstantize
|
9
9
|
isolate_namespace Whenever
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def config
|
13
|
+
@config ||= Whenever::WebConfig.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def job_list
|
17
|
+
Whenever::WebJobList.new(file: config.schedule_file)
|
18
|
+
end
|
19
|
+
end
|
10
20
|
end
|
11
21
|
end
|
data/whenever-web.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "whenever-web"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.5"
|
8
8
|
spec.authors = ["Bartosz Kopinski"]
|
9
9
|
spec.email = ["bartosz.kopinski@gmail.pl"]
|
10
10
|
spec.summary = %q{Web GUI for Whenever gem}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whenever-web
|
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
|
- Bartosz Kopinski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,12 +78,19 @@ files:
|
|
78
78
|
- LICENSE
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
|
-
- app/controllers/whenever/application_controller.rb
|
82
81
|
- app/controllers/whenever/jobs_controller.rb
|
82
|
+
- app/controllers/whenever/logs_controller.rb
|
83
|
+
- app/controllers/whenever/web_controller.rb
|
83
84
|
- app/helpers/whenever/jobs_helper.rb
|
85
|
+
- app/models/whenever/cron_tab.rb
|
86
|
+
- app/models/whenever/log.rb
|
87
|
+
- app/models/whenever/web_config.rb
|
84
88
|
- app/models/whenever/web_job.rb
|
85
89
|
- app/models/whenever/web_job_list.rb
|
90
|
+
- app/services/whenever/job_runner.rb
|
86
91
|
- app/views/whenever/jobs/index.html.erb
|
92
|
+
- app/views/whenever/layouts/admin.html.haml
|
93
|
+
- config/locales/en.yml
|
87
94
|
- config/routes.rb
|
88
95
|
- lib/whenever/patches/job.rb
|
89
96
|
- lib/whenever/patches/job_list.rb
|
@@ -109,8 +116,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
116
|
version: '0'
|
110
117
|
requirements: []
|
111
118
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.2.
|
119
|
+
rubygems_version: 2.2.2
|
113
120
|
signing_key:
|
114
121
|
specification_version: 4
|
115
122
|
summary: Web GUI for Whenever gem
|
116
123
|
test_files: []
|
124
|
+
has_rdoc:
|