Skip to content

Commit 4621d03

Browse files
authored
Demonstrate interoperability with Coinbase Ruby SDK (#23)
1 parent 1593123 commit 4621d03

File tree

11 files changed

+309
-18
lines changed

11 files changed

+309
-18
lines changed

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
source 'https://rubygems.org'
44

5+
# Primary Temporal dependency
56
gem 'temporalio'
67

8+
# Some samples require certain dependencies, so they are in groups below alphabetically by group
9+
# TODO(cretz): Move this to coinbase/temporal-ruby and off this fork/branch
10+
# when https://github.com/coinbase/temporal-ruby/pull/335 merged, and then update the coinbase_ruby README
11+
gem 'temporal-ruby', github: 'cretz/coinbase-temporal-ruby', branch: 'disable-proto-load-option', group: :coinbase_ruby
12+
713
group :development do
814
gem 'minitest'
915
gem 'rake'

Gemfile.lock

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,48 @@
1+
GIT
2+
remote: https://github.com/cretz/coinbase-temporal-ruby.git
3+
revision: debe21843b6214995fdcb1e4ea052f2b1075cc18
4+
branch: disable-proto-load-option
5+
specs:
6+
temporal-ruby (0.1.1)
7+
base64
8+
grpc
9+
oj
10+
111
GEM
212
remote: https://rubygems.org/
313
specs:
414
ast (2.4.2)
15+
base64 (0.2.0)
516
bigdecimal (3.1.9)
6-
google-protobuf (4.30.2)
7-
bigdecimal
8-
rake (>= 13)
9-
google-protobuf (4.30.2-aarch64-linux)
10-
bigdecimal
11-
rake (>= 13)
12-
google-protobuf (4.30.2-arm64-darwin)
13-
bigdecimal
14-
rake (>= 13)
15-
google-protobuf (4.30.2-x86-linux)
16-
bigdecimal
17-
rake (>= 13)
18-
google-protobuf (4.30.2-x86_64-darwin)
19-
bigdecimal
20-
rake (>= 13)
21-
google-protobuf (4.30.2-x86_64-linux)
22-
bigdecimal
23-
rake (>= 13)
17+
google-protobuf (3.25.7)
18+
googleapis-common-protos-types (1.19.0)
19+
google-protobuf (>= 3.18, < 5.a)
20+
grpc (1.71.0)
21+
google-protobuf (>= 3.25, < 5.0)
22+
googleapis-common-protos-types (~> 1.0)
23+
grpc (1.71.0-aarch64-linux)
24+
google-protobuf (>= 3.25, < 5.0)
25+
googleapis-common-protos-types (~> 1.0)
26+
grpc (1.71.0-arm64-darwin)
27+
google-protobuf (>= 3.25, < 5.0)
28+
googleapis-common-protos-types (~> 1.0)
29+
grpc (1.71.0-x86-linux)
30+
google-protobuf (>= 3.25, < 5.0)
31+
googleapis-common-protos-types (~> 1.0)
32+
grpc (1.71.0-x86_64-darwin)
33+
google-protobuf (>= 3.25, < 5.0)
34+
googleapis-common-protos-types (~> 1.0)
35+
grpc (1.71.0-x86_64-linux)
36+
google-protobuf (>= 3.25, < 5.0)
37+
googleapis-common-protos-types (~> 1.0)
2438
json (2.9.1)
2539
language_server-protocol (3.17.0.3)
2640
logger (1.7.0)
2741
minitest (5.25.4)
42+
oj (3.16.10)
43+
bigdecimal (>= 3.0)
44+
ostruct (>= 0.2)
45+
ostruct (0.6.1)
2846
parallel (1.26.3)
2947
parser (3.3.6.0)
3048
ast (~> 2.4.1)
@@ -77,6 +95,7 @@ DEPENDENCIES
7795
minitest
7896
rake
7997
rubocop
98+
temporal-ruby!
8099
temporalio
81100

82101
BUNDLED WITH

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Prerequisites:
2121
<!-- Keep this list in alphabetical order -->
2222
* [activity_simple](activity_simple) - Simple workflow that calls two activities.
2323
* [activity_worker](activity_worker) - Use Ruby activities from a workflow in another language.
24+
* [coinbase_ruby](coinbase_ruby) - Demonstrate interoperability with the
25+
[Coinbase Ruby SDK](https://github.com/coinbase/temporal-ruby).
2426
* [context_propagation](context_propagation) - Use interceptors to propagate thread/fiber local data from clients
2527
through workflows/activities.
2628
* [message_passing_simple](message_passing_simple) - Simple workflow that accepts signals, queries, and updates.

coinbase_ruby/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Coinbase Ruby
2+
3+
This sample shows a workflow, activity, and client from [Coinbase Ruby SDK](https://github.com/coinbase/temporal-ruby)
4+
able to interoperate with a workflow, activity, and client from Temporal Ruby SDK. Specifically this sample contains an
5+
activity in both SDKs, a workflow in both SDKs each calling both activities, a worker in both SDKs running in the same
6+
process, and a starter with clients from each SDK each invoking both workflows.
7+
8+
⚠️ NOTE - this requires disabling the loading of protos from the Coinbase Ruby SDK. As of this writing,
9+
https://github.com/coinbase/temporal-ruby/pull/335 is not merged, so the Gemfile depends on the branch at
10+
https://github.com/cretz/coinbase-temporal-ruby/tree/disable-proto-load-option for now.
11+
12+
To run, first see [README.md](../README.md) for prerequisites. Then, in another terminal, start the Ruby worker
13+
from this directory:
14+
15+
bundle exec ruby worker.rb
16+
17+
Finally in another terminal, use the Ruby client to run the workflow from this directory:
18+
19+
bundle exec ruby starter.rb
20+
21+
The Ruby code will invoke 4 workflows. The output of the final command should be:
22+
23+
```
24+
Coinbase SDK workflow result from Temporal SDK client: ["Hello from Coinbase Ruby SDK, user1!", "Hello from Temporal Ruby SDK, user1!"]
25+
Temporal SDK workflow result from Temporal SDK client: ["Hello from Coinbase Ruby SDK, user2!", "Hello from Temporal Ruby SDK, user2!"]
26+
Coinbase SDK workflow result from Coinbase SDK client: ["Hello from Coinbase Ruby SDK, user3!", "Hello from Temporal Ruby SDK, user3!"]
27+
Temporal SDK workflow result from Coinbase SDK client: ["Hello from Coinbase Ruby SDK, user4!", "Hello from Temporal Ruby SDK, user4!"]
28+
```

coinbase_ruby/coinbase_activity.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require 'temporal-ruby'
4+
5+
module CoinbaseRuby
6+
class CoinbaseActivity < Temporal::Activity
7+
def execute(name)
8+
"Hello from Coinbase Ruby SDK, #{name}!"
9+
end
10+
end
11+
end

coinbase_ruby/coinbase_workflow.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require 'temporal-ruby'
4+
require_relative 'coinbase_activity'
5+
6+
module CoinbaseRuby
7+
class CoinbaseWorkflow < Temporal::Workflow
8+
def execute(name)
9+
[
10+
# Execute activity on Coinbase SDK worker
11+
CoinbaseActivity.execute!(name),
12+
# Execute activity on Temporal SDK worker
13+
workflow.execute_activity!(:TemporalActivity, name, options: { task_queue: 'coinbase-ruby-sample-temporal' })
14+
]
15+
end
16+
end
17+
end

coinbase_ruby/starter.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
# We must require Temporal SDK first and set the env var to prevent Coinbase SDK from trying to load its protos
4+
require 'temporalio/client'
5+
ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] = '1'
6+
7+
require_relative 'coinbase_workflow'
8+
require_relative 'temporal_workflow'
9+
require 'logger'
10+
require 'temporal-ruby'
11+
12+
# Create Temporal SDK client
13+
client = Temporalio::Client.connect('localhost:7233', 'default')
14+
15+
# Run Coinbase workflow
16+
result = client.execute_workflow(
17+
CoinbaseRuby::CoinbaseWorkflow.name, 'user1',
18+
id: 'coinbase-ruby-sample-workflow-id-1', task_queue: 'coinbase-ruby-sample-coinbase'
19+
)
20+
puts "Coinbase SDK workflow result from Temporal SDK client: #{result}"
21+
22+
# Run Temporal workflow
23+
result = client.execute_workflow(
24+
CoinbaseRuby::TemporalWorkflow, 'user2',
25+
id: 'coinbase-ruby-sample-workflow-id-2', task_queue: 'coinbase-ruby-sample-temporal'
26+
)
27+
puts "Temporal SDK workflow result from Temporal SDK client: #{result}"
28+
29+
# Now do the same with Coinbase SDK, first configuring the client
30+
Temporal.configure do |config|
31+
config.host = 'localhost'
32+
config.port = 7233
33+
config.namespace = 'default'
34+
end
35+
36+
# Run Coinbase workflow
37+
run_id = Temporal.start_workflow(
38+
CoinbaseRuby::CoinbaseWorkflow, 'user3',
39+
options: { workflow_id: 'coinbase-ruby-sample-workflow-id-3', task_queue: 'coinbase-ruby-sample-coinbase' }
40+
)
41+
result = Temporal.await_workflow_result(
42+
CoinbaseRuby::CoinbaseWorkflow,
43+
workflow_id: 'coinbase-ruby-sample-workflow-id-3', run_id:
44+
)
45+
puts "Coinbase SDK workflow result from Coinbase SDK client: #{result}"
46+
47+
# Run Temporal workflow
48+
run_id = Temporal.start_workflow(
49+
:TemporalWorkflow, 'user4',
50+
options: { workflow_id: 'coinbase-ruby-sample-workflow-id-4', task_queue: 'coinbase-ruby-sample-temporal' }
51+
)
52+
result = Temporal.await_workflow_result(
53+
:TemporalWorkflow,
54+
workflow_id: 'coinbase-ruby-sample-workflow-id-4', run_id:
55+
)
56+
puts "Temporal SDK workflow result from Coinbase SDK client: #{result}"

coinbase_ruby/temporal_activity.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require 'temporalio/activity'
4+
5+
module CoinbaseRuby
6+
class TemporalActivity < Temporalio::Activity::Definition
7+
def execute(name)
8+
"Hello from Temporal Ruby SDK, #{name}!"
9+
end
10+
end
11+
end

coinbase_ruby/temporal_workflow.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require 'temporalio/workflow'
4+
require_relative 'coinbase_activity'
5+
require_relative 'temporal_activity'
6+
7+
module CoinbaseRuby
8+
class TemporalWorkflow < Temporalio::Workflow::Definition
9+
def execute(name)
10+
[
11+
# Execute activity on Coinbase SDK worker
12+
Temporalio::Workflow.execute_activity(CoinbaseActivity.name, name,
13+
start_to_close_timeout: 10, task_queue: 'coinbase-ruby-sample-coinbase'),
14+
# Execute activity on Temporal SDK worker
15+
Temporalio::Workflow.execute_activity(TemporalActivity, name, start_to_close_timeout: 10)
16+
]
17+
end
18+
end
19+
end

coinbase_ruby/worker.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
# We must require Temporal SDK first and set the env var to prevent Coinbase SDK from trying to load its protos
4+
require 'temporalio/client'
5+
require 'temporalio/worker'
6+
ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] = '1'
7+
8+
require_relative 'coinbase_activity'
9+
require_relative 'coinbase_workflow'
10+
require_relative 'temporal_activity'
11+
require_relative 'temporal_workflow'
12+
require 'logger'
13+
require 'temporal-ruby'
14+
require 'temporal/worker'
15+
16+
# Create a Temporal client
17+
client = Temporalio::Client.connect(
18+
'localhost:7233',
19+
'default',
20+
logger: Logger.new($stdout, level: Logger::INFO)
21+
)
22+
23+
# Create Temporal worker with the activity and workflow on the coinbase-ruby-sample-temporal task queue
24+
worker = Temporalio::Worker.new(
25+
client:,
26+
task_queue: 'coinbase-ruby-sample-temporal',
27+
activities: [CoinbaseRuby::TemporalActivity],
28+
workflows: [CoinbaseRuby::TemporalWorkflow]
29+
)
30+
31+
# Run the Temporal worker and inside it run the Coinbase worker
32+
puts 'Starting worker on both Temporal Ruby SDK and Coinbase Ruby SDK'
33+
worker.run do
34+
# Configure Coinbase client/worker on the coinbase-ruby-sample-coinbase task queue
35+
Temporal.configure do |config|
36+
config.host = 'localhost'
37+
config.port = 7233
38+
config.namespace = 'default'
39+
config.task_queue = 'coinbase-ruby-sample-coinbase'
40+
end
41+
42+
# Run the Coinbase worker
43+
worker = Temporal::Worker.new
44+
worker.register_activity(CoinbaseRuby::CoinbaseActivity)
45+
worker.register_workflow(CoinbaseRuby::CoinbaseWorkflow)
46+
worker.start
47+
end

0 commit comments

Comments
 (0)