flexite 0.0.23 → 0.0.24

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
  SHA1:
3
- metadata.gz: fafe03dff2fb801bc056c93267c78ce5f256a7ea
4
- data.tar.gz: daaffa1e0587f510ddaed4cc5a32778ab21bce4a
3
+ metadata.gz: e032838d9d874df9e0acc442083e551c8e0d760a
4
+ data.tar.gz: 9ae676c5872e54b2b9e902221a52b117cc78b77f
5
5
  SHA512:
6
- metadata.gz: 434294461fd2e452fd08897cce0c85fead85f19b9db56e595b01be2c720f9d78adc84934729aae6977093fe87027c113509cdbe2db1c599f328ab4f178212fdb
7
- data.tar.gz: 7ddb6b724832435c25e75cdc5996ceff687263d23987b4cd61343edacca4a30adb70d86941d720b3c3da537d3e0477c9af42dc18e71e0f5d08cf8b008d3a2634
6
+ metadata.gz: bc06b67c75a5af494f6878078a4501ea879f2552f710a9b7a9bdd476573d2bcb6a854fa448b5d3ed650bc2df9a75d0d8ee104d92c28286ebcfd54ed95486d763
7
+ data.tar.gz: 628fba6f9199cfd136972b0ca4266308b574898f7b546e2f3064f55afea3a6ad332f6a8e7885d8b8a27bf22c57d3c91efe28cdbb868decfd24534d798e6784a7
@@ -26,7 +26,7 @@ $flexite(window).on('load', function () {
26
26
  });
27
27
 
28
28
  $flexite("#show-diff").on("click", function () {
29
- $flexite.get("<%= diff_path %>" + "?url=" + $flexite("select[id='stage']").val() + "&stage=" + $flexite("select[id='stage']").text());
29
+ $flexite.get("<%= get_diff_path %>" + "?url=" + $flexite("select[id='stage']").val() + "&stage=" + $flexite("select[id='stage']").text());
30
30
  });
31
31
 
