batch_manager 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mjc1M2YyMmMxMDA0MjlmN2I5NDZhNzJlNGUyMWVkZGRjZmZiMTljNA==
4
+ NmYzM2MwZmQyZWY1NjE3YWNjY2U0N2NlYjkwYjNlNjRjZjgwNzMyZQ==
5
5
  data.tar.gz: !binary |-
6
- YzZhNmQ5MDNhZjFmNTA4NDQ0Mjg2YzJjMmI2OTI2NzUzMDhjM2NlYQ==
6
+ MTM2Zjk1NzA5YzQwZGRmMTJlZTkwMGRjNmYyZThmMTY1ZTQ2Yzc1Ng==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OGE1MzRlMjFiNDY0YWFjMzEyNTcyYWNlNzc4YTgzYmViNmVhOWEyMjg3MDVj
10
- NDFjM2QwYTY5YzFkMzE1YTFmODY5MzZkNGE4Y2U3MTdmZjkyMTdjMDAxYWY4
11
- MmM1MDQ3ZDUxZDQ2OWI3YzE3Y2VkODBkZWU2N2Q0YjJhYmZiY2Y=
9
+ NTM3OThhMTA0OTM3YWYyY2E4NDdmOGVjZTk5ZDIyYzdiODcxYmM1YWZiMjlj
10
+ OTFlZjFkY2JmYTJmNTNiYWYyNGRlMjJjNWVlOTc1NmI3YjdmZTM4MjAwN2Q0
11
+ N2QwYzI0MDRiZmQyYTAxNzI5OWYzZDMyN2QyMmZlNTEzMmQ5MTk=
12
12
  data.tar.gz: !binary |-
13
- MzY3YzVmNzVhMGFkMjcxYWI5NmQ3YjYzZjg0MTEyMWVmZGQ0YTNkMmZjNDA3
14
- OTAzNjQyZGIyMjQ3ZjFkN2RmODkwNjJkNDQ1ZjEzYjg2OTIzMGQzNDZlYjUw
15
- YjgxYzEzMWQzMWMyZTg4OTM5NGQ5NWQzYzJiYjc2NGZiMTlmMGQ=
13
+ MjdlZWI0NDJlZjY2Y2U5Zjc3YTlmMDdkYmZmYjI5NmVmOTYyYmQ3ODQwYzUy
14
+ ZGQwZTQzZTExY2JlZmRhMmYzN2IwMTJiMGE3NzYzOWY5Zjc5Y2UzYjNjZTE0
15
+ YjA0ZGZmMTgwMWNlM2JkYzc3NjI3YzQ5NTkwNDUyMDg3OGM1YTA=
@@ -2,3 +2,102 @@
2
2
  *= require_self
3
3
  *= require_tree .
4
4
  */
