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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 630ceaf2df3bdaf72836bc6efd65bb753967a65b867269a3cff7c9479252bd72
4
- data.tar.gz: cd8645ae092493325f25071257be7c87fcb5a4e43376b19d79c7273260966ffc
3
+ metadata.gz: fe9d521039531a8f5cfe02230061bb23ac7e303cd8fd76367ee727870421295c
4
+ data.tar.gz: 642a711172bf0360fcff1b8d8422cfeadff6b2f081e77f7f57b46dbda65ac890
5
5
  SHA512:
6
- metadata.gz: dc61fa5be6a36cf0dab33000d1ff3d5a2d1be22574074dc1a6b59598ce8f0332dbcfe268a2edd649d9e24d064a4c467fff448a17d8508d96cef3adb5e6328779
7
- data.tar.gz: 5bef6a80f0b1ecee69d8e08d1fb6b746f2a98bc5dec8a388fd53738ef2e60e9c2f943bd4a81ef9254574baae3c0ee3b7f3fdc7c031b2f6ceb69c43e66eabdc98
6
+ metadata.gz: d2da308b055fffc8b31b824df1c083be95fe12ef7b18ac9a5158c17fcbafbe3ef462b44acae8d0801e5ada84ca888fce56166d8843b067bb80b394af86175445
7
+ data.tar.gz: afaf342c71088477fc0f41fa840028b392fd239bf0e1bbbb7faad0c601c75d015efa92c8299316dab9cd2dbef54d690ff67f8c49dd23d4df3c59cb15a4bca610
@@ -1,3 +1,3 @@
1
1
  module Cadence
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -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
- while !shutting_down? do
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
- process(task) if task&.workflowType
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.0
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-15 00:00:00.000000000 Z
11
+ date: 2021-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thrift