tailog 0.5.9 → 0.6.0

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: d16334b0b46319a4bb6d4720e7b56fbf592dc52a
4
- data.tar.gz: 34f8c3e366866577ab881d52dca2b4a74f915b07
3
+ metadata.gz: 8c4a061b770009df2e91f93ac5b5dad228187bde
4
+ data.tar.gz: 46d65f82419ac331348bdcb5025e6d0c0bd8de55
5
5
  SHA512:
6
- metadata.gz: fb383a70f5fea68ec6c4ebe74a8e3db0335be9bdcea5f75d3f6a8d248534e918711f33d56341782f1ca828a63435b6f0a549f043d2c6ca9f0b379a3abd55c57f
7
- data.tar.gz: 2ffe49df29b8fbb5a12b8bfbb98438e131f1791cc82a64fff9f581a2aa21769284c32ccbcea0a7f7a4abfd1f8620c4ee2224ede6c1fa767b08f2d5156b2f8b51
6
+ metadata.gz: 257905134ec95342d84b7521980e84cd9d428f520dd50ac932f09371c3359d90257f83a6a3b912c1217b1459effcec519120f8563c543bbdee9bc5909daacd63
7
+ data.tar.gz: cd734694966ded697fa5c4a3cd1492f448ec7b6ace86d7048c2dfd2bab1476f798afb7d3706482e27e2375c73d7514f1c966d35c7b554e5d7c9f83e64a68af72
@@ -5,9 +5,9 @@
5
5
  <div class="pull-right">
6
6
  <select name="type" class="form-control" id="mode">
7
7
  <option value="ruby">Ruby</option>
8
- <option value="ruby_debug">Ruby (Debug Mode)</option>
9
8
  <option value="bash">Bash</option>
10
9
  </select>
10
+ <button id="broadcast-button" type="submit" class="btn btn-danger">Broadcast</button>
11
11
  <button id="submit-button" type="submit" class="btn btn-primary">Submit</button>
12
12
  </div>
13
13
  <div>
@@ -35,9 +35,8 @@
35
35
  lineNumbers: true
36
36
  });
37
37
 
38
- ModeMap = {
38
+ var ModeMap = {
39
39
  ruby: "ruby",
40
- ruby_debug: "ruby",
41
40
  bash: "shell"
42
41
  };
43
42
 
@@ -45,30 +44,101 @@
45
44
  editor.setOption("mode", ModeMap[$(this).val()]);
46
45
  });
47
46
 
47
+ var $content = $("#content"),
48
+ $script = $("#script");
48
49
 
