erd_map 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: 860c0712604342f0e495b6ff55da67a041d7b886bfc7e561aa96c0bf848a3290
4
- data.tar.gz: 89d513411e0732f0583c1613d7ebb961519f0d1248166204289d0c30419578b2
3
+ metadata.gz: ed4d072a4862423c842760702dbb6d1e51d749e3dcb53968a53f34a7780962f6
4
+ data.tar.gz: 5da740ea6a8613083bcb5dcd4274087482189f9cbc0ec8e56e8c4032c4c9e3be
5
5
  SHA512:
6
- metadata.gz: eba427423e7d20c9246b45a7e87a4785da9ebe38a91c303bcbbfe5203013ab47808aa651857f631383cf46414a21319f294e4c2dbd700379451e49b2107595e0
7
- data.tar.gz: 26700b51e97658e85f0cab1f3c4056c50836d4d1a3d60f1cbc4b15ca2e8f4604e25c882d9a91dc5ead1295cca7dc16734fc41316ad7a3395104b4420f67f1acd
6
+ metadata.gz: c887c21acfb720eb0ae8a3a2b5d6aa1caeca816ccf68781384e29a901a2e8dafb30bb6bde4524b3c46319da7ad10e53eb384535c5f01e8733d304cdadd9e86bc
7
+ data.tar.gz: 0ae4645e25e70ad6b709c37ab2525285bf421ede860b9eed22e0ef307fafcfe29461da9fbbe81430030877a269396b7fca2eea43aed0a39aed8f85760daad8d0
data/README.md CHANGED
@@ -37,6 +37,8 @@ pyenv global $(pyenv install --list | grep -E '^\s*[0-9]+\.[0-9]+\.[0-9]+$' | ta
37
37
  ```bash
38
38
  # Install packages, for example with pip
39
39
  pip install networkx bokeh scipy
40
+ # with pip3
41
+ pip3 install networkx bokeh scipy
40
42
  ```
41
43
 
42
44
  ## Installation
@@ -59,7 +61,7 @@ Add the following to your `config/routes.rb` and access `/erd_map` in your brows
59
61
 
60
62
  ```ruby
61
63
  Rails.application.routes.draw do
62
- mount ErdMap::Engine => "erd_map"
64
+ mount ErdMap::Engine => "erd_map" if defined?(ErdMap)
63
65
  end
64
66
  ```
65
67
 
@@ -2,30 +2,22 @@
2
2
 
3
3
  module ErdMap
4
4
  class ErdMapController < ApplicationController
5
- FILE_PATH = Rails.root.join("tmp", "erd_map", "map.html")
6
-
7
5
  skip_forgery_protection
8
6
 
9
7
  def index
10
- if File.exist?(FILE_PATH)
11
- render html: File.read(FILE_PATH).html_safe
8
+ if File.exist?(ErdMap::MAP_FILE)
9
+ render html: File.read(ErdMap::MAP_FILE).html_safe
12
10
  else
13
- _stdout, stderr, status = Open3.capture3("rails runner 'ErdMap::MapBuilder.build'")
14
- if status.success?
15
- render html: File.read(FILE_PATH).html_safe
16
- else
17
- render plain: "Error: #{stderr}", status: :unprocessable_entity
18
- end
11
+ pid = spawn("rails erd_map")
12
+ Process.detach(pid)
19
13
  end
20
14
  end
21
15
 
22
16
  def update
23
- _stdout, stderr, status = Open3.capture3("rails runner 'ErdMap::MapBuilder.build'")
24
- if status.success?
25
- head :ok
26
- else
27
- render json: { message: "Error: \n#{stderr}" }, status: :unprocessable_entity
28
- end
17
+ File.delete(ErdMap::MAP_FILE) if File.exist?(ErdMap::MAP_FILE)
18
+ pid = spawn("rails erd_map")
19
+ Process.detach(pid)
20
+ redirect_to erd_map.root_path, status: :see_other
29
21
  end
30
22
  end
31
23
  end
@@ -0,0 +1,7 @@
1
+ <script>
2
+ document.addEventListener("DOMContentLoaded", () => {
3
+ setInterval(() => { window.location.reload() }, 5000)
4
+ })
5
+ </script>
6
+
7
+ Computing...
@@ -1,3 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ErdMap.py_call_modules = ErdMap::PyCallModules.new
3
+ module ErdMap
4
+ TMP_DIR = Rails.root.join("tmp", "erd_map")
5
+ LOCK_FILE = Rails.root.join("tmp", "erd_map", "task.pid")
6
+ MAP_FILE = Rails.root.join("tmp", "erd_map", "map.html")
7
+ end
@@ -55,13 +55,9 @@ module ErdMap
55
55
  end
56
56
 
57
57
  def save(layout)
58
- tmp_dir = Rails.root.join("tmp", "erd_map")
59
- FileUtils.makedirs(tmp_dir) unless Dir.exist?(tmp_dir)
60
- output_path = File.join(tmp_dir, "map.html")
61
-
62
- bokeh_io.output_file(output_path)
58
+ bokeh_io.output_file(ErdMap::MAP_FILE.to_s)
63
59
  bokeh_io.save(layout)
64
- puts output_path
60
+ puts "[erd_map] #{ErdMap::MAP_FILE} (#{Process.pid})"
65
61
  end
66
62
 
67
63
  def setup_graph_manager(plot)
@@ -106,9 +102,19 @@ module ErdMap
106
102
 
107
103
  class << self
108
104
  def build
109
- Rails.logger.info "build start"
105
+ log "Loading modules starts."
106
+ ErdMap.load_py_call_modules
107
+ log "Loading modules completed."
108
+
109
+ log "Building map starts."
110
110
  new.execute
111
- Rails.logger.info "build completed"
111
+ log "Building map completed."
112
+ end
113
+
114
+ private
115
+
116
+ def log(text)
117
+ puts "[erd_map] #{text} (#{Process.pid})"
112
118
  end
113
119
  end
114
120
  end
data/lib/erd_map/plot.rb CHANGED
@@ -159,19 +159,17 @@ module ErdMap
159
159
  button.disabled = true
160
160
  button.label = "Computing ..."
161
161
 
162
- fetch("/erd_map", { method: "PUT" })
163
- .then(response => {
164
- if (response.ok) { return response.text() }
165
- else { return response.json().then(json => { throw new Error(json.message) }) }
166
- })
167
- .then(data => { window.location.reload() })
168
- .catch(error => {
169
- alert(error.message)
170
- console.error(error)
171
-
172
- button.disabled = false
173
- button.label = "Re-Compute"
174
- })
162
+ const form = document.createElement("form")
163
+ form.method = "POST"
164
+ form.action = "/erd_map"
165
+ form.style.display = "none"
166
+ const input = document.createElement("input")
167
+ input.type = "hidden"
168
+ input.name = "_method"
169
+ input.value = "PUT"
170
+ form.appendChild(input)
171
+ document.body.appendChild(form)
172
+ form.submit()
175
173
  JS
176
174
  )
