Files
tasks/tools/tdbg/dlq_job_service.go
86c645568b Adding DescribeDLQJob and CancelDLQJob commands to tdbg (#5086)
<!-- Describe what has changed in this PR -->
**What changed?**
Adding commands to tdbg to call DescribeDLQJob and CancelDLQJob APIs

<!-- Tell your future self why have you made these changes -->
**Why?**
Operators will be using these commands to query the status of ongoing
DLQ jobs and
cancel the jobs if needed.

<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
Unit tests

<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**


<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**

---------

Co-authored-by: Tim Deeb-Swihart <[email protected]>
2023-11-15 10:09:12 -08:00

89 lines
2.7 KiB
Go

// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package tdbg
import (
"fmt"
"io"
"github.com/urfave/cli/v2"
"go.temporal.io/server/api/adminservice/v1"
)
type (
DLQJobService struct {
clientFactory ClientFactory
writer io.Writer
}
)
func NewDLQJobService(
clientFactory ClientFactory,
writer io.Writer,
) *DLQV2Service {
return &DLQV2Service{
clientFactory: clientFactory,
writer: writer,
}
}
func (ac *DLQJobService) DescribeJob(c *cli.Context) error {
adminClient := ac.clientFactory.AdminClient(c)
jobToken := c.String(FlagJobToken)
ctx, cancel := newContext(c)
defer cancel()
response, err := adminClient.DescribeDLQJob(ctx, &adminservice.DescribeDLQJobRequest{
JobToken: jobToken,
})
if err != nil {
return fmt.Errorf("call to DescribeDLQJob failed: %w", err)
}
err = newEncoder(ac.writer).Encode(response)
if err != nil {
return fmt.Errorf("unable to encode DescribeDLQJob response: %w", err)
}
return nil
}
func (ac *DLQJobService) CancelJob(c *cli.Context) error {
adminClient := ac.clientFactory.AdminClient(c)
jobToken := c.String(FlagJobToken)
reason := c.String(FlagReason)
ctx, cancel := newContext(c)
defer cancel()
response, err := adminClient.CancelDLQJob(ctx, &adminservice.CancelDLQJobRequest{
JobToken: jobToken,
Reason: reason,
})
if err != nil {
return fmt.Errorf("call to CancelDLQJob failed: %w", err)
}
err = newEncoder(ac.writer).Encode(response)
if err != nil {
return fmt.Errorf("unable to encode CancelDLQJob response: %w", err)
}
return nil
}