32
32
  $flexite("#new-node-btn").on("click", function () {
@@ -0,0 +1,18 @@
1
+ module Flexite
2
+ class ApiController < ApplicationController
3
+ before_filter :check_token
4
+
5
+ def configs
6
+ @nodes = Config.t_nodes
7
+ render json: @nodes
8
+ end
9
+
10
+ private
11
+
12
+ def check_token
13
+ if Diff::Token.new(params[:token]).invalid?
14
+ render json: { status: 'error', code: 401, message: 'unauthorized user' }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -26,19 +26,12 @@ module Flexite
26
26
  end
27
27
 
28
28
  def show
29
- result = ServiceFactory.instance.get("#{Flexite.config.diff_approach}_show_diff".to_sym, params[:stage], params[:url]).call
30
-
31
- if result.succeed?
32
- @data = result.data
33
- @stage = params[:stage]
34
- @url = params[:url]
35
- end
36
-
37
- if result.flash.present?
38
- service_flash(result)
39
- end
29
+ @result = ServiceFactory.instance.get(:show_diff, params[:name]).call
30
+ end
40
31
 
41
- service_response(result)
32
+ def get
33
+ @result = ServiceFactory.instance.get(:get_diff, params[:stage], params[:url]).call
34
+ render :show
42
35
  end
43
36
  end
44
37
  end
@@ -13,12 +13,10 @@ module Flexite
13
13
  arr_entry_destroy: 'Entry::DestroyService',
14
14
  destroy_array_entry: 'Entry::DestroyArrayEntryService',
15
15
  update_config: 'Config::UpdateService',
16
- sync_check_diff: 'Diff::SyncCheckService',
17
- async_check_diff: 'Diff::AsyncCheckService',
18
- sync_show_diff: 'Diff::SyncShowService',
19
- async_show_diff: 'Diff::AsyncShowService',
20
16
  apply_diff: 'Diff::ApplyService',
21
- push_diff: 'Diff::PushService'
17
+ push_diff: 'Diff::PushService',
18
+ get_diff: 'Diff::GetService',
19
+ show_diff: 'Diff::ShowService'
22
20
  }
23
21
  end
24
22
  end
@@ -0,0 +1,21 @@
1
+ ShowDiffJob = Struct.new(:other_tree, :file_name ) do
2
+ def before
3
+ Flexite::JobReport.create(file_name: file_name, status: Flexite::JobReport::STATUS[:in_progress])
4
+ end
5
+
6
+ def perform
7
+ Flexite::Diff::CheckService.new(other_tree, file_name).call
8
+ end
9
+
10
+ def success
11
+ Flexite::JobReport
12
+ .find_by_file_name(file_name)
13
+ .update_attributes(status: Flexite::JobReport::STATUS[:done])
14
+ end
15
+
16
+ def error
17
+ Flexite::JobReport
18
+ .find_by_file_name(file_name)
19
+ .update_attributes(status: Flexite::JobReport::STATUS[:error])
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module Flexite
2
+ class JobReport < ActiveRecord::Base
3
+ attr_accessible :file_name, :status
4
+
5
+ STATUS = { in_progress: 1,
6
+ done: 2,
7
+ error: 3 }.freeze
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ module Flexite
2
+ class Diff
3
+ class CheckService
4
+ def initialize(other_tree, file_name)
5
+ @other_tree = other_tree
6
+ @current_tree = Config.t_nodes
7
+ @file_name = file_name
8
+ end
9
+
10
+ def call
11
+ check
12
+ save
13
+ end
14
+
15
+ protected
16
+
17
+ def check
18
+ diffs = HashDiff.diff(@current_tree, @other_tree, array_path: true)
19
+
20
+ if diffs.blank?
21
+ return {}
22
+ end
23
+
24
+ @view_diffs = { '+': [], '-': [], '~': [] }
25
+
26
+ diffs.each do |type, depth, *changes|
27
+ @view_diffs[type.to_sym] << [depth, *changes]
28
+ end
29
+ end
30
+
31
+ def save
32
+ File.open("config/diffs/#{@file_name}", "w") do |file|
33
+ file.write @view_diffs.to_yaml
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ module Flexite
2
+ class Diff
3
+ class GetService
4
+ include Flexite::Engine.routes.url_helpers
5
+
6
+ def initialize(stage, endpoint)
7
+ @stage = stage
8
+ @token = Flexite.config.migration_token
9
+ @endpoint = endpoint + api_configs_path(token: @token)
10
+ @timestamps = Time.now.strftime("%Y%m%d%H%M%S")
11
+ @file_name = "#{@timestamps}_#{@stage}.yml"
12
+ @result = ActionService::Result.new
13
+ end
14
+
15
+ def call
16
+ get_configs
17
+ calculate_diff
18
+
19
+ Flexite::ActionService::Result.new(data: { file_name: @file_name })
20
+ end
21
+
22
+ private
23
+
24
+ def get_configs
25
+ uri = URI(@endpoint)
26
+ response = Net::HTTP.get(uri)
27
+ @other_tree = JSON.parse(response)
28
+ end
29
+
30
+ def calculate_diff
31
+ Delayed::Job.enqueue(ShowDiffJob.new(@other_tree, @file_name))
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ module Flexite
2
+ class Diff
3
+ class ShowService
4
+ def initialize(file_name)
5
+ @file_name = file_name
6
+ end
7
+
8
+ def call
9
+ @data = { file_name: @file_name}
10
+ if File.exists?("#{Rails.root}/config/diffs/#{@file_name}")
11
+ @data = { diffs: YAML.load_file("#{Rails.root}/config/diffs/#{@file_name}") }
12
+ end
13
+
14
+ Flexite::ActionService::Result.new(data: @data)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -15,3 +15,4 @@
15
15
  #section-2.pos-fixed
16
16
  .col-md-4
17
17
  #section-3.pos-fixed
18
+ #diff-timer
@@ -1,5 +1,5 @@
1
1
  .diffs
2
- - @data.each do |type, diffs|
2
+ - data&.each do |type, diffs|
3
3
  %button.btn.btn-default{ type: :button,
4
4
  data: { toggle: :collapse, target: "##{t("css.#{type}-diff")}" },
5
5
  aria: { expanded: 'false', controls: t("css.#{type}-diff") },
@@ -0,0 +1,7 @@
1
+ :javascript
2
+ setTimeout(function() {
3
+ $flexite.ajax({
4
+ url: "#{diff_path}",
5
+ data: { name: "#{@result.data[:file_name]}" }
6
+ })
7
+ }, 2000);
@@ -0,0 +1,9 @@
1
+ - data = @result.data.try(:[], :diffs)
2
+ -if data.blank?
3
+ $flexite('#diff-timer').html("#{j render 'timer'}");
4
+ -else
5
+ $flexite("#modal-body").html("#{j render 'diff', data: data}");
6
+ // $flexite("#submit-btn").html("#{j link_to 'Push', push_diff_path(stage: @stage, url: @url), remote: true, class: 'btn btn-success' }");
7
+ $flexite("#modal").modal("show");
8
+
9
+
data/config/routes.rb CHANGED
@@ -22,8 +22,13 @@ Flexite::Engine.routes.draw do
22
22
  post :check
23
23
  post :apply
24
24
  post :save_diff
25
+ get :get
25
26
  get :push
26
27
  end
27
28
 
29
+ namespace :api, defaults: { format: :json } do
30
+ get :configs
31
+ end
32
+
28
33
  root to: 'application#index'
29
34
  end
@@ -0,0 +1,9 @@
1
+ class CreateFlexiteJobReports < ActiveRecord::Migration
2
+ def change
3
+ create_table :flexite_job_reports do |t|
4
+ t.string :file_name
5
+ t.integer :status
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Flexite
2
- VERSION = '0.0.23'
2
+ VERSION = '0.0.24'
3
3
  end
@@ -0,0 +1,5 @@
1
+ require 'delayed_job_active_record'
2
+
3
+ Delayed::Worker.delay_jobs = true
4
+ Delayed::Worker.destroy_failed_jobs = false
5
+ Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))
@@ -11,7 +11,23 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20180629110934) do
14
+ ActiveRecord::Schema.define(:version => 20180829112429) do
15
+
16
+ create_table "delayed_jobs", :force => true do |t|
17
+ t.integer "priority", :default => 0, :null => false
18
+ t.integer "attempts", :default => 0, :null => false
19
+ t.text "handler", :null => false
20
+ t.text "last_error"
21
+ t.datetime "run_at"
22
+ t.datetime "locked_at"
23
+ t.datetime "failed_at"
24
+ t.string "locked_by"
25
+ t.string "queue"
26
+ t.datetime "created_at"
27
+ t.datetime "updated_at"
28
+ end
29
+
30
+ add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
15
31
 
