Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream from coinbase's branch #8

Open
wants to merge 129 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
9d88b87
Pass config to the error handler instead of using the global config
DeRauk Oct 5, 2021
f0fee2d
Fix example tests
DeRauk Oct 5, 2021
9c58a49
Make the config property in the workflow context publicly readable
DeRauk Oct 20, 2021
3b5a4dc
Merge pull request #107 from DeRauk/error-handler-config-refactor
DeRauk Oct 20, 2021
fba30df
[Fix] Retryer GRPC error lookup (#109)
antstorm Oct 22, 2021
be33f00
[Feature] Add id and domain to workflow context's metadata (#110)
DeRauk Nov 1, 2021
2c16ba1
Explicit docker-compose project name (#114)
antstorm Nov 3, 2021
64dca95
Add YARD documentation for Temporal::Client (#113)
antstorm Nov 8, 2021
9a581ce
Add signal arguments to start_workflow (support for signal_with_start…
nagl-stripe Nov 9, 2021
8c36d90
Extend #wait_for to take multiple futures and a condition block (#111)
jeffschoner-stripe Nov 12, 2021
388d9ed
Differentiate TARGET_WILDCARD and WILDCARD, allow comparison with Eve…
jeffschoner-stripe Nov 15, 2021
be42f00
Turn off schedule_to_start activity timeout by default (#119)
drewhoskins-stripe Nov 17, 2021
824652b
Separate options from keyword args in #start_workflow (#117)
antstorm Nov 17, 2021
5648972
Surface additional workflow metadata on workflow context (#120)
jeffschoner-stripe Nov 21, 2021
7d63692
Add memos (#121)
jeffschoner-stripe Nov 28, 2021
654cdad
Add describe_namespace (#122)
drewhoskins-stripe Nov 30, 2021
27ac014
Improve header serialization and propagation (#124)
jeffschoner-stripe Dec 5, 2021
9e367d1
[Fix] Non-started activity cancellation (#125)
antstorm Dec 9, 2021
965ef0d
[Fix] Workflow scheduling using a String for a workflow name (#128)
antstorm Dec 23, 2021
265edd3
Fix describe_namespace integration spec to use the default namespace …
jeffschoner-stripe Jan 4, 2022
f764e21
Make error deserialization more resilient (#127)
nagl-stripe Jan 10, 2022
6adb4e4
Modify the Getting Started section so that it works
chuckremes2 Jan 12, 2022
31d22ce
add namespace to emitted metrics
christopherb-stripe Jan 19, 2022
f4c57b5
Merge pull request #131 from chuckremes2/master
DeRauk Jan 21, 2022
30342ae
Merge pull request #132 from christopherb-stripe/christopherb/metrics…
DeRauk Jan 21, 2022
534d2a6
emit the workflow name tag during activity processing
christopherb-stripe Jan 31, 2022
0d7e637
fix typo
christopherb-stripe Jan 31, 2022
101ec13
Merge pull request #133 from christopherb-stripe/christopherb/add-wor…
DeRauk Feb 4, 2022
e249d63
Added list_namespace to client and fixed gRPC request (#137)
calum-stripe Feb 14, 2022
175ffe4
Add support for SignalExternalWorkflow (#134)
chuckremes2 Feb 14, 2022
427f105
Reject commands issued after workflow completion (#135)
drewhoskins-stripe Feb 14, 2022
fd445bd
Populate namespace field to all workflow/activity task RPCs (#139)
cvanderschuere Feb 21, 2022
48f185e
[Fix] Add missing namespace arg for heartbeat (#146)
dwillett Feb 28, 2022
69f90a3
Implement upsert_search_attributes (#145)
drewhoskins-stripe Feb 28, 2022
bfd5250
Improvements for upsert_search_attributes (#147)
drewhoskins-stripe Mar 2, 2022
7422a38
Remove error logspew when workers shutdown (#148)
drewhoskins-stripe Mar 4, 2022
5b2d7e4
Added stub for signal_external_workflow (#142)
cvanderschuere Mar 4, 2022
6f094b8
[Fix] Spec issues with Ruby 3 (#155)
antstorm Mar 4, 2022
a769b1f
Fix bugs with workflow.upsert_search_attributes (#154)
drewhoskins-stripe Mar 4, 2022
d5f3918
List filter workflow executions (#151)
DeRauk Mar 4, 2022
9f4ee9d
Fix upsert_search_attributes (#158)
drewhoskins-stripe Mar 8, 2022
0cfd4b3
expose memo to child workflow execution (#160)
aryak-stripe Mar 8, 2022
1e29989
Added fix for nil search attributes when listing workflows (#161)
calum-stripe Mar 12, 2022
e85d401
Make it easier to debug converter_spec failure. (#153)
drewhoskins-stripe Mar 14, 2022
37a2c4f
Expose scheduled_time and current_attempt_scheduled_time on activity …
nagl-stripe Mar 17, 2022
4ce0748
child workflow execution parent close policy (#163)
aryak-stripe Mar 17, 2022
f02fec1
Updating register namespace (#149)
calum-stripe Mar 17, 2022
25a666f
Expose wait_for_start for child workflow execution (#167)
arya-k Mar 23, 2022
06b9997
Synchronous-proxy example in Ruby (#138)
chuckremes2 Mar 23, 2022
79c0b36
Add parent_run_id, parent_id to workflow metadata (#169)
aryak-stripe Mar 28, 2022
243c6a7
Named signal handlers (#157)
chuckremes2 Apr 7, 2022
93c7102
Better error message for NonDeterministicWorkflowError (#171)
drewhoskins-stripe Apr 12, 2022
398fd24
Support for invoking and processing queries (#141)
Apr 15, 2022
dd52ab9
Expose workflow name in activity metadata in temporal-ruby's unit tes…
nagl-stripe Apr 19, 2022
6b8973f
Fix bugs around child workflow ids and workflow_reuse_policy (#172)
nagl-stripe Apr 19, 2022
20bc15f
Fix a merge error between child workflows and metadata enrichment (#180)
nagl-stripe Apr 20, 2022
fd6f98d
Added list workflows API and Pagination Support (#177)
calum-stripe May 5, 2022
aa30be1
[API Breaking] Separate wait_for into two methods: wait_for_any and w…
jeffschoner-stripe May 5, 2022
d686c32
Add binary checksum (#179)
jeffschoner-stripe May 5, 2022
dbf3273
Child workflow futures (#181)
calum-stripe May 5, 2022
dd0a489
Remove finished dispatcher handlers, order dispatch handlers (#183)
jeffschoner-stripe Jun 6, 2022
78e4fb8
Add gRPC credentials (#186)
jlemesh Jun 24, 2022
0e3e7b1
Query functionality for temporal-web: stack trace and registered quer…
jeffschoner Jun 24, 2022
ac8ae20
Allow initial search attributes to be specified when starting workflo…
jazevedo-stripe Aug 5, 2022
bb3f330
Fix dispatch ordering of wait_until handlers (#189)
jeffschoner Sep 6, 2022
a7259e1
Add an interface and support for cron scheduling child workflows (#190)
dwillett Sep 9, 2022
17181e4
Adds ProtoJSON support for protobuf inputs (#192)
stuppy Sep 16, 2022
bd5b705
Pin RSpec to 3.10.0 (#200)
antstorm Oct 25, 2022
155a046
Fix for incorrect handling of Child Workflows that time out and are t…
calum-stripe Oct 26, 2022
b50f0d0
Derive client identity from pid, make configurable (#198)
jeffschoner-stripe Oct 26, 2022
13ac2e2
Task metrics (#199)
jeffschoner-stripe Oct 28, 2022
e84f669
Unify converter accessor, make default_identity private (#202)
jeffschoner-stripe Oct 28, 2022
dcec716
x (#205)
calum-stripe Nov 18, 2022
58379cd
dynamic Activity (#208)
drewhoskins-stripe Jan 3, 2023
214b334
Allow exceptions thrown from activities to accept more args (#214)
drewhoskins-stripe Feb 9, 2023
f16228e
Update Temporal API to 1.16 (#217)
jeffschoner Feb 13, 2023
ed2e905
Test for executable concerns with dup only for String (#219)
jeffschoner Feb 27, 2023
868e492
APIs for managing custom search attributes (#218)
jeffschoner Feb 27, 2023
d0cf921
dynamic Workflow (#221)
drewhoskins-stripe Mar 8, 2023
5e9dd9e
Read search attributes from inside workflow code (#222)
jeffschoner Mar 24, 2023
d0f3ad9
Add header propagation and workflow middleware. (#226)
markchua Mar 28, 2023
86264ad
Paginate through empty workflow history pages (#213)
drewhoskins-stripe Apr 3, 2023
6e5fc34
Don't serialize huge exceptions (#227)
drewhoskins-stripe Apr 6, 2023
21252c4
Adding payload codec pipeline (#224)
calum-stripe Apr 7, 2023
8077a87
Fix header in example integration test. (#230)
markchua Apr 10, 2023
01da80c
Update READMEs for running integration specs (#231)
jeffschoner Apr 10, 2023
5d1c088
Fix broken encryption specs, update Temporal API proto to 1.20 (#233)
jeffschoner Apr 12, 2023
89b0fa5
Integrate CI with Github Actions (#235)
DeRauk Apr 13, 2023
9b4cc16
Add sleep after bad poll (#216)
jlemesh Apr 17, 2023
6256f56
Terminate-if-running workflow ID reuse policy (#220)
jeffschoner Apr 17, 2023
c2b1ec2
Add client-name and client-version headers (#223)
mjameswh Apr 19, 2023
59ed591
Temporal CLI and SQL-based enhanced visibility compatibility (#236)
jeffschoner Apr 20, 2023
146cfed
Require version (#241)
jeffschoner May 5, 2023
d972473
Add a dynamic config for the examples docker container and set system…
DeRauk May 5, 2023
8266601
Make worker.start and worker.stop threadsafe (#240)
jeffschoner May 6, 2023
41a8e92
Heartbeat throttling (#234)
jeffschoner May 10, 2023
8979bd8
Fix continue as new timeout propagation (#246)
jeffschoner Jun 7, 2023
c60c0dd
Fix and add spec for local activities (#247)
jeffschoner Jun 7, 2023
4bb72e6
add filter to query_workflow_executions method arguments (#250)
hashimr1 Jun 14, 2023
71eaf80
Add missing arguments to Temporal.reset_workflow and add integration …
jazev-stripe Jul 14, 2023
80f0063
Update version to 0.0.3 (#257)
cj-cb Jul 17, 2023
4a379c1
Signals first ordering (#261)
jeffschoner Sep 11, 2023
d75dfee
Fix continue as new timeout propagation (#265)
jeffschoner Sep 11, 2023
0540942
ProtoJSON safely encode JSON to ASCII-8BIT (String#b) (#264)
stuppy Oct 11, 2023
263e975
History size and suggest continue as new (#269)
jeffschoner Oct 19, 2023
08fe1e9
Save signals on first workflow task (#268)
jeffschoner Oct 20, 2023
6a11a81
Improve thread pool error handling (#273)
jeffschoner Oct 30, 2023
cce6f02
Expose count_workflow_executions on the temporal client (#272)
harsh-stripe Nov 9, 2023
628960b
Add Schedule api support (#277)
dhruv-stripe Jan 4, 2024
cfcbdd3
Remove cancelation commands when underlying futures are closed (#275)
jeffschoner Jan 4, 2024
052641c
Fix task queue type to match enum (#252)
awesomenix Jan 4, 2024
b6c7a76
fix: Use Standard Interface for Metrics Tags (#228)
0xTheProDev Jan 5, 2024
95d62d2
Add keyword arguments support to Activity classes (#255)
santiagodoldan Jan 5, 2024
3e0dae7
Fix warnings (#282)
jeffschoner Jan 16, 2024
65dfdb0
Add option for gRPC client connection retries (#270)
hughevans Feb 5, 2024
c4fb094
Update README with middleware documentation (#288)
DeRauk Mar 5, 2024
b20abf6
Pin examples auto-setup image to v1.22.0 (#298)
DeRauk Apr 6, 2024
f075102
Move off `Dry::Struct::Value` before its removed from `dry-struct` (#…
SalvatoreT Apr 6, 2024
34a7e4d
Plumb through :use_error_serialization_v2 from Configuration -> GRPC …
davehughes May 9, 2024
3fbc675
Mark continue_as_new as not implemented in testing context (#299)
taonic May 9, 2024
5d12aa3
Replay testing (#300)
jeffschoner Jun 24, 2024
dc937e8
Specify Protobuf Version To Fix Build (#308)
DeRauk Jul 17, 2024
0c9a0c7
Add pagination to get_workflow_history (#290)
cduanfigma Jul 22, 2024
c3991a9
Relax version specifier for 'google-protobuf' to fix build errors on …
jazev-stripe Jul 30, 2024
0d3a8bb
Support passing activity task rate limit on worker options (#311)
jazev-stripe Jul 30, 2024
e3c351f
Fix integration specs (#315)
antstorm Sep 3, 2024
c73a07e
[Refactor] Remove Temporal::Concerns::Payloads (#314)
antstorm Sep 4, 2024
f41efb7
[Refactor] Remove global config references (#317)
antstorm Sep 4, 2024
b5efd2c
Add workflow start delay option (#294)
santiagodoldan Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
History size and suggest continue as new (coinbase#269)
* Track history size

* Add example integration test for continuing as new
  • Loading branch information
jeffschoner authored Oct 19, 2023
commit 263e975961ce0da1613af93775377b182ebbe5db
1 change: 1 addition & 0 deletions examples/bin/worker
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ worker.register_workflow(CancellingTimerWorkflow)
worker.register_workflow(CheckWorkflow)
worker.register_workflow(ChildWorkflowTimeoutWorkflow)
worker.register_workflow(ChildWorkflowTerminatedWorkflow)
worker.register_workflow(ContinueAsNewWorkflow)
worker.register_workflow(FailingActivitiesWorkflow)
worker.register_workflow(FailingWorkflow)
worker.register_workflow(HandlingStructuredErrorWorkflow)
43 changes: 43 additions & 0 deletions examples/spec/integration/continue_as_new_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'workflows/continue_as_new_workflow'
require 'workflows/loop_workflow'

describe LoopWorkflow do
@@ -47,4 +48,46 @@
expect(final_result[:memo]).to eq(memo)
expect(final_result[:headers]).to eq(headers)
end

it 'uses history bytes size to continue as new' do
workflow_id = SecureRandom.uuid
# 7 activity invocations produce about 10,000 bytes of history. This should
# result in one continue as new with 7 activities in the first and 3 in the
# second run.
run_id = Temporal.start_workflow(
ContinueAsNewWorkflow,
10, # hello count
10_000, # max bytes limit
options: {
workflow_id: workflow_id,
timeouts: {
execution: 60,
run: 20
}
},
)

# First run will throw because it continued as new
next_run_id = nil
expect do
Temporal.await_workflow_result(
ContinueAsNewWorkflow,
workflow_id: workflow_id,
run_id: run_id,
)
end.to raise_error(Temporal::WorkflowRunContinuedAsNew) do |error|
next_run_id = error.new_run_id
end

expect(next_run_id).to_not eq(nil)

# Second run will not throw because it returns rather than continues as new.
final_result = Temporal.await_workflow_result(
ContinueAsNewWorkflow,
workflow_id: workflow_id,
run_id: next_run_id,
)

expect(final_result[:runs]).to eq(2)
end
end
19 changes: 19 additions & 0 deletions examples/workflows/continue_as_new_workflow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'activities/hello_world_activity'

# Demonstrates how to use history_size to determine when to continue as new
class ContinueAsNewWorkflow < Temporal::Workflow
def execute(hello_count, bytes_max, run = 1)
while hello_count.positive? && workflow.history_size.bytes < bytes_max
HelloWorldActivity.execute!("Alice Long#{'long' * 100}name")
hello_count -= 1
end

workflow.logger.info("Workflow history size: #{workflow.history_size}, remaining hellos: #{hello_count}")

return workflow.continue_as_new(hello_count, bytes_max, run + 1) if hello_count.positive?

{
runs: run
}
end
end
6 changes: 6 additions & 0 deletions lib/temporal/workflow/context.rb
Original file line number Diff line number Diff line change
@@ -67,6 +67,12 @@ def has_release?(release_name)
state_manager.release?(release_name.to_s)
end

# Returns information about the workflow run's history up to this point. This can be used to
# determine when to continue as new.
def history_size
state_manager.history_size
end

def execute_activity(activity_class, *input, **args)
options = args.delete(:options) || {}
input << args unless args.empty?
11 changes: 11 additions & 0 deletions lib/temporal/workflow/history/size.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Temporal
class Workflow
class History
Size = Struct.new(
:bytes, # integer, total number of bytes used
:events, # integer, total number of history events used
:suggest_continue_as_new, # boolean, true if server history length limits are being approached
keyword_init: true)
end
end
end
6 changes: 5 additions & 1 deletion lib/temporal/workflow/history/window.rb
Original file line number Diff line number Diff line change
@@ -5,14 +5,16 @@ module Temporal
class Workflow
class History
class Window
attr_reader :local_time, :last_event_id, :events, :sdk_flags
attr_reader :local_time, :last_event_id, :events, :sdk_flags, :history_size_bytes, :suggest_continue_as_new

def initialize
@local_time = nil
@last_event_id = nil
@events = []
@replay = false
@sdk_flags = Set.new
@history_size_bytes = 0
@suggest_continue_as_new = false
end

def replay?
@@ -24,6 +26,8 @@ def add(event)
when 'WORKFLOW_TASK_STARTED'
@last_event_id = event.id + 1 # one for completed
@local_time = event.timestamp
@history_size_bytes = event.attributes.history_size_bytes
@suggest_continue_as_new = event.attributes.suggest_continue_as_new
when 'WORKFLOW_TASK_FAILED', 'WORKFLOW_TASK_TIMED_OUT'
@last_event_id = nil
@local_time = nil
11 changes: 11 additions & 0 deletions lib/temporal/workflow/state_manager.rb
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
require 'temporal/workflow/command'
require 'temporal/workflow/command_state_machine'
require 'temporal/workflow/history/event_target'
require 'temporal/workflow/history/size'
require 'temporal/concerns/payloads'
require 'temporal/workflow/errors'
require 'temporal/workflow/sdk_flags'
@@ -90,6 +91,8 @@ def apply(history_window)
@local_time = history_window.local_time
@last_event_id = history_window.last_event_id
history_window.sdk_flags.each { |flag| sdk_flags.add(flag) }
@history_size_bytes = history_window.history_size_bytes
@suggest_continue_as_new = history_window.suggest_continue_as_new

order_events(history_window.events).each do |event|
apply_event(event)
@@ -116,6 +119,14 @@ def self.signal_event?(event)
event.type == 'WORKFLOW_EXECUTION_SIGNALED'
end

def history_size
History::Size.new(
events: @last_event_id,
bytes: @history_size_bytes,
suggest_continue_as_new: @suggest_continue_as_new
).freeze
end

private

attr_reader :dispatcher, :command_tracker, :marker_ids, :side_effects, :releases, :sdk_flags
5 changes: 4 additions & 1 deletion spec/fabricators/grpc/history_event_fabricator.rb
Original file line number Diff line number Diff line change
@@ -62,12 +62,15 @@ class TestSerializer
end

Fabricator(:api_workflow_task_started_event, from: :api_history_event) do
transient :history_size_bytes, :suggest_continue_as_new
event_type { Temporalio::Api::Enums::V1::EventType::EVENT_TYPE_WORKFLOW_TASK_STARTED }
workflow_task_started_event_attributes do |attrs|
Temporalio::Api::History::V1::WorkflowTaskStartedEventAttributes.new(
scheduled_event_id: attrs[:event_id] - 1,
identity: 'test-worker@test-host',
request_id: SecureRandom.uuid
request_id: SecureRandom.uuid,
history_size_bytes: attrs[:history_size_bytes],
suggest_continue_as_new: attrs[:suggest_continue_as_new]
)
end
end
34 changes: 34 additions & 0 deletions spec/unit/lib/temporal/workflow/state_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -302,6 +302,40 @@ def test_order(signal_first)
end
end

describe '#history_size' do
let(:config) { Temporal::Configuration.new }
let(:history_size_bytes) { 27 }
let(:suggest_continue_as_new) { true }
let(:start_workflow_execution_event) { Fabricate(:api_workflow_execution_started_event) }
let(:workflow_task_scheduled_event) { Fabricate(:api_workflow_task_scheduled_event, event_id: 2) }
let(:workflow_task_started_event) do
Fabricate(
:api_workflow_task_started_event,
event_id: 3,
history_size_bytes: history_size_bytes,
suggest_continue_as_new: suggest_continue_as_new)
end

it 'has correct event count' do
state_manager = described_class.new(Temporal::Workflow::Dispatcher.new, config)

window = Temporal::Workflow::History::Window.new
window.add(Temporal::Workflow::History::Event.new(start_workflow_execution_event))
window.add(Temporal::Workflow::History::Event.new(workflow_task_scheduled_event))
window.add(Temporal::Workflow::History::Event.new(workflow_task_started_event))

state_manager.apply(window)

expect(state_manager.history_size).to eq(
Temporal::Workflow::History::Size.new(
events: 4, # comes from event id of started + 1
bytes: history_size_bytes,
suggest_continue_as_new: suggest_continue_as_new
)
)
end
end

describe '#search_attributes' do
let(:initial_search_attributes) do
{