49
- var $content = $("#content");
50
-
51
- $("#script").ajaxForm({
52
- beforeSend: function() {
53
- $content
54
- .html("<hr/>")
55
- .append('<span class="text-info">Loading...</span>')
56
- },
57
- error: function() {
58
- $content
59
- .html("<hr/>")
60
- .append('<span class="text-danger">Oops! Something went wrong, please try again later!</span>')
61
- },
62
- success: function(json) {
63
- try {
64
- var data = JSON.parse(json);
50
+ $("#submit-button").click(function(event) {
51
+ event.preventDefault();
52
+ editor.save();
53
+
54
+ $script.ajaxSubmit({
55
+ beforeSend: function() {
56
+ $content
57
+ .html("<hr/>")
58
+ .append('<span class="text-info">Loading...</span>');
59
+ },
60
+ error: function() {
65
61
  $content
66
62
  .html("<hr/>")
67
- .append('<span class="text-info">' + data.server_hostname + "</span>")
68
- .append(ansi_up.ansi_to_html(data.content));
69
- } catch (error) {
70
- console.error(error)
63
+ .append('<span class="text-danger">Oops! Something went wrong, please try again later!</span>');
64
+ },
65
+ success: function(json) {
66
+ try {
67
+ var data = JSON.parse(json);
68
+ $content
69
+ .html("<hr/>")
70
+ .append('<span class="text-info">' + data.server_hostname + " - " + data.process_uuid + "</span>")
71
+ .append(ansi_up.ansi_to_html(data.content));
72
+ } catch (error) {
73
+ console.error(error)
74
+ }
75
+ }
76
+ });
77
+ });
78
+
79
+ $("#broadcast-button").click(function(event) {
80
+ event.preventDefault();
81
+ editor.save();
82
+
83
+ $content
84
+ .html("<hr/>")
85
+ .append('<div class="progress"><div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" style="width: 0%"><span class="progress-bar-indicator">0 / 1 Requests, 0 Instances (0%)</span></div></div>');
86
+ var $progressBar = $(".progress-bar"),
87
+ $indicator = $(".progress-bar-indicator");
88
+
89
+ var MaxCurrent = 10;
90
+ var discovered = [],
91
+ totalEstimate = 1,
92
+ currentTries = 0,
93
+ concurrent = 0;
94
+
95
+ var ajaxInterval = setInterval(function() {
96
+ if (currentTries < totalEstimate) {
97
+ if (concurrent < MaxCurrent) {
98
+ $script.ajaxSubmit({
99
+ data: {
100
+ broadcast: true,
101
+ discovered_instances: discovered
102
+ },
103
+ beforeSend: function() {
104
+ currentTries += 1;
105
+ concurrent += 1;
106
+ },
107
+ error: function() {
108
+ $content
109
+ .html("<hr/>")
110
+ .append('<span class="text-danger">Oops! Something went wrong, please try again later!</span>')
111
+ },
112
+ success: function(json) {
113
+ try {
114
+ var data = JSON.parse(json);
115
+
116
+ var instanceId = data.instance_id;
117
+ if (discovered.indexOf(instanceId) < 0) {
118
+ totalEstimate += currentTries * 2 + 2;
119
+ discovered.push(instanceId);
120
+
121
+ $content
122
+ .append('<hr/><span class="text-info">' + data.server_hostname + " - " + data.process_uuid + "</span>")
123
+ .append(ansi_up.ansi_to_html(data.content));
124
+ }
125
+
126
+ var percent = +parseFloat(currentTries / totalEstimate * 100).toFixed(2);
127
+ $indicator.text(currentTries + " / " + totalEstimate + " Requests, " + discovered.length + " Instances (" + percent + "%)");
128
+ $progressBar.width(percent + "%");
129
+
130
+ } catch (error) {
131
+ console.error(error)
132
+ }
133
+ },
134
+ complete: function() {
135
+ concurrent -= 1;
136
+ }
137
+ });
138
+ }
139
+ } else {
140
+ clearInterval(ajaxInterval);
71
141
  }
72
- }
142
+ }, 100);
73
143
  });
74
144
  </script>
@@ -1,10 +1,19 @@
1
1
  <% begin %>
2
- <% output = StringIO.new %>
2
+ <% irb = IRB::Irb.new nil, StringInputMethod.new(script + "\nexit\n") %>
3
+ <% IRB.conf[:MAIN_CONTEXT] = irb.context %>
4
+ <% IRB.conf[:OUTPUT] = [] %>
3
5
 
4
6
  <% begin %>
5
- <% output.send :eval, script %>
6
- <% output.string.each_line do |line| %>
7
- <p><%= h line %></p>
7
+ <% irb.eval_input %>
8
+ <% IRB.Output.each do |key, line| %>
9
+ <% case key
10
+ when :stdin %>
11
+ <p class="text-info"><%= h line %></p>
12
+ <% when :stdout %>
13
+ <p><%= h line %></p>
14
+ <% when :stderr %>
15
+ <p class="text-danger"><%= h line %></p>
16
+ <% end %>
8
17
  <% end %>
9
18
  <% rescue => error %>
10
19
  <p class="text-danger"><%= h error.class %>: <%= h error.message %></p>
@@ -18,6 +18,10 @@ def IRB.evaluate_string string
18
18
  irb.eval_input
19
19
  end
20
20
 
21
+ def IRB.irb_exit irb, ret
22
+ ret
23
+ end
24
+
21
25
  class IRB::WorkSpace
22
26
  def evaluate(context, statements, file = __FILE__, line = __LINE__)
23
27
  @after_ruby_debug_erb = false
@@ -1,3 +1,3 @@
1
1
  module Tailog
2
- VERSION = "0.5.9"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/tailog.rb CHANGED
@@ -20,6 +20,10 @@ module Tailog
20
20
  def server_hostname
21
21
  @server_hostname ||= Socket.gethostname
22
22
  end
23
+
24
+ def process_uuid
25
+ @process_uuid ||= SecureRandom.uuid
26
+ end
23
27
  end
24
28
 
25
29
  self.log_path = File.expand_path("log", Dir.pwd)
@@ -62,6 +66,7 @@ module Tailog
62
66
 
63
67
  {
64
68
  server_hostname: Tailog.server_hostname,
69
+ process_uuid: Tailog.process_uuid,
65
70
  file_size: file_size,
66
71
  content: content
67
72
  }.to_json
@@ -76,12 +81,21 @@ module Tailog
76
81
  end
77
82
 
78
83
  post '/script' do
79
- content = erb :"script/#{params[:type]}", locals: { script: params[:script] }, layout: false
80
-
81
- {
84
+ result = {
82
85
  server_hostname: Tailog.server_hostname,
83
- content: content
84
- }.to_json
86
+ process_uuid: Tailog.process_uuid
87
+ }
88
+
89
+ ignore_content = false
90
+ if params[:broadcast]
91
+ instance_id = result[:instance_id] = params[:type] == "bash" ? Tailog.server_hostname : Tailog.process_uuid
92
+ discovered_instances = params[:discovered_instances] || []
93
+ ignore_content = true if discovered_instances.include? instance_id
94
+ end
95
+
96
+ result[:content] = erb :"script/#{params[:type]}", locals: { script: params[:script] }, layout: false unless ignore_content
97
+
98
+ result.to_json
85
99
  end
86
100
  end
87
101
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bbtfr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-25 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -91,7 +91,6 @@ files:
91
91
  - app/views/script/bash.erb
92
92
  - app/views/script/index.erb
93
93
  - app/views/script/ruby.erb
94
- - app/views/script/ruby_debug.erb
95
94
  - bin/console
96
95
  - bin/setup
97
96
  - lib/tailog.rb
@@ -1,28 +0,0 @@
1
- <% begin %>
2
- <% irb = IRB::Irb.new nil, StringInputMethod.new(script + "\n") %>
3
- <% IRB.conf[:MAIN_CONTEXT] = irb.context %>
4
- <% IRB.conf[:OUTPUT] = [] %>
5
-
6
- <% begin %>
7
- <% irb.eval_input %>
8
- <% IRB.Output.each do |key, line| %>
9
- <% case key
10
- when :stdin %>
11
- <p class="text-info"><%= h line %></p>
12
- <% when :stdout %>
13
- <p><%= h line %></p>
14
- <% when :stderr %>
15
- <p class="text-danger"><%= h line %></p>
16
- <% end %>
17
- <% end %>
18
- <% rescue => error %>
19
- <p class="text-danger"><%= h error.class %>: <%= h error.message %></p>
20
- <% error.backtrace.each do |backtrace| %>
21
- <p class="text-danger"> <%= h backtrace %></p>
22
- <% end %>
23
- <% end %>
24
-
25
- <% rescue => error %>
26
- <%= erb :error, locals: { error: error }, layout: false %>
27
- <% end %>
28
-