Skip to content

Conversation

@antstorm
Copy link
Contributor

@antstorm antstorm commented Dec 7, 2021

When an activity cancellation is requested before the activity had a chance to start Temporal will issue an ACTIVITY_CANCELED event. This PR fixed handling of this event.

Tested:

  • Added both unit & integration specs to ensure it works as expected

@antstorm antstorm added the sync pending Needs to be ported to cadence-ruby label Dec 7, 2021
@antstorm antstorm requested a review from DeRauk December 7, 2021 14:21
# with the intent to propagate to a workflow
class ActivityException < ClientError; end

# Represents cancellation of a non-started activity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since cancels can also happen at a heartbeat, should we unify this case with that case? It's not ideal that people would have to deal with both depending on the timing of when the cancellation comes in.
If that's not possible, should name it as ActivityCanceledBeforeStart?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing preventing other to re-use the Temporal::ActivityCancelled error for heartbeat cancellations. It's just that a heartbeat cancellation is no different from any other failure raised by an activity. I think a more interesting question here is — should we provide a #cancel! API for the activity context that would raise that error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I forgot that in this SDK, heartbeat cancel doesn't throw, it returns a boolean.
In our wrapper SDK (and in the java SDK), it will throw. We think this is the best way to make sure developers don't drop cancellations.

context 'when event is ACTIVITY_CANCELED' do
let(:raw_event) { Fabricate(:api_activity_task_canceled_event) }

it 'sets type to timer' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copypasta?

context 'when event is ACTIVITY_TASK_CANCEL_REQUESTED' do
let(:raw_event) { Fabricate(:api_activity_task_cancel_requested_event) }

it 'sets type to cancel_timer_request' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

©️ 🍝 here as well

@antstorm antstorm merged commit 9e367d1 into master Dec 9, 2021
@antstorm antstorm deleted the fix-non-started-activity-cancellation branch December 9, 2021 18:13
gvieira pushed a commit to clearbit/temporal-ruby that referenced this pull request Dec 21, 2021
* Pass config to the error handler instead of using the global config

* Fix example tests

* Make the config property in the workflow context publicly readable

* [Fix] Retryer GRPC error lookup (coinbase#109)

* Fix issue with GRPC error lookup in Retryer

* Rename spec file for retryer to contain _spec

* [Feature] Add id and domain to workflow context's metadata (coinbase#110)

* Start syncing id and domain on workflow context metadata

* Fixed tests

Co-authored-by: DeRauk Gibble <derauk.gibble@coinbase.com>

* Explicit docker-compose project name (coinbase#114)

* Add YARD documentation for Temporal::Client (coinbase#113)

* Add YARD documentation for Temporal::Client

* Add yard gem

* Fix @option tag

* Typo fix

* Add signal arguments to start_workflow (support for signal_with_start) (coinbase#112)

* Add signal arguments to start_workflow (to support signal_with_start)

* Move signal arguments to the options hash

* PR feedback

* Fix merge error

* Extend #wait_for to take multiple futures and a condition block (coinbase#111)

* Differentiate TARGET_WILDCARD and WILDCARD, allow comparison with EventTarget objects (coinbase#118)

* Turn off schedule_to_start activity timeout by default (coinbase#119)

* Separate options from keyword args in #start_workflow (coinbase#117)

* Separate options from keyword args in #start_workflow

* fixup! Separate options from keyword args in #start_workflow

* Surface additional workflow metadata on workflow context (coinbase#120)

* Refactor metadata generation

* Make task queue available on workflow metadata, add example test

* Expose workflow start time metadata

* Add memos (coinbase#121)

* Add describe_namespace (coinbase#122)

* Add describe_namespace

* Feedback

* Improve header serialization and propagation (coinbase#124)

* [Fix] Non-started activity cancellation (coinbase#125)

* Fix event target map entry for ACTIVITY_CANCELED event

* Fix cancellation of a non-started activity

* fixup! Fix event target map entry for ACTIVITY_CANCELED event

Co-authored-by: DeRauk Gibble <derauk.gibble@coinbase.com>
Co-authored-by: DeRauk Gibble <derauk@gmail.com>
Co-authored-by: Anthony Dmitriyev <antstorm@gmail.com>
Co-authored-by: nagl-stripe <86737162+nagl-stripe@users.noreply.github.com>
Co-authored-by: jeffschoner-stripe <63118764+jeffschoner-stripe@users.noreply.github.com>
Co-authored-by: Drew Hoskins <37816070+drewhoskins-stripe@users.noreply.github.com>
sleep 0.5
Temporal.signal_workflow(LongWorkflow, :CANCEL, workflow_id, run_id)

result = Temporal.await_workflow_result(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always failing for me, locally

  1) Activity cancellation cancels a running activity
     Failure/Error: expect(result).to be_a(LongRunningActivity::Canceled)
       expected #<Temporal::ActivityCanceled: ACTIVITY_ID_NOT_STARTED> to be a kind of LongRunningActivity::Canceled
     # ./spec/integration/activity_cancellation_spec.rb:19:in `block (2 levels) in <top (required)>'

calum-stripe pushed a commit to calum-stripe/temporal-ruby that referenced this pull request Mar 28, 2023
…oner-WOFLO-1216

Support terminate-if-running workflow ID reuse policy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sync pending Needs to be ported to cadence-ruby

Development

Successfully merging this pull request may close these issues.

2 participants