16
32
  create_table "flexite_configs", :force => true do |t|
17
33
  t.string "name"
@@ -56,4 +72,11 @@ ActiveRecord::Schema.define(:version => 20180629110934) do
56
72
 
57
73
  add_index "flexite_history_attributes", ["history_id"], :name => "index_flexite_history_attributes_on_history_id"
58
74
 
75
+ create_table "flexite_job_reports", :force => true do |t|
76
+ t.string "file_name"
77
+ t.integer "status"
78
+ t.datetime "created_at", :null => false
79
+ t.datetime "updated_at", :null => false
80
+ end
81
+
59
82
  end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
4
+ require 'delayed/command'
5
+ Delayed::Command.new(ARGV).daemonize
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maksim Rusakovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-21 00:00:00.000000000 Z
11
+ date: 2018-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: delayed_job_active_record
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: daemons
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.0
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: rails
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -176,6 +204,7 @@ files:
176
204
  - app/assets/stylesheets/flexite/entries.css
177
205
  - app/assets/stylesheets/flexite/tree.css
178
206
  - app/assets/stylesheets/scaffold.css
207
+ - app/controllers/flexite/api_controller.rb
179
208
  - app/controllers/flexite/application_controller.rb
180
209
  - app/controllers/flexite/configs_controller.rb
181
210
  - app/controllers/flexite/diffs_controller.rb
@@ -190,6 +219,7 @@ files:
190
219
  - app/helpers/flexite/application_helper.rb
191
220
  - app/helpers/flexite/configs_helper.rb
192
221
  - app/helpers/flexite/entries_helper.rb
222
+ - app/jobs/show_diff_job.rb
193
223
  - app/models/concerns/flexite/with_history.rb
194
224
  - app/models/flexite/arr_entry.rb
195
225
  - app/models/flexite/bool_entry.rb
@@ -199,6 +229,7 @@ files:
199
229
  - app/models/flexite/history.rb
200
230
  - app/models/flexite/history_attribute.rb
201
231
  - app/models/flexite/int_entry.rb
232
+ - app/models/flexite/job_report.rb
202
233
  - app/models/flexite/str_entry.rb
203
234
  - app/models/flexite/sym_entry.rb
204
235
  - app/presenters/flexite/diff_presenter.rb
