Workflow complete #5925
Replies: 12 comments 9 replies
-
Do you mean terminate/cancel? Check following commands:
|
Beta Was this translation helpful? Give feedback.
-
No don't terminate I want to complete the workflow, I have the context, run
id and workflow id how to achieve by using this.
…On Mon, 22 Apr, 2024, 8:12 pm Ender Demirkaya, ***@***.***> wrote:
Do you mean terminate/cancel? Check following commands:
cadence workflow terminate --help and
cadence workflow cancel --help
—
Reply to this email directly, view it on GitHub
<#5925 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWSX6EZA5BUDZGQIHX4YROLY6UOT5AVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TCOBZHEZDG>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I think I'm still missing something :) You can add a signal for your workflow and complete your workflow upon receiving the signal in your workflow logic. You can send a signal to a workflow when you know the domain name, workflow id and the signal name. |
Beta Was this translation helpful? Give feedback.
-
Yes exactly I want to achieve this, but can you guide how to send signal
and how to receive that signal in an activity, and the signal I'm sending
is out of the workflow like a function working in background not included
in workflow
…On Mon, 22 Apr, 2024, 8:56 pm Ender Demirkaya, ***@***.***> wrote:
I think I'm still missing something :)
You cannot complete workflows externally. It only completes based on the
workflow logic.
Do you maybe mean you want to signal the workflow?
You can add a signal
<https://cadenceworkflow.io/docs/java-client/signals/#implement-signal-handler-in-workflow>
for your workflow and complete your workflow upon receiving the signal in
your workflow logic.
You can send a signal to a workflow when you know the domain name,
workflow id and the signal name.
—
Reply to this email directly, view it on GitHub
<#5925 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWSX6EYV3TDTVVHCJK2F3STY6UT2HAVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TCOJQGU4DC>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
how to send signal though
…On Mon, Apr 22, 2024 at 9:44 PM Ender Demirkaya ***@***.***> wrote:
You cannot receive signals inside an activity, they can only be received
in the workflow code (outside the activity). Feel free to check our samples
(example
<https://github.com/uber-common/cadence-samples/blob/master/new_samples/workflows/signal_greeter_multi_language.go>
).
You normally don't want to wait inside an activity. Your activities should
always be processing something and the "waiting" should be inside the
workflow code via signals and timers.
If you have to use an activity, then you need to implement receiving
signals by yourself inside the activity as Cadence doesn't have access to
your activity. If you can do that, then your activity can immediately
finish and return something indicating workflow needs to complete. Then in
your workflow code, based on that return value, you can complete your
workflow.
Does that answer your question?
—
Reply to this email directly, view it on GitHub
<#5925 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWSX6E5JVTFNNEUXKTRGBGDY6UZPDAVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TCOJRGE4DQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
can you write me a code where a function is sending signal and the worflow
is revcing it
…On Mon, Apr 22, 2024 at 11:19 PM Ender Demirkaya ***@***.***> wrote:
You can either send it from the CLI or programmatically.
- For CLI, check cadence workflow signal --help
- For program, check this test
<https://github.com/uber-common/cadence-samples/blob/master/cmd/samples/recipes/signalcounter/workflow_test.go#L36>
as an example.
—
Reply to this email directly, view it on GitHub
<#5925 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWSX6EY3SBI6ZW5KMOBSU73Y6VEUBAVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TCOJSGA2TK>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
any other way to send signal to a workflow without using cmd line
…On Tue, Apr 23, 2024 at 8:34 PM Ender Demirkaya ***@***.***> wrote:
Here's a sample about signals:
- workflow that receives signals:
https://github.com/uber-common/cadence-samples/blob/master/cmd/samples/recipes/signalcounter/signal_counter_workflow.go#L31
- test that's sending signal
https://github.com/uber-common/cadence-samples/blob/master/cmd/samples/recipes/signalcounter/workflow_test.go#L36
—
Reply to this email directly, view it on GitHub
<#5925 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWSX6E7UDNYOUR3DZKNCFPLY6Z2ANAVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TEMBSGIYTE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Actually i have a function in which it dequeues from a queue, this is the
function in main.go file. when we dequeue we can get workflow id , run id,
ctx of a workflow , now i want to send signal to a workflow which is in
customer.go file waiting to receive a signal. how can i achieve this?
…On Wed, Apr 24, 2024 at 12:31 AM Ender Demirkaya ***@***.***> wrote:
The second link in the response above showing how to send signals
programmatically on line 36.
This is the signal interface where you can see the API doc:
https://github.com/uber-go/cadence-client/blob/master/client/client.go#L168
—
Reply to this email directly, view it on GitHub
<#5925 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWSX6E66YPVBUOGMEKTY6QLY62VY3AVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TEMBUGU3TE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I'll check them out, but sir i am really stuck on this , I will
implement this once and get back at you
Thank you
…On Wed, Apr 24, 2024 at 1:04 AM Ender Demirkaya ***@***.***> wrote:
The links above exactly do that. You need to call the SignalWorkflow API
from the Cadence Client object.
Here are all the samples about signaling:
https://github.com/search?q=repo%3Auber-common%2Fcadence-samples+signalworkflow&type=code
Here's an example StackOverflow entry too:
https://stackoverflow.com/questions/56568871/sending-external-events-to-a-workflow
(search SignalWorkflow in the page)
You can find other examples by searching "cadence signalworkflow" too.
There are several blogs talking about signals as well.
—
Reply to this email directly, view it on GitHub
<#5925 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWSX6E43WJR2OGAM3TTZXA3Y62ZSRAVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TEMBUHA2DA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
c, err := client.NewClient(client.Options{})
if err != nil {
log.Fatalln("unable to create Temporal client", err)
}
The arguments for this is not complete it is saying
[image: image.png]
…On Wed, Apr 24, 2024 at 1:52 AM Ender Demirkaya ***@***.***> wrote:
This was the GPT's output in case its retention expires:
Here's a sample Cadence workflow in Go that accepts a signal to complete
and a code to signal that workflow.
`package main
import (
"context"
"fmt"
"go.uber.org/cadence/activity"
"go.uber.org/cadence/workflow"
"go.uber.org/zap"
"go.uber.org/cadence/worker"
)
// WorkflowName is the name of the workflow
const WorkflowName = "SampleWorkflow"
// SignalName is the name of the signal
const SignalName = "CompleteSignal"
// SampleWorkflow is a sample Cadence workflow
func SampleWorkflow(ctx workflow.Context) error {
logger := workflow.GetLogger(ctx)
logger.Info("SampleWorkflow started")
var completed bool
// This channel will be used to receive the signal
signalChannel := workflow.GetSignalChannel(ctx, SignalName)
// Wait for the signal
workflow.Go(ctx, func(ctx workflow.Context) {
var signalData string
// This will block until the signal is received
signalChannel.Receive(ctx, &signalData)
logger.Info("Received signal", zap.String("SignalData", signalData))
completed = true
})
// This loop will keep waiting for the signal
for !completed {
// Sleep for a short duration before checking again
workflow.Sleep(ctx, 1)
}
logger.Info("Workflow completed")
return nil
}
// SignalWorkflow is used to signal the workflow
func SignalWorkflow(ctx context.Context, workflowID, signalData string)
error {
// Create a Cadence client
client, err := workflow.NewClient(ctx)
if err != nil {
return err
}
defer client.Close()
// Use the client to signal the workflow
signalClient := client.SignalWithStartWorkflow(ctx, workflowID)
err = signalClient.SignalWorkflow(SignalName, signalData, workflowID, SampleWorkflow, nil)
if err != nil {
return err
}
return nil
}
// RegisterWorker registers the workflow and activity with the worker
func RegisterWorker(w worker.Worker) {
w.RegisterWorkflow(SampleWorkflow)
}
func main() {
// Create a Worker.
workerOptions := worker.Options{
Logger: zap.NewNop(),
MaxConcurrentActivityTaskPollers: 5,
}
worker := worker.New(nil, "sample-task-list", workerOptions)
RegisterWorker(worker)
// Start the Worker.
err := worker.Start()
if err != nil {
panic(fmt.Sprintf("unable to start worker: %v", err))
}
}
`
In this sample, SampleWorkflow waits for a signal named CompleteSignal.
You can use the SignalWorkflow function to signal this workflow.
Make sure to include the necessary dependencies in your go.mod:
`module cadence_sample
go 1.17
require (
github.com/uber/cadence-client v0.2.3
go.uber.org/cadence v0.8.0
go.uber.org/zap v1.17.0
)
`
And install them using:
go mod tidy
—
Reply to this email directly, view it on GitHub
<#5925 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWSX6E27BLVUTE3K64R3DMTY627HJAVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TEMBVGIZDG>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Not able to figure out, if it's possible to get on a meet? It'll be really
appreciated as I am working hard on this project
…On Wed, 24 Apr, 2024, 9:59 pm Ender Demirkaya, ***@***.***> wrote:
here's an example way to build client:
https://github.com/uber-common/cadence-samples/blob/df6f7bdba978d6565ad78e9f86d9cd31dfac9f78/new_samples/worker/worker.go#L72
You may need to ready/check the samples I sent above.
—
Reply to this email directly, view it on GitHub
<#5925 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWSX6E2NT3D326J5X4LDJBTY67MXZAVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TEMJVHA4TE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Sir thank you for your time and co-operation. Was able to figure it out
with your links and help.
Thank you
On Thu, Apr 25, 2024 at 3:16 PM shubham goyal ***@***.***>
wrote:
… Not able to figure out, if it's possible to get on a meet? It'll be really
appreciated as I am working hard on this project
On Wed, 24 Apr, 2024, 9:59 pm Ender Demirkaya, ***@***.***>
wrote:
> here's an example way to build client:
> https://github.com/uber-common/cadence-samples/blob/df6f7bdba978d6565ad78e9f86d9cd31dfac9f78/new_samples/worker/worker.go#L72
>
> You may need to ready/check the samples I sent above.
>
> —
> Reply to this email directly, view it on GitHub
> <#5925 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AWSX6E2NT3D326J5X4LDJBTY67MXZAVCNFSM6AAAAABGRJK5U6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TEMJVHA4TE>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
-
How to complete a workflow in between if we have its workflow id .
Beta Was this translation helpful? Give feedback.
All reactions