-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add order-worker. #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/temporalio/orders-reference-app-go/order" | ||
"github.com/temporalio/orders-reference-app-go/shipment" | ||
"go.temporal.io/sdk/client" | ||
"go.temporal.io/sdk/worker" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "order-worker", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to change anything, but can get a bit confusing calling this "order" worker that does "order" and "shipment" stuff. I think there is ambiguity on whether "order" means "order" things in code or the general name of the app/worker. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Paul, Rob, and I discussed this. We agree with the comment, but feel that it's probably a short-term issue, as the single Worker will likely be split into more specialized Workers later (e.g., one for Orders and another for Shipments). If that doesn't happen before release, then we'll find a better name for this one. |
||
Short: "Worker for Order system", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
c, err := client.Dial(client.Options{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't have to be now, but at some point we're going to want people to be able to configure their endpoint externally (i.e. ability to run reference app against cloud) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cretz What would you recommend as being the most convenient way to do that? Through environment variables, for example? If so, I can certainly update the code to do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are actually exploring this as a general feature need for Temporal at temporalio/features#441. In the meantime, anything is probably ok (e.g. env vars is fine). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I plan to submit a PR that updates it to use environment variables. I'll use the same as those already used by the Temporal CLI, for consistency. |
||
if err != nil { | ||
log.Fatalf("client error: %v", err) | ||
} | ||
defer c.Close() | ||
|
||
w := worker.New(c, "order", worker.Options{}) | ||
|
||
w.RegisterWorkflow(order.Order) | ||
w.RegisterActivity(&order.Activities{}) | ||
w.RegisterWorkflow(shipment.Shipment) | ||
w.RegisterActivity(&shipment.Activities{SMTPStub: true}) | ||
|
||
err = w.Run(worker.InterruptCh()) | ||
if err != nil { | ||
log.Fatalf("worker exited: %v", err) | ||
} | ||
}, | ||
} | ||
|
||
func main() { | ||
cobra.CheckErr(rootCmd.Execute()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main.go
would be the consistent name for this file with the other cmd