@@ -210,12 +241,11 @@ files:
210
241
  - app/services/flexite/data/migrators/yaml.rb
211
242
  - app/services/flexite/data/new_service.rb
212
243
  - app/services/flexite/diff/apply_service.rb
213
- - app/services/flexite/diff/async_check_service.rb
214
- - app/services/flexite/diff/async_show_service.rb
244
+ - app/services/flexite/diff/check_service.rb
245
+ - app/services/flexite/diff/get_service.rb
215
246
  - app/services/flexite/diff/push_service.rb
216
247
  - app/services/flexite/diff/save_diff_service.rb
217
- - app/services/flexite/diff/sync_check_service.rb
218
- - app/services/flexite/diff/sync_show_service.rb
248
+ - app/services/flexite/diff/show_service.rb
219
249
  - app/services/flexite/diff/token.rb
220
250
  - app/services/flexite/entry/array_create_service.rb
221
251
  - app/services/flexite/entry/array_update_service.rb
@@ -233,7 +263,9 @@ files:
233
263
  - app/views/flexite/configs/new.js.haml
234
264
  - app/views/flexite/configs/update.js.haml
235
265
  - app/views/flexite/diffs/_diff.html.haml
266
+ - app/views/flexite/diffs/_timer.js.haml
236
267
  - app/views/flexite/diffs/push.js.haml
268
+ - app/views/flexite/diffs/show.js.haml
237
269
  - app/views/flexite/diffs/sync_show.js.haml
238
270
  - app/views/flexite/entries/_form.html.haml
239
271
  - app/views/flexite/entries/_new_array_entry_form.html.haml
@@ -272,6 +304,7 @@ files:
272
304
  - db/migrate/20180618115057_create_flexite_history_attributes.rb
273
305
  - db/migrate/20180621134948_add_description_column_to_flexite_configs.rb
274
306
  - db/migrate/20180629110934_remove_created_by_column_from_flexite_configs.rb
307
+ - db/migrate/20180829112429_create_flexite_job_reports.rb
275
308
  - lib/flexite.rb
276
309
  - lib/flexite/cached_node.rb
277
310
  - lib/flexite/configuration.rb
@@ -296,6 +329,7 @@ files:
296
329
  - test/dummy/config/environments/production.rb
297
330
  - test/dummy/config/environments/test.rb
298
331
  - test/dummy/config/initializers/backtrace_silencers.rb
332
+ - test/dummy/config/initializers/delayed_job.rb
299
333
  - test/dummy/config/initializers/flexite.rb
300
334
  - test/dummy/config/initializers/inflections.rb
301
335
  - test/dummy/config/initializers/mime_types.rb
@@ -314,6 +348,7 @@ files:
314
348
  - test/dummy/public/422.html
315
349
  - test/dummy/public/500.html
316
350
  - test/dummy/public/favicon.ico
351
+ - test/dummy/script/delayed_job
317
352
  - test/dummy/script/rails
318
353
  - test/dummy/tmp/cache/assets/C67/060/sprockets%2Ffaf176441f0544dd2b51901280044b40
319
354
  - test/dummy/tmp/cache/assets/C9D/530/sprockets%2Fdcd49c063327c12052812f41c20a8e74
@@ -375,7 +410,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
375
410
  version: '0'
376
411
  requirements: []
377
412
  rubyforge_project:
378
- rubygems_version: 2.6.11
413
+ rubygems_version: 2.6.14
379
414
  signing_key:
380
415
  specification_version: 4
381
416
  summary: Database driven web-app settings
@@ -438,11 +473,13 @@ test_files:
438
473
  - test/dummy/config/initializers/wrap_parameters.rb
439
474
  - test/dummy/config/initializers/backtrace_silencers.rb
440
475
  - test/dummy/config/initializers/secret_token.rb
476
+ - test/dummy/config/initializers/delayed_job.rb
441
477
  - 'test/dummy/elect("#{Config.table_name}.*, #{Entry.table_name}.id AS entry_id")'
442
478
  - test/dummy/app/controllers/application_controller.rb
443
479
  - test/dummy/app/helpers/application_helper.rb
444
480
  - test/dummy/app/assets/stylesheets/application.css
445
481
  - test/dummy/app/assets/javascripts/application.js
482
+ - test/dummy/script/delayed_job
446
483
  - test/dummy/script/rails
447
484
  - test/dummy/Rakefile
