artery 1.4.1 → 1.4.2
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 +4 -4
- data/lib/artery/publisher.rb +40 -20
- data/lib/artery/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66026b7e5dd81edcbb4fc03956531d781f06387846c23cc6a88c7047da24000d
|
|
4
|
+
data.tar.gz: 8177b56b29b22a7c09324c4d5a8915b9c697a73aba69f937d4870f1664a0dcb2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e33b8a5fafbf2f56651a85b43636ad62ad68a4e34c219979a171cdf2dcdef1b68372ff17f4f07be256ea1524f5a5b3d999cd8685687ecfdc4eb4afbf7143f40d
|
|
7
|
+
data.tar.gz: 39b1c29831cef207fabf34c0c52d8889c4695c0a99ea81f13565538c65a733f4d3aa19cdf5625e4d67a5ef549c02ce3999b19893b696afb5bd5d6493bc4b0ffa
|
data/lib/artery/publisher.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'concurrent'
|
|
|
4
4
|
|
|
5
5
|
module Artery
|
|
6
6
|
class Publisher
|
|
7
|
-
DISCOVERY_INTERVAL =
|
|
7
|
+
DISCOVERY_INTERVAL = 30
|
|
8
8
|
POLL_INTERVAL = 0.5
|
|
9
9
|
BATCH_SIZE = 100
|
|
10
10
|
|
|
@@ -27,44 +27,64 @@ module Artery
|
|
|
27
27
|
max_queue: 0,
|
|
28
28
|
fallback_policy: :caller_runs
|
|
29
29
|
)
|
|
30
|
-
@
|
|
30
|
+
@known_models = Concurrent::Set.new
|
|
31
|
+
@busy_models = Concurrent::Set.new
|
|
32
|
+
@last_discovery = Time.at(0)
|
|
31
33
|
|
|
32
34
|
Instrumentation.instrument(:publisher, action: :started)
|
|
33
35
|
|
|
34
36
|
loop do
|
|
35
|
-
|
|
37
|
+
discover_models if discovery_due?
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
next if @
|
|
39
|
+
@known_models.each do |model|
|
|
40
|
+
next if @busy_models.include?(model)
|
|
39
41
|
|
|
40
|
-
@
|
|
41
|
-
@pool.post {
|
|
42
|
+
@busy_models.add(model)
|
|
43
|
+
@pool.post { process_model(model) }
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
sleep
|
|
46
|
+
sleep POLL_INTERVAL
|
|
45
47
|
end
|
|
46
48
|
end
|
|
47
49
|
|
|
48
|
-
def
|
|
49
|
-
Artery.
|
|
50
|
+
def discover_models
|
|
51
|
+
current = Artery.model_info_class.pluck(:model)
|
|
52
|
+
|
|
53
|
+
(@known_models - current).each do |removed|
|
|
54
|
+
@known_models.delete(removed)
|
|
55
|
+
Instrumentation.instrument(:publisher, action: :model_removed, model: removed)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
current.each do |model|
|
|
59
|
+
next if @known_models.include?(model)
|
|
60
|
+
|
|
61
|
+
@known_models.add(model)
|
|
50
62
|
Artery.model_info_class.ensure_initialized!(model)
|
|
51
63
|
Instrumentation.instrument(:publisher, action: :model_started, model: model)
|
|
64
|
+
end
|
|
52
65
|
|
|
66
|
+
@last_discovery = Time.now
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def discovery_due?
|
|
70
|
+
Time.now - @last_discovery >= DISCOVERY_INTERVAL
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def process_model(model)
|
|
74
|
+
Artery.logger.tagged('Publisher', model) do
|
|
53
75
|
loop do
|
|
54
76
|
published = publish_batch(model)
|
|
55
|
-
|
|
77
|
+
break if published < BATCH_SIZE
|
|
56
78
|
end
|
|
57
|
-
rescue StandardError => e
|
|
58
|
-
Instrumentation.instrument(:publisher, action: :error, model: model, error: e.message)
|
|
59
|
-
Artery.handle_error Error.new(
|
|
60
|
-
"Publisher error for #{model}: #{e.message}",
|
|
61
|
-
original_exception: e
|
|
62
|
-
)
|
|
63
|
-
sleep POLL_INTERVAL
|
|
64
|
-
retry
|
|
65
79
|
end
|
|
80
|
+
rescue StandardError => e
|
|
81
|
+
Instrumentation.instrument(:publisher, action: :error, model: model, error: e.message)
|
|
82
|
+
Artery.handle_error Error.new(
|
|
83
|
+
"Publisher error for #{model}: #{e.message}",
|
|
84
|
+
original_exception: e
|
|
85
|
+
)
|
|
66
86
|
ensure
|
|
67
|
-
@
|
|
87
|
+
@busy_models&.delete(model)
|
|
68
88
|
end
|
|
69
89
|
|
|
70
90
|
def publish_batch(model)
|
data/lib/artery/version.rb
CHANGED