cadence-ruby 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cadence/version.rb +1 -1
- data/lib/cadence/workflow/poller.rb +22 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe9d521039531a8f5cfe02230061bb23ac7e303cd8fd76367ee727870421295c
|
4
|
+
data.tar.gz: 642a711172bf0360fcff1b8d8422cfeadff6b2f081e77f7f57b46dbda65ac890
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2da308b055fffc8b31b824df1c083be95fe12ef7b18ac9a5158c17fcbafbe3ef462b44acae8d0801e5ada84ca888fce56166d8843b067bb80b394af86175445
|
7
|
+
data.tar.gz: afaf342c71088477fc0f41fa840028b392fd239bf0e1bbbb7faad0c601c75d015efa92c8299316dab9cd2dbef54d690ff67f8c49dd23d4df3c59cb15a4bca610
|
data/lib/cadence/version.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
require 'cadence/client'
|
2
|
+
require 'cadence/thread_pool'
|
2
3
|
require 'cadence/middleware/chain'
|
3
4
|
require 'cadence/workflow/decision_task_processor'
|
4
5
|
|
5
6
|
module Cadence
|
6
7
|
class Workflow
|
7
8
|
class Poller
|
9
|
+
DEFAULT_OPTIONS = {
|
10
|
+
thread_pool_size: 1
|
11
|
+
}.freeze
|
12
|
+
|
8
13
|
def initialize(domain, task_list, workflow_lookup, middleware = [], options = {})
|
9
14
|
@domain = domain
|
10
15
|
@task_list = task_list
|
11
16
|
@workflow_lookup = workflow_lookup
|
12
17
|
@middleware = middleware
|
13
|
-
@options = options
|
18
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
14
19
|
@shutting_down = false
|
15
20
|
end
|
16
21
|
|
@@ -26,6 +31,7 @@ module Cadence
|
|
26
31
|
|
27
32
|
def wait
|
28
33
|
@thread.join
|
34
|
+
thread_pool.shutdown
|
29
35
|
end
|
30
36
|
|
31
37
|
private
|
@@ -36,10 +42,6 @@ module Cadence
|
|
36
42
|
@client ||= Cadence::Client.generate(options)
|
37
43
|
end
|
38
44
|
|
39
|
-
def middleware_chain
|
40
|
-
@middleware_chain ||= Middleware::Chain.new(middleware)
|
41
|
-
end
|
42
|
-
|
43
45
|
def shutting_down?
|
44
46
|
@shutting_down
|
45
47
|
end
|
@@ -48,14 +50,20 @@ module Cadence
|
|
48
50
|
last_poll_time = Time.now
|
49
51
|
metrics_tags = { domain: domain, task_list: task_list }.freeze
|
50
52
|
|
51
|
-
|
53
|
+
loop do
|
54
|
+
thread_pool.wait_for_available_threads
|
55
|
+
|
56
|
+
return if shutting_down?
|
57
|
+
|
52
58
|
time_diff_ms = ((Time.now - last_poll_time) * 1000).round
|
53
59
|
Cadence.metrics.timing('workflow_poller.time_since_last_poll', time_diff_ms, metrics_tags)
|
54
60
|
Cadence.logger.debug("Polling for decision tasks (#{domain} / #{task_list})")
|
55
61
|
|
56
62
|
task = poll_for_task
|
57
63
|
last_poll_time = Time.now
|
58
|
-
|
64
|
+
next unless task&.workflowType
|
65
|
+
|
66
|
+
thread_pool.schedule { process(task) }
|
59
67
|
end
|
60
68
|
end
|
61
69
|
|
@@ -67,8 +75,15 @@ module Cadence
|
|
67
75
|
end
|
68
76
|
|
69
77
|
def process(task)
|
78
|
+
client = Cadence::Client.generate
|
79
|
+
middleware_chain = Middleware::Chain.new(middleware)
|
80
|
+
|
70
81
|
DecisionTaskProcessor.new(task, domain, workflow_lookup, client, middleware_chain).process
|
71
82
|
end
|
83
|
+
|
84
|
+
def thread_pool
|
85
|
+
@thread_pool ||= ThreadPool.new(options[:thread_pool_size])
|
86
|
+
end
|
72
87
|
end
|
73
88
|
end
|
74
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cadence-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Dmitriyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thrift
|