448
485
  - test/test_helper.rb
@@ -1,18 +0,0 @@
1
- module Flexite
2
- class Diff
3
- class AsyncCheckService
4
- def initialize(*args)
5
- @args = args
6
- @handler = Flexite.config.async_diff_handler
7
- end
8
-
9
- def call
10
- unless @handler.is_a?(Proc)
11
- raise 'Async handler should be a proc object'
12
- end
13
-
14
- @handler.call(*@args)
15
- end
16
- end
17
- end
18
- end
@@ -1,21 +0,0 @@
1
- module Flexite
2
- class Diff
3
- class AsyncShowService < SyncShowService
4
- def call
5
- response = Flexite.cache.read("#{Flexite.state_digest}-#{@stage}-show-diff")
6
-
7
- if response.present?
8
- return result(response)
9
- end
10
-
11
- expire_old
12
- nodes = Config.t_nodes
13
- checksum = Digest::MD5.hexdigest(nodes.to_json)
14
- Flexite.cache.write("#{Flexite.state_digest}-#{@stage}-diff-checksum", checksum)
15
- @remote_diff.check({ token: Flexite.config.migration_token, tree: nodes, stage: Flexite.config.stagename, checksum: checksum })
16
- ActionService::Result.new(flash: { type: :warning, message: "You will be notified via #{Flexite.config.async_diff_handler&.notifier} when difference check will be completed" },
17
- endpoint: { partial: 'flexite/shared/show_flash' })
18
- end
19
- end
20
- end
21
- end
@@ -1,42 +0,0 @@
1
- module Flexite
2
- class Diff
3
- class SyncCheckService
4
- def initialize(other_tree, token, stage, checksum)
5
- @other_tree = other_tree
6
- @current_tree = Config.t_nodes
7
- @token = Token.new(token)
8
- @stage = stage
9
- @checksum = checksum
10
- end
11
-
12
- def call
13
- check
14
- end
15
-
16
- protected
17
-
18
- def check
19
- if @token.invalid?
20
- return { error: 'Invalid token', code: 401 }
21
- end
22
-
23
- diffs = HashDiff.diff(@current_tree, @other_tree, array_path: true)
24
-
25
- if diffs.blank?
26
- return {}
27
- end
28
-
29
- view_diffs = { '+': [], '-': [], '~': [] }
30
-
31
- diffs.each do |type, depth, *changes|
32
- view_diffs[type.to_sym] << [depth, *changes]
33
- end
34
-
35
- Flexite.cache.write("#{Flexite.state_digest}-#{@checksum}-#{@stage}-diffs", diffs)
36
- { diffs: view_diffs }
37
- rescue => exc
38
- { error: exc.message, code: 500 }
39
- end
40
- end
41
- end
42
- end
@@ -1,42 +0,0 @@
1
- module Flexite
2
- class Diff
3
- class SyncShowService
4
- def initialize(stage, url)
5
- @stage = stage
6
- @remote_diff = Diff.new(url)
7
- @state_digest = Flexite.state_digest
8
- end
9
-
10
- def call
11
- response = Flexite.cache.read("#{@state_digest}-#{@stage}-show-diff")
12
-
13
- if response.nil?
14
- expire_old
15
- nodes = Config.t_nodes
16
- checksum = Digest::MD5.hexdigest(nodes.to_json)
17
- Flexite.cache.write("#{@state_digest}-#{@stage}-diff-checksum", checksum)
18
- response = @remote_diff.check({ token: Flexite.config.migration_token, tree: nodes, stage: Flexite.config.stagename, checksum: checksum })
19
- Flexite.cache.write("#{@state_digest}-#{@stage}-show-diff", response)
20
- end
21
-
22
- result(response)
23
- end
24
-
25
- protected
26
-
27
- def expire_old
28
- Flexite.cache.delete_matched(Flexite.match_key("-#{@stage}-show-diff"))
29
- Flexite.cache.delete_matched(Flexite.match_key("-#{@stage}-diff-checksum"))
30
- end
31
-
32
- def result(response)
33
- if response[:error].present?
34
- expire_old
35
- ActionService::Result.new(success: false, flash: { type: :danger, message: response[:error] }, endpoint: { partial: 'flexite/shared/show_flash' })
36
- else
37
- ActionService::Result.new(data: response[:diffs], endpoint: { action: :sync_show })
38
- end
39
- end
40
- end
41
- end
42
- end