5
+
6
+ body {
7
+ margin: 0;
8
+ padding: 0;
9
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
10
+ font-size: 13px;
11
+ line-height: 18px;
12
+ color: #333;
13
+ background: #fff;
14
+ }
15
+
16
+ #wrapper {
17
+ width: 1200px;
18
+ margin: 0 auto;
19
+ min-height: 600px;
20
+ }
21
+
22
+ header {
23
+ height: 36px;
24
+ padding: 5px;
25
+ background: #F1F1F1;
26
+ -webkit-box-shadow: 0 1px 10px rgba(0,0,0,0.1);
27
+ -moz-box-shadow: 0 1px 10px rgba(0,0,0,0.1);
28
+ box-shadow: 0 1px 10px rgba(0,0,0,0.1);
29
+ border-bottom: 1px solid #d4d4d4;
30
+ margin-bottom: 20px;
31
+ }
32
+
33
+ header .inner {
34
+ width: 1200px;
35
+ margin: 0 auto;
36
+ }
37
+
38
+ header h1 {
39
+ float: left;
40
+ margin: 0;
41
+ padding: 0;
42
+ font-family: "Yanone",sans-serif;
43
+ font-size: 18px;
44
+ line-height: 36px;
45
+ font-weight: normal;
46
+ color: #777777;
47
+ text-shadow: 0 1px 0 #ffffff;
48
+ }
49
+
50
+ .title {
51
+ padding-bottom: 20px;
52
+ margin-bottom: 25px;
53
+ border-bottom: 1px solid #e2e2e2;
54
+ }
55
+
56
+ h2 {
57
+ color: #777;
58
+ font-size: 18px;
59
+ line-height: 18px;
60
+ margin: 0;
61
+ padding: 0;
62
+ }
63
+
64
+ textarea {
65
+ border: 1px solid #ccc;
66
+ color: #333;
67
+ padding: 10px;
68
+ box-sizing: border-box;
69
+ }
70
+
71
+ footer {
72
+ text-align: center;
73
+ padding: 30px 0;
74
+ margin-top: 70px;
75
+ border-top: 1px solid #e5e5e5;
76
+ background-color: #f5f5f5;
77
+ }
78
+
79
+ footer p {
80
+ padding: 0;
81
+ margin: 0;
82
+ color: #999;
83
+ text-shadow: 0 1px 1px #ffffff;
84
+ }
85
+
86
+ footer a {
87
+ color: #999;
88
+ font-weight: bold;
89
+ text-decoration: none;
90
+ }
91
+
92
+ footer a:hover {
93
+ color: #777;
94
+ text-decoration: underline;
95
+ }
96
+
97
+ .group:after {
98
+ content: ".";
99
+ display: block;
100
+ height: 0;
101
+ clear: both;
102
+ visibility: hidden;
103
+ }
@@ -0,0 +1,57 @@
1
+ .btn {
2
+ display: inline-block;
3
+ padding: 2px 8px;
4
+ margin-bottom: 0;
5
+ font-size: 12px;
6
+ line-height: 12px;
7
+ text-align: center;
8
+ vertical-align: middle;
9
+ cursor: pointer;
10
+ text-decoration: none;
11
+ border: 1px solid #bbb;
12
+ border-color: #BBB;
13
+ text-shadow: 0 1px 1px #fff;
14
+ }
15
+
16
+ .btn.large {
17
+ padding: 4px 12px;
18
+ font-size: 14px;
19
+ line-height: 14px;
20
+ }
21
+
22
+ .btn.info {
23
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#f1f1f1), to(#e1e1e1));
24
+ background-image: -webkit-linear-gradient(#f1f1f1, #e1e1e1);
25
+ background-image: -moz-linear-gradient(#f1f1f1, #e1e1e1);
26
+ background-repeat: repeat-x;
27
+ color: #777;
28
+ }
29
+
30
+ .btn.info:hover {
31
+ background: #f1f1f1;
32
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fAfAfA), to(#f1f1f1));
33
+ background-image: -webkit-linear-gradient(#fAfAfA, #f1f1f1);
34
+ background-image: -moz-linear-gradient(#fAfAfA, #f1f1f1);
35
+ color: #333;
36
+ }
37
+
38
+ .btn.danger {
39
+ background-color: #da4f49;
40
+ background-image: -moz-linear-gradient(top, #ee5f5b, #bd362f);
41
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ee5f5b), to(#bd362f));
42
+ background-image: -webkit-linear-gradient(top, #ee5f5b, #bd362f);
43
+ background-image: linear-gradient(to bottom, #ee5f5b, #bd362f);
44
+ background-repeat: repeat-x;
45
+ border-color: #bd362f #bd362f #802420;
46
+ color: #fff;
47
+ text-shadow: none;
48
+ }
49
+
50
+ .btn.danger:hover {
51
+ background: #EE4E49;
52
+ }
53
+
54
+ .btn.disabled {
55
+ color: #999;
56
+ background: #eee;
57
+ }
@@ -0,0 +1,20 @@
1
+ .label {
2
+ display: inline-block;
3
+ padding: 2px 4px;
4
+ font-size: 11.844px;
5
+ font-weight: bold;
6
+ line-height: 14px;
7
+ color: #ffffff;
8
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
9
+ white-space: nowrap;
10
+ vertical-align: baseline;
11
+ background-color: #999999;
12
+ }
13
+
14
+ .label.info {
15
+ background-color: #3a87ad;
16
+ }
17
+
18
+ .label.warn {
19
+ background-color: #f89406;
20
+ }
@@ -0,0 +1,24 @@
1
+ .alert {
2
+ padding: 8px 35px 8px 14px;
3
+ margin: 20px auto;
4
+ text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
5
+ background-color: #fcf8e3;
6
+ border: 1px solid #fbeed5;
7
+ -webkit-border-radius: 4px;
8
+ -moz-border-radius: 4px;
9
+ border-radius: 4px;
10
+ width: 600px;
11
+ text-align: center;
12
+ }
13
+
14
+ .alert.notice {
15
+ color: #468847;
16
+ background-color: #dff0d8;
17
+ border-color: #d6e9c6;
18
+ }
19
+
20
+ .alert.error {
21
+ color: #b94a48;
22
+ background-color: #f2dede;
23
+ border-color: #eed3d7;
24
+ }
@@ -0,0 +1,33 @@
1
+ table {
2
+ width: 100%;
3
+ color: #555;
4
+ border-collapse: collapse;
5
+ border-spacing: 0;
6
+ background-color: #ffffff;
7
+ background: #F9F9F9;
8
+ margin-bottom: 25px;
9
+ border: 1px solid #ccc;
10
+ -webkit-box-shadow: 0 0 0 3px #f1f1f1;
11
+ -moz-box-shadow: 0 0 0 3px #f1f1f1;
12
+ box-shadow: 0 0 0 3px #f1f1f1;
13
+ }
14
+
15
+ td, th {
16
+ border: 1px solid #ccc;
17
+ line-height: 13px;
18
+ }
19
+
20
+ th {
21
+ color: #666;
22
+ text-align:center;
23
+ padding: 10px;
24
+ background-color: #eee;
25
+ background-image: -webkit-gradient(linear, 0 0, 0 30, color-stop(0.066, #eee), to(#dfdfdf));
26
+ background-image: -webkit-linear-gradient(#eee 6.6%, #dfdfdf);
27
+ text-shadow: 0 1px 1px #fff;
28
+ }
29
+
30
+ td {
31
+ padding: 10px;
32
+ color: #777;
33
+ }
@@ -1,12 +1,23 @@
1
1
  module BatchManager
2
2
  class BatchesController < ApplicationController
3
+ include BatchManager::Utils
3
4
  before_filter :retain_batch_params, :except => [:index]
5
+ helper_method :escape_batch_name
4
6
 
5
7
  def index
6
8
  @resque_supported = resque_supported?
7
9
  @details = BatchManager::Monitor.details
8
10
  end
9
11
 
12
+ def edit
13
+ @content = File.read(batch_full_path(@batch_name))
14
+ end
15
+
16
+ def update
17
+ File.open(batch_full_path(@batch_name), "w") { |f| f << params[:content] }
18
+ redirect_to(batches_url, :notice => "#{@batch_name} updated.")
19
+ end
20
+
10
21
  def exec
11
22
  if resque_supported?
12
23
  Resque.enqueue(BatchManager::ExecBatchWorker, @batch_name, :wet => @wet)
@@ -17,20 +28,33 @@ module BatchManager
17
28
  end
18
29
  end
19
30
 
31
+ def log
32
+ @offset = log_file.size
33
+ @content = log_file.read
34
+ end
35
+
20
36
  def async_read_log
21
37
  log_file.seek(params[:offset].to_i) if params[:offset].present?
22
38
  render :json => {:content => log_file.read, :offset => log_file.size}
23
39
  end
24
40
 
25
- def log
26
- @offset = log_file.size
27
- @content = log_file.read
41
+ def remove_log
42
+ FileUtils.rm(BatchManager::Logger.log_file_path(@batch_name, @wet))
43
+ redirect_to(batches_url, :notice => "Log removed.")
44
+ end
45
+
46
+ def escape_batch_name(name)
47
+ name.gsub("/", "|")
48
+ end
49
+
50
+ def unescape_batch_name(name)
51
+ name.gsub("|", "/")
28
52
  end
29
53
 
30
54
  private
31
55
 
32
56
  def retain_batch_params
33
- @batch_name = params[:batch_name]
57
+ @batch_name = unescape_batch_name(params[:id])
34
58
  @wet = params[:wet]
35
59
  end
36
60
 
@@ -40,7 +64,7 @@ module BatchManager
40
64
  @log_file ||= File.open(BatchManager::Logger.log_file_path(@batch_name, @wet), 'r')
41
65
  return @log_file
42
66
  rescue
43
- sleep 3
67
+ sleep 2
44
68
  retry
45
69
  end
46
70
  end
@@ -0,0 +1,10 @@
1
+ <div class="group title">
2
+ <h2 style="float:left;">Edit Batch</h2>
3
+ <div class="label" style="float:left;margin-left:25px;"><%= @batch_name %></div>
4
+ </div>
5
+ <%= form_tag batch_url(escape_batch_name(@batch_name)), :method => :put do %>
6
+ <%= text_area_tag :content, @content, style: "width:100%;height:500px;" %>
7
+ <div style="margin-top:15px;">
8
+ <%= submit_tag "Save", :class => "btn info large" %>
9
+ </div>
10
+ <% end %>
@@ -1,9 +1,21 @@
1
- <h2>Batches</h2>
2
- <% if @resque_supported %>
3
- <div class="resque_label support">Resque worker found</div>
4
- <% else %>
5
- <div class="resque_label not_support">Resque or Resque worker not found</div>
6
- <% end %>
1
+ <div class="group title">
2
+ <h2 style="float:left;">Batches</h2>
3
+ <div style="float:right;text-align:right;">
4
+ <% if @resque_supported %>
5
+ <div class="label info">Resque worker found</div>
6
+ <% else %>
7
+ <div class="label warn">Resque or Resque worker not found</div>
8
+ <% end %>
9
+ </div>
10
+ </div>
11
+ <div class="group">
12
+ <% if flash[:notice] %>
13
+ <div class="alert notice"><%= flash[:notice] %></div>
14
+ <% end %>
15
+ <% if flash[:error] %>
16
+ <div class="alert error"><%= flash[:error] %></div>
17
+ <% end %>
18
+ </div>
7
19
  <table>
8
20
  <tr>
9
21
  <th>Managed?</th>
@@ -28,18 +40,26 @@
28
40
  <td style="text-align:center;"><%= status.created_at.strftime('%Y-%m-%d %H:%M:%S') if status.created_at %></td>
29
41
  <td style="text-align:center;">
30
42
  <% if File.exist?(BatchManager::Logger.log_file_path(status.name)) %>
31
- <%= link_to "dry", log_batches_url(:batch_name => status.name) %>
43
+ <%= link_to "DRY", log_batch_url(escape_batch_name(status.name)), :class => "btn info" %>
44
+ <%= link_to "X", remove_log_batch_url(escape_batch_name(status.name)), :class => "btn danger", :onclick => "return confirm('Are you sure?')" %>
32
45
  <% end %>
33
46
  <% if File.exist?(BatchManager::Logger.log_file_path(status.name, true)) %>
34
- <%= link_to "wet", log_batches_url(:batch_name => status.name, :wet => true) %>
47
+ <%= link_to "WET", log_batch_url(escape_batch_name(status.name), :wet => true), :class => "btn info" %>
48
+ <%= link_to "X", remove_log_batch_url(escape_batch_name(status.name), :wet => true), :class => "btn danger", :onclick => "return confirm('Are you sure?')" %>
35
49
  <% end %>
36
50
  </td>
37
51
  <td style="text-align:center;">
52
+ <%= link_to "EDIT", edit_batch_url(escape_batch_name(status.name)), :class => "btn info" %>
38
53
  <% if status.managed? %>
39
- <%= link_to "dry run", exec_batches_url(:batch_name => status.name) %>
54
+ <%= link_to "DRY RUN", exec_batch_url(escape_batch_name(status.name)), :class => "btn info" %>
40
55
  <% if status.can_run? %>
41
- <%= link_to "wet run", exec_batches_url(:batch_name => status.name, :wet => true), :class => "danger", :onclick => "return confirm('Are you sure?')" %>
56
+ <%= link_to "WET RUN", exec_batch_url(escape_batch_name(status.name), :wet => true), :class => "btn danger", :onclick => "return confirm('Are you sure?')" %>
57
+ <% else %>
58
+ <%= link_to "WET RUN", "#", :class => "btn disabled", :onclick => "return false" %>
42
59
  <% end %>
60
+ <% else %>
61
+ <%= link_to "DRY RUN", "#", :class => "btn disabled", :onclick => "return false" %>
62
+ <%= link_to "WET RUN", "#", :class => "btn disabled", :onclick => "return false" %>
43
63
  <% end %>
44
64
  </td>
45
65
  </tr>
@@ -2,7 +2,7 @@
2
2
  <script>
3
3
  function read_log() {
4
4
  offset = $("#offset").val();
5
- $.get('<%= async_read_log_batches_url(:batch_name => @batch_name, :wet => @wet) %>' + '&offset=' + offset, function(data) {
5
+ $.get('<%= async_read_log_batch_url(escape_batch_name(@batch_name), :wet => @wet) %>' + '&offset=' + offset, function(data) {
6
6
  $("#log_box").val($("#log_box").val() + data.content);
7
7
  $("#offset").val(data.offset);
8
8
  scrollLogBoxDown();
@@ -13,12 +13,18 @@
13
13
  logBox.scrollTop(logBox[0].scrollHeight - logBox.height());
14
14
  }
15
15
  $(function() {
16
- setInterval(read_log, 1000);
16
+ setInterval(read_log, 2000);
17
17
  });
18
18
  </script>
19
19
  <% end %>
20
20
 
21
- <h2><%= @batch_name %><h2>
21
+ <div class="group title">
22
+ <h2><%= @batch_name %></h2>
23
+ </div>
22
24
 
23
- <%= text_area_tag :log, @content, :id => "log_box" %>
25
+ <%= text_area_tag :log, @content, :id => "log_box", style: "width:100%;height:500px;" %>
24
26
  <%= hidden_field_tag :offset, @offset, :id => :offset %>
27
+
28
+ <div style="margin-top:15px;">
29
+ <%= link_to "Back to list", batches_url, :class => "btn info large" %>
30
+ </div>
@@ -8,7 +8,19 @@
8
8
  </head>
9
9
  <body>
10
10
 
11
- <%= yield %>
11
+ <header>
12
+ <div class="inner">
13
+ <h1>BatchManager</h1>
14
+ </div>
15
+ </header>
16
+
17
+ <div id="wrapper">
18
+ <%= yield %>
19
+ </div>
20
+
21
+ <footer>
22
+ <p><a href="https://github.com/cctiger36/batch_manager">BatchManager</a> VERSION <%= BatchManager::VERSION %></p>
23
+ </footer>
12
24
 
13
25
  </body>
14
26
  </html>
data/config/routes.rb CHANGED
@@ -3,10 +3,11 @@ BatchManager::Engine.routes.draw do
3
3
  root :to => "batches#index"
4
4
 
5
5
  resources :batches do
6
- collection do
6
+ member do
7
7
  get :exec
8
8
  get :log
9
9
  get :async_read_log
10
+ get :remove_log
10
11
  end
11
12
  end
12
13
 
@@ -1,3 +1,3 @@
1
1
  module BatchManager
2
- VERSION = "0.2.8"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batch_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weihu Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-10 00:00:00.000000000 Z
11
+ date: 2013-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -119,9 +119,13 @@ extra_rdoc_files: []
119
119
  files:
120
120
  - app/assets/javascripts/batch_manager/application.js
121
121
  - app/assets/stylesheets/batch_manager/application.css
122
- - app/assets/stylesheets/batch_manager/batches.css
122
+ - app/assets/stylesheets/batch_manager/button.css
123
+ - app/assets/stylesheets/batch_manager/label.css
124
+ - app/assets/stylesheets/batch_manager/notice.css
125
+ - app/assets/stylesheets/batch_manager/table.css
123
126
  - app/controllers/batch_manager/application_controller.rb
124
127
  - app/controllers/batch_manager/batches_controller.rb
128
+ - app/views/batch_manager/batches/edit.html.erb
125
129
  - app/views/batch_manager/batches/index.html.erb
126
130
  - app/views/batch_manager/batches/log.html.erb
127
131
  - app/views/layouts/batch_manager/application.html.erb
@@ -1,70 +0,0 @@
1
- body {
2
- width: 1200px;
3
- margin: 0 auto;
4
- }
5
-
6
- table {
7
- width: 100%;
8
- border-collapse:collapse;
9
- border-spacing:0;
10
- background-color:#ffffff;
11
- empty-cells:show;
12
- }
13
-
14
- td, th {
15
- border:1px solid #663300;
16
- }
17
-
18
- th {
19
- color:#FFF;
20
- background-color:#996633;
21
- background-position:left top;
22
- padding:0.1em 0.5em;
23
- text-align:center;
24
- }
25
-
26
- th a {
27
- color: #FFF;
28
- text-decoration: underline;;
29
- }
30
-
31
- td {
32
- padding:0.1em 0.5em;
33
- }
34
-
35
- tr.odd {
36
- background-color:#ffffcc;
37
- }
38
-
39
- tr.attention {
40
- background-color:#ffaaaa;
41
- }
42
-
43
- tr.disable {
44
- background-color:#aaaaaa;
45
- }
46
-
47
- tr.even.disable {
48
- background-color:#bbbbbb;
49
- }
50
-
51
- tr.odd.disable {
52
- background-color:#bbbbaa;
53
- }
54
-
55
- #log_box {
56
- width: 100%;
57
- height:500px;
58
- }
59
-
60
- .resque_label {
61
- text-align: right;
62
- }
63
-
64
- .resque_label.support {
65
- color: green;
66
- }
67
-
68
- .resque_label.not_support {
69
- color: red;
70
- }