177
175
  )
@@ -1,3 +1,3 @@
1
1
  module ErdMap
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/erd_map.rb CHANGED
@@ -12,8 +12,8 @@ module ErdMap
12
12
  @py_call_modules
13
13
  end
14
14
 
15
- def py_call_modules=(py_call_modules)
16
- @py_call_modules = py_call_modules
15
+ def load_py_call_modules
16
+ @py_call_modules = ErdMap::PyCallModules.new
17
17
  end
18
18
  end
19
19
  end
@@ -1,8 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  desc "Compute erd_map"
4
- task erd_map: :environment do
5
- puts "Map computing start."
6
- ErdMap::MapBuilder.build
7
- puts "Map computing completed."
4
+ task erd_map: :environment do
5
+ FileUtils.makedirs(ErdMap::TMP_DIR) unless Dir.exist?(ErdMap::TMP_DIR)
6
+ timeout = 5 * 60
7
+
8
+ if File.exist?(ErdMap::LOCK_FILE)
9
+ pid = File.read(ErdMap::LOCK_FILE).to_i
10
+
11
+ if Time.now - File.mtime(ErdMap::LOCK_FILE) > timeout
12
+ puts "[erd_map] Lock expired. Kill process and remove lock file (pid: #{pid}, file: #{ErdMap::LOCK_FILE})."
13
+ Process.kill("KILL", pid) rescue nil
14
+ File.delete(ErdMap::LOCK_FILE)
15
+ else
16
+ puts "[erd_map] ErdMap is already computing (pid: #{pid}, file: #{ErdMap::LOCK_FILE})."
17
+ exit 0
18
+ end
19
+ end
20
+
21
+ File.open(ErdMap::LOCK_FILE, File::WRONLY|File::CREAT|File::TRUNC, 0644) do |f|
22
+ f.write(Process.pid)
23
+ f.flush
24
+ ErdMap::MapBuilder.build
25
+ end
26
+ File.delete(ErdMap::LOCK_FILE)
8
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erd_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - makicamel
@@ -68,6 +68,7 @@ files:
68
68
  - app/controllers/erd_map/erd_map_controller.rb
69
69
  - app/helpers/erd_map/application_helper.rb
70
70
  - app/models/erd_map/application_record.rb
71
+ - app/views/erd_map/erd_map/index.html.erb
71
72
  - app/views/layouts/erd_map/application.html.erb
72
73
  - config/initializers/erd_map.rb
73
74
  - config/routes.rb