kimurai-dashboard 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d45c04e24e2f570510b38e3027958d190e39cb8cc3991f03925691acc5c0a4cf
4
- data.tar.gz: 8833f523ebc1f303d48a5ad9107c0ecc1e33f36d0e0aa987206f13f30508e26a
3
+ metadata.gz: 4076735ad425281574a5bf8352235ef4afe94be5a9457af82cce178c16baa15d
4
+ data.tar.gz: c6a6536f7e7e5e2a6e5e73fb02fc3f6d049c0f917a4e7cfe09062b6bbd2d054b
5
5
  SHA512:
6
- metadata.gz: e12f971ce5e9c6dab110cae9e6975f4ace11ffac1c1a607d855e5d32b2662bdb3619fd08a4921b0f58f90dc30634a18ade29ead57273bcbc8b525c9786e6fc13
7
- data.tar.gz: ff659649fb65ab2c7953e9544dc6ea3bc3a0196bd150d812316fb3f9ca8652a667c31c37e6d6a5643ff8804d5f29d3dbd57bc63b13ebc7eb5a05df2401f78833
6
+ metadata.gz: 245e2444dd1ddf1db5f969a29e57f741a086527f6c511952b16d74dfbf35b8e1f52bc68e7e2cbba3c281bb50bbe4aa37d4be8651db57dd2edb6f49cfbb805255
7
+ data.tar.gz: 5f3b06c071f15a45f1833f8f11cb603f0c24a12847850d5dbd6a7e6e1159b06ee457616d428e807b812cc6b61bf4a9b91be9753a890f9e4643c103e5ba6f6c18
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
  spec.required_ruby_version = ">= 2.5.0"
21
21
 
22
- spec.add_dependency "kimurai", "~> 1.2.0"
22
+ spec.add_dependency "kimurai", ">= 1.3.0"
23
23
  spec.add_dependency "sequel"
24
24
  spec.add_dependency "sinatra-contrib"
25
25
  spec.add_dependency "pagy"
@@ -11,35 +11,35 @@ module Kimurai
11
11
 
12
12
  DB.create_table?(:sessions) do
13
13
  primary_key :id, type: :integer, auto_increment: false
14
- string :status
15
- datetime :start_time, empty: false
16
- datetime :stop_time
17
- string :environment
18
- integer :concurrent_jobs
19
- text :spiders
20
- text :error
14
+ String :status
15
+ Time :start_time, empty: false
16
+ Time :stop_time
17
+ String :environment
18
+ Integer :concurrent_jobs
19
+ String :spiders, text: true
20
+ String :error, text: true
21
21
  end
22
22
 
23
- DB.create_table?(:runs) do
23
+ DB.create_table?(:spiders) do
24
24
  primary_key :id
25
- string :spider_name, empty: false
26
- string :status
27
- string :environment
28
- datetime :start_time, empty: false
29
- datetime :stop_time
30
- float :running_time
31
- foreign_key :session_id, :sessions
32
- foreign_key :spider_id, :spiders
33
- text :visits
34
- text :items
35
- text :events
36
- text :error
37
- text :server
25
+ String :name, empty: false, unique: true
38
26
  end
39
27
 
40
- DB.create_table?(:spiders) do
28
+ DB.create_table?(:runs) do
41
29
  primary_key :id
42
- string :name, empty: false, unique: true
30
+ String :spider_name, empty: false
31
+ String :status
32
+ String :environment
33
+ Time :start_time, empty: false
34
+ Time :stop_time
35
+ Float :running_time
36
+ foreign_key :session_id, :sessions
37
+ foreign_key :spider_id, :spiders
38
+ String :visits, text: true
39
+ String :items, text: true
40
+ String :events, text: true
41
+ String :error, text: true
42
+ String :server, text: true
43
43
  end
44
44
  end
45
45
  end
@@ -118,13 +118,7 @@ module Kimurai
118
118
  end
119
119
 
120
120
  get "/:id_or_name" do
121
- @spider =
122
- if params[:id_or_name].match?(/^(\d)+$/)
123
- Spider.find(id: params[:id_or_name].to_i)
124
- else
125
- Spider.find(name: params[:id_or_name])
126
- end
127
-
121
+ find_spider
128
122
  halt "Error, can't find spider!" unless @spider
129
123
 
130
124
  @spider_runs = @spider.runs_dataset.reverse_order(:id)
@@ -134,10 +128,32 @@ module Kimurai
134
128
  f.html { erb :'spiders/show' }
135
129
  end
136
130
  end
131
+
132
+ get "/:id_or_name/log" do
133
+ find_spider
134
+ halt "Error, can't find spider!" unless @spider
135
+
136
+ log_name = "./log/#{@spider.name}.log"
137
+ if File.exists?(log_name)
138
+ content_type 'text/event-stream'
139
+ File.readlines(log_name)
140
+ else
141
+ halt "There is not log file for this spider yet"
142
+ end
143
+ end
137
144
  end
138
145
 
139
146
  private
140
147
 
148
+ def find_spider
149
+ @spider =
150
+ if params[:id_or_name].match?(/^(\d)+$/)
151
+ Spider.find(id: params[:id_or_name].to_i)
152
+ else
153
+ Spider.find(name: params[:id_or_name])
154
+ end
155
+ end
156
+
141
157
  def pagy_get_vars(collection, vars)
142
158
  {
143
159
  count: collection.count,
@@ -23,15 +23,15 @@ module Kimurai::Dashboard
23
23
  end
24
24
 
25
25
  def running_runs
26
- runs_dataset.where(status: "running").all
26
+ runs_dataset.where(status: "running").order(:id).all
27
27
  end
28
28
 
29
29
  def failed_runs
30
- runs_dataset.where(status: "failed").all
30
+ runs_dataset.where(status: "failed").order(:id).all
31
31
  end
32
32
 
33
33
  def completed_runs
34
- runs_dataset.where(status: "completed").all
34
+ runs_dataset.where(status: "completed").order(:id).all
35
35
  end
36
36
  end
37
37
  end
@@ -16,5 +16,13 @@ module Kimurai::Dashboard
16
16
  def current_state
17
17
  running? ? "running" : "stopped"
18
18
  end
19
+
20
+ def latest_run
21
+ runs_dataset.last
22
+ end
23
+
24
+ def latest_log
25
+ #
26
+ end
19
27
  end
20
28
  end
@@ -1,5 +1,5 @@
1
1
  module Kimurai
2
2
  module Dashboard
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -25,12 +25,7 @@
25
25
  <tr>
26
26
  <th>Latest log</th>
27
27
  <td>
28
- <% if latest = @spider.runs_dataset.last %>
29
- <a target="_blank" href="/runs/<%= latest.id %>/log"><%= latest.spider_name %>.log</a>
30
- (run <a href="/runs/<%= latest.id %>">#<%= latest.id %></a>)
31
- <% else %>
32
- Not available
33
- <% end %>
28
+ <a target="_blank" href="/spiders/<%= @spider.id %>/log"><%= @spider.name %>.log</a>
34
29
  </td>
35
30
  </tr>
36
31
  </tbody>
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kimurai-dashboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Afanasev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-20 00:00:00.000000000 Z
11
+ date: 2018-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kimurai
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.0
19
+ version: 1.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.0
26
+ version: 1.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sequel
29
29
  requirement: !ruby/object:Gem::Requirement