sync_machine 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/lib/sync_machine/ensure_publication_worker.rb +15 -1
- data/lib/sync_machine/find_subjects_worker.rb +13 -10
- data/lib/sync_machine/orm_adapters/active_record_adapter.rb +2 -2
- data/lib/sync_machine/orm_adapters/mongoid_adapter.rb +1 -3
- data/lib/sync_machine/railtie.rb +15 -0
- data/lib/sync_machine/tracer_adapters/open_tracing_adapter.rb +37 -0
- data/lib/sync_machine/tracer_adapters.rb +21 -0
- data/lib/sync_machine/version.rb +1 -1
- data/lib/sync_machine.rb +7 -0
- data/sync_machine.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 102155af0851cece6b27470411c50f11c945be750d08c6acb98093b011f65e85
|
4
|
+
data.tar.gz: 956031cb81b308903a5606d43c877eed613f4c3a3302b655592f1ce891197357
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e0718d0e199a23ca685eccd530cffa3bdd49969925536d2881fea680126aa96a83a8ebae0ea871e93179670928df40b4564962c02d10641bf2b92d6159f571a
|
7
|
+
data.tar.gz: 52ac953901aed56ca103e58e7285fc15bb2acdec89a9ad9f88531b01e91d080aaed78892e9d835b6df6e55b7219c475681fd10708d79b1f94557b4a269ac633a
|
data/.rubocop.yml
CHANGED
@@ -10,7 +10,7 @@ module SyncMachine
|
|
10
10
|
|
11
11
|
[:build, :check_publishable, :publish, :after_publish].each do |hook|
|
12
12
|
define_singleton_method(hook) do |&block|
|
13
|
-
hooks[hook] = block
|
13
|
+
hooks[hook] = Hook.new(hook.to_s, block)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -35,5 +35,19 @@ module SyncMachine
|
|
35
35
|
subject_class = sync_module.subject_class
|
36
36
|
subject_class.find(subject_id)
|
37
37
|
end
|
38
|
+
|
39
|
+
# Wrap build, check_publishable, etc blocks.
|
40
|
+
class Hook
|
41
|
+
def initialize(name, block)
|
42
|
+
@name = name
|
43
|
+
@block = block
|
44
|
+
end
|
45
|
+
|
46
|
+
def call(*args)
|
47
|
+
TracerAdapters.tracer_adapter.start_active_span(@name) do
|
48
|
+
@block.call(*args)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
38
52
|
end
|
39
53
|
end
|
@@ -11,7 +11,7 @@ module SyncMachine
|
|
11
11
|
|
12
12
|
def self.add_hook(meth, block)
|
13
13
|
sync_module = SyncMachine.sync_module(self)
|
14
|
-
hooks[meth] = Hook.new(sync_module, block)
|
14
|
+
hooks[meth] = Hook.new(meth.to_s, sync_module, block)
|
15
15
|
end
|
16
16
|
private_class_method :add_hook
|
17
17
|
|
@@ -52,20 +52,23 @@ module SyncMachine
|
|
52
52
|
|
53
53
|
# Wrap a "subject_ids_from_*" block.
|
54
54
|
class Hook
|
55
|
-
def initialize(sync_module, block)
|
55
|
+
def initialize(name, sync_module, block)
|
56
|
+
@name = name.to_s
|
56
57
|
@sync_module = sync_module
|
57
58
|
@block = block
|
58
59
|
end
|
59
60
|
|
60
61
|
def call(record, changed_keys)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
62
|
+
TracerAdapters.tracer_adapter.start_active_span(@name) do
|
63
|
+
raw_source_ids = if @block.arity == 2
|
64
|
+
@block.call(record, changed_keys)
|
65
|
+
else
|
66
|
+
@block.call(record)
|
67
|
+
end
|
68
|
+
Array.wrap(raw_source_ids).map { |raw_source_id|
|
69
|
+
@sync_module.orm_adapter.record_id_for_job(raw_source_id)
|
70
|
+
}
|
71
|
+
end
|
69
72
|
end
|
70
73
|
end
|
71
74
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
begin
|
2
2
|
require 'wisper/mongoid'
|
3
3
|
rescue LoadError
|
4
|
-
|
5
|
-
"Please install the fhwang-wisper-mongoid gem when using SyncMachine with Mongoid."
|
6
|
-
)
|
4
|
+
SyncMachine.abort_with_installation_hint('fhwang-wisper-mongoid', 'Mongoid')
|
7
5
|
end
|
8
6
|
|
9
7
|
module SyncMachine
|
data/lib/sync_machine/railtie.rb
CHANGED
@@ -6,6 +6,21 @@ module SyncMachine
|
|
6
6
|
require("sync_machine/orm_adapters/active_record_adapter")
|
7
7
|
Module.const_defined?(:Mongoid) && \
|
8
8
|
require("sync_machine/orm_adapters/mongoid_adapter")
|
9
|
+
if Module.const_defined?(:OpenTracing)
|
10
|
+
begin
|
11
|
+
require 'sidekiq-opentracing'
|
12
|
+
rescue LoadError
|
13
|
+
SyncMachine.abort_with_installation_hint(
|
14
|
+
'sfx-sidekiq-opentracing', 'OpenTracing'
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
config.after_initialize do
|
21
|
+
if Module.const_defined?(:OpenTracing)
|
22
|
+
Sidekiq::Tracer.instrument(tracer: OpenTracing.global_tracer)
|
23
|
+
end
|
9
24
|
end
|
10
25
|
end
|
11
26
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module SyncMachine
|
2
|
+
module TracerAdapters
|
3
|
+
# Adapt OpenTracing for use with SyncMachine.
|
4
|
+
module OpenTracingAdapter
|
5
|
+
def self.start_active_span(name, &block)
|
6
|
+
scope = tracer.start_active_span(
|
7
|
+
name,
|
8
|
+
child_of: parent_span.context,
|
9
|
+
tags: tags
|
10
|
+
)
|
11
|
+
block.call
|
12
|
+
rescue Exception => exception
|
13
|
+
log_errors(scope.span, exception) if scope
|
14
|
+
raise exception
|
15
|
+
ensure
|
16
|
+
scope.close if scope
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.log_errors(span, exception)
|
20
|
+
span.set_tag('error', true)
|
21
|
+
span.log_kv(event: 'error', :'error.object' => exception)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.parent_span
|
25
|
+
OpenTracing.active_span
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.tags
|
29
|
+
{ 'component' => 'SyncMachine', 'span.kind' => 'server' }
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.tracer
|
33
|
+
OpenTracing.global_tracer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'sync_machine/tracer_adapters/open_tracing_adapter'
|
2
|
+
|
3
|
+
module SyncMachine
|
4
|
+
# Adapt SyncMachine functionality to a specific distributed tracer.
|
5
|
+
module TracerAdapters
|
6
|
+
def self.tracer_adapter
|
7
|
+
if const_defined?(:OpenTracing)
|
8
|
+
OpenTracingAdapter
|
9
|
+
else
|
10
|
+
NullAdapter
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Do not log spans anywhere.
|
15
|
+
module NullAdapter
|
16
|
+
def self.start_active_span(_name)
|
17
|
+
yield
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/sync_machine/version.rb
CHANGED
data/lib/sync_machine.rb
CHANGED
@@ -5,6 +5,7 @@ require "sync_machine/change_listener"
|
|
5
5
|
require "sync_machine/ensure_publication"
|
6
6
|
require "sync_machine/ensure_publication_worker"
|
7
7
|
require "sync_machine/find_subjects_worker"
|
8
|
+
require "sync_machine/tracer_adapters"
|
8
9
|
require "sync_machine/orm_adapters"
|
9
10
|
require "sync_machine/version"
|
10
11
|
require "sync_machine/railtie" if defined?(Rails::Railtie)
|
@@ -12,6 +13,12 @@ require "sync_machine/railtie" if defined?(Rails::Railtie)
|
|
12
13
|
# A mini-framework for intelligently publishing complex model changes to an
|
13
14
|
# external API..
|
14
15
|
module SyncMachine
|
16
|
+
def self.abort_with_installation_hint(gem_name, dependency)
|
17
|
+
Kernel.abort(
|
18
|
+
"Please install the #{gem_name} gem when using SyncMachine with #{dependency}."
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
15
22
|
# Force loading of all relevant classes. Should only be necessary when
|
16
23
|
# running your application in a way that it defers loading constants, i.e.,
|
17
24
|
# Rails' development or test mode.
|
data/sync_machine.gemspec
CHANGED
@@ -44,6 +44,7 @@ Gem::Specification.new do |spec|
|
|
44
44
|
spec.add_development_dependency "factory_bot"
|
45
45
|
spec.add_development_dependency "fhwang-wisper-mongoid"
|
46
46
|
spec.add_development_dependency "mongoid"
|
47
|
+
spec.add_development_dependency "opentracing"
|
47
48
|
spec.add_development_dependency "rake", "~> 10.0"
|
48
49
|
spec.add_development_dependency "rspec", "~> 3.0"
|
49
50
|
spec.add_development_dependency "rspec_junit_formatter"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sync_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francis Hwang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: opentracing
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rake
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -236,6 +250,8 @@ files:
|
|
236
250
|
- lib/sync_machine/orm_adapters/active_record_adapter.rb
|
237
251
|
- lib/sync_machine/orm_adapters/mongoid_adapter.rb
|
238
252
|
- lib/sync_machine/railtie.rb
|
253
|
+
- lib/sync_machine/tracer_adapters.rb
|
254
|
+
- lib/sync_machine/tracer_adapters/open_tracing_adapter.rb
|
239
255
|
- lib/sync_machine/version.rb
|
240
256
|
- sync_machine.gemspec
|
241
257
|
homepage: https://github.com/fhwang/sync_machine
|