syncable_models 0.0.9 → 0.0.10
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 +8 -8
- data/bin/import_syncable_models +42 -0
- data/lib/generators/syncable_models/templates/initializer.rb +4 -4
- data/lib/syncable_models/importer.rb +22 -10
- data/lib/syncable_models/version.rb +1 -1
- data/lib/tasks/syncable_models.rake +18 -0
- data/test/dummy/log/test.log +9 -9
- metadata +19 -5
- data/bin/import +0 -36
- data/lib/tasks/syncable_models_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjM5MDVhOWMwZGRkMGIyMmI3NTI1NTNlZjk2ZTVmZWE5NzJmY2NkMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGI3NTFhOWI4OWNjZDYzZmE1YmYyZGNlNDNlYjcyMjgyMDllZWRlZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWU5M2Q2NDA5MmE2NGUxNjI4ODQ5YjNjZjAxMjRkMjQ1NjYyMjhiYmU5MDlh
|
10
|
+
NTFhMTIyZmMxNTZjYWIxNGY2YmY3OTBiMTcyZjczMWMxZTRhZjU4NzBiOGI4
|
11
|
+
NDZjMjU2YWZjMzg2OWJlMzBkMjAyODVjNTRhOTdmNmQ1NTc4Y2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWI5MjQzYjM4MDU4MTY0MzkyMGI3YTY5NTg1ZTY0YjYwOGFlMWRmOTEwN2Y1
|
14
|
+
NzE2YTNmM2Q2Y2M5MjY1YzMzNDMyNTQ1NzM2N2JkOTZlNTVkNGFhZTA2ZmE3
|
15
|
+
ZmZhMjZkYWI0MWQyNmRhM2UyM2JhZWQxOGUzNTNlNDViNTdlZjE=
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require ENV['APP_PATH'] || File.join(File.expand_path('.'), 'config', 'application')
|
4
|
+
Rails.application.initialize!
|
5
|
+
|
6
|
+
## Importer
|
7
|
+
puts 'Starting Importer... '
|
8
|
+
|
9
|
+
importers = []
|
10
|
+
|
11
|
+
SyncableModels::Importer.imports.each do |i|
|
12
|
+
puts "Registering importer #{ i.name } (interval=#{ i.interval }s, timeout=#{ i.timeout }s)..."
|
13
|
+
importers << Concurrent::TimerTask.new(execution_interval: i.interval,
|
14
|
+
timeout_interval: i.timeout,
|
15
|
+
run_now: true) do
|
16
|
+
begin
|
17
|
+
i.import
|
18
|
+
rescue => exc
|
19
|
+
Rails.logger.error "[Importer] Error: #{exc.message}\n" \
|
20
|
+
" backtrace:\n #{exc.backtrace.join("\n ")}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
importers.each &:execute
|
26
|
+
puts "done."
|
27
|
+
|
28
|
+
# Signal catching
|
29
|
+
def shut_down
|
30
|
+
puts "\nShutting down gracefully..."
|
31
|
+
sleep 1
|
32
|
+
end
|
33
|
+
|
34
|
+
["TERM", "INT"].each do |sig|
|
35
|
+
trap(sig) do
|
36
|
+
shut_down
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
loop { sleep }
|
@@ -1,13 +1,13 @@
|
|
1
1
|
SyncableModels::Importer.config do |conf|
|
2
2
|
## Define one or several imports here
|
3
|
-
# conf.add_import do |import|
|
3
|
+
# conf.add_import :my_awesome_import do |import|
|
4
4
|
# import.api_url = 'http://www.example.com/import_api/'
|
5
5
|
# import.destination = :my_awesome_project
|
6
6
|
|
7
7
|
# import.import_model 'Project', id_key: :uuid
|
8
8
|
# import.import_model 'Team', fetch_path: 'some_teams', sync_path: 'sync_some_teams'
|
9
|
-
# end
|
10
9
|
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# conf.interval = 5.minutes
|
11
|
+
# conf.timeout = 10.seconds
|
12
|
+
# end
|
13
13
|
end
|
@@ -3,11 +3,14 @@ require 'faraday'
|
|
3
3
|
module SyncableModels
|
4
4
|
module Importer
|
5
5
|
class Import
|
6
|
-
attr_accessor :api_url, :api_key, :destination
|
6
|
+
attr_accessor :name, :api_url, :api_key, :destination, :interval, :timeout
|
7
7
|
attr_reader :models
|
8
8
|
|
9
|
-
def initialize
|
9
|
+
def initialize(name)
|
10
|
+
@name = name.to_s
|
10
11
|
@models = {}
|
12
|
+
@interval = 5.minutes
|
13
|
+
@timeout = 10.seconds
|
11
14
|
end
|
12
15
|
|
13
16
|
def import_model(class_name, args = {})
|
@@ -31,8 +34,15 @@ module SyncableModels
|
|
31
34
|
params
|
32
35
|
end
|
33
36
|
|
34
|
-
def import
|
35
|
-
|
37
|
+
def import(model_names=[])
|
38
|
+
selected_models = model_names.any? ?
|
39
|
+
@models.select{ |k, v| k.in? model_names } :
|
40
|
+
@models
|
41
|
+
|
42
|
+
selected_models.each do |model_name, params|
|
43
|
+
puts "[SyncableModels::Importer] Importing #{model_name.underscore.pluralize}..."
|
44
|
+
next if model_names.any? && !model_name.in?(model_names)
|
45
|
+
|
36
46
|
fetch_url = self.api_url + params[:fetch_path]
|
37
47
|
sync_url = self.api_url + params[:sync_path]
|
38
48
|
|
@@ -66,22 +76,24 @@ module SyncableModels
|
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
|
-
mattr_accessor :imports
|
79
|
+
mattr_accessor :imports
|
70
80
|
@@imports = []
|
71
|
-
@@interval = 5.minutes
|
72
|
-
@@timeout = 10.seconds
|
73
81
|
|
74
82
|
def self.config
|
75
83
|
yield self
|
76
84
|
end
|
77
85
|
|
78
|
-
def self.add_import
|
79
|
-
import = Import.new
|
86
|
+
def self.add_import(name)
|
87
|
+
import = Import.new name
|
80
88
|
yield import
|
81
89
|
@@imports << import
|
82
90
|
end
|
83
91
|
|
84
|
-
def self.
|
92
|
+
def self.find_import(name)
|
93
|
+
@@imports.detect{ |i| i.name == name.to_s }
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.import_all
|
85
97
|
@@imports.each &:import
|
86
98
|
end
|
87
99
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# desc "Explaining what the task does"
|
2
|
+
|
3
|
+
def prepare_models(models)
|
4
|
+
return unless models
|
5
|
+
models.split(',').map(&:camelize)
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :syncable_models do
|
9
|
+
task import: :environment do
|
10
|
+
models = prepare_models(ENV['MODELS']) || []
|
11
|
+
|
12
|
+
if import = SyncableModels::Importer.find_import(ENV['NAME'])
|
13
|
+
import.import models
|
14
|
+
else
|
15
|
+
puts "Import #{ENV['NAME']} was not found..."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/dummy/log/test.log
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
[1m[36m (
|
2
|
-
[1m[35m (0.
|
3
|
-
[1m[36m (
|
4
|
-
[1m[35m (0.
|
1
|
+
[1m[36m (38.8ms)[0m [1mCREATE TABLE "syncs" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "subject_id" integer, "subject_type" varchar, "destination" varchar, "created_at" datetime, "updated_at" datetime) [0m
|
2
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
3
|
+
[1m[36m (2.6ms)[0m [1mCREATE INDEX "index_syncs_on_destination" ON "syncs" ("destination")[0m
|
4
|
+
[1m[35m (0.1ms)[0m SELECT sql
|
5
5
|
FROM sqlite_master
|
6
6
|
WHERE name='index_syncs_on_destination' AND type='index'
|
7
7
|
UNION ALL
|
@@ -9,12 +9,12 @@
|
|
9
9
|
FROM sqlite_temp_master
|
10
10
|
WHERE name='index_syncs_on_destination' AND type='index'
|
11
11
|
|
12
|
-
[1m[36m (
|
13
|
-
[1m[35m (
|
14
|
-
[1m[36m (
|
12
|
+
[1m[36m (2.5ms)[0m [1mCREATE INDEX "index_syncs_on_subject_id_and_subject_type_and_destination" ON "syncs" ("subject_id", "subject_type", "destination")[0m
|
13
|
+
[1m[35m (6.8ms)[0m CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
|
14
|
+
[1m[36m (4.5ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
15
15
|
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
16
|
-
[1m[36m (
|
17
|
-
[1m[36mActiveRecord::SchemaMigration Load (0.
|
16
|
+
[1m[36m (7.2ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20160225141153')[0m
|
17
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
18
18
|
[1m[35m (0.2ms)[0m begin transaction
|
19
19
|
------------------------------
|
20
20
|
SyncableModelsTest: test_truth
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syncable_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serafim Nenarokov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -66,11 +66,25 @@ dependencies:
|
|
66
66
|
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.9.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: concurrent-ruby-edge
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.2.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.2.1
|
69
83
|
description: The gem provides tagged syncing functionality and API methods.
|
70
84
|
email:
|
71
85
|
- serafim.nenarokov@flant.ru
|
72
86
|
executables:
|
73
|
-
-
|
87
|
+
- import_syncable_models
|
74
88
|
extensions: []
|
75
89
|
extra_rdoc_files: []
|
76
90
|
files:
|
@@ -78,7 +92,7 @@ files:
|
|
78
92
|
- README.md
|
79
93
|
- Rakefile
|
80
94
|
- app/models/syncable_models/sync.rb
|
81
|
-
- bin/
|
95
|
+
- bin/import_syncable_models
|
82
96
|
- config/routes.rb
|
83
97
|
- db/migrate/20160225141153_create_syncs.rb
|
84
98
|
- lib/generators/syncable_models/import_config_generator.rb
|
@@ -89,7 +103,7 @@ files:
|
|
89
103
|
- lib/syncable_models/engine.rb
|
90
104
|
- lib/syncable_models/importer.rb
|
91
105
|
- lib/syncable_models/version.rb
|
92
|
-
- lib/tasks/
|
106
|
+
- lib/tasks/syncable_models.rake
|
93
107
|
- test/dummy/README.rdoc
|
94
108
|
- test/dummy/Rakefile
|
95
109
|
- test/dummy/app/assets/javascripts/application.js
|
data/bin/import
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join((ENV['APP_PATH'] || File.expand_path('.')), 'config', 'environment')
|
4
|
-
|
5
|
-
## Importer
|
6
|
-
print 'Starting Importer... '
|
7
|
-
|
8
|
-
interval = SyncableModels::Importer.interval
|
9
|
-
timeout = SyncableModels::Importer.timeout
|
10
|
-
|
11
|
-
importer = Concurrent::TimerTask.new(execution_interval: interval, timeout_interval: timeout, run_now: true) do
|
12
|
-
begin
|
13
|
-
SyncableModels::Importer.import
|
14
|
-
rescue => exc
|
15
|
-
Rails.logger.error "[Importer] Error: #{exc.message}\n" \
|
16
|
-
" backtrace:\n #{exc.backtrace.join("\n ")}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
importer.execute
|
20
|
-
print "done.\n"
|
21
|
-
|
22
|
-
# Signal catching
|
23
|
-
def shut_down
|
24
|
-
puts "\nShutting down gracefully..."
|
25
|
-
sleep 1
|
26
|
-
end
|
27
|
-
|
28
|
-
["TERM", "INT"].each do |sig|
|
29
|
-
trap(sig) do
|
30
|
-
shut_down
|
31
|
-
exit
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
loop { sleep }
|