-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/relworker: add relworker command
This adds a basic relworker command. relworker subscribes to the relui queue, and prints messages. Eventually, it will be responsible for executing the release workflows. For golang/go#40279 Change-Id: I6a2fd228e20b7074daa05df56470a8c95c1a8462 Reviewed-on: https://go-review.googlesource.com/c/build/+/275236 Trust: Alexander Rakoczy <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# golang.org/x/build/cmd/relui | ||
|
||
``` | ||
▀▀█ █ | ||
▄ ▄▄ ▄▄▄ █ ▄ ▄ ▄▄▄ ▄ ▄▄ █ ▄ ▄▄▄ ▄ ▄▄ | ||
█▀ ▀ █▀ █ █ ▀▄ ▄ ▄▀ █▀ ▀█ █▀ ▀ █ ▄▀ █▀ █ █▀ ▀ | ||
█ █▀▀▀▀ █ █▄█▄█ █ █ █ █▀█ █▀▀▀▀ █ | ||
█ ▀█▄▄▀ ▀▄▄ █ █ ▀█▄█▀ █ █ ▀▄ ▀█▄▄▀ █ | ||
``` | ||
|
||
relworker is a worker process for running tasks from relui. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// relworker is a worker process for managing the release process of Go. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"cloud.google.com/go/pubsub" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
var ( | ||
projectID = flag.String("project-id", os.Getenv("PUBSUB_PROJECT_ID"), "Pubsub project ID for communicating with relui. Uses PUBSUB_PROJECT_ID by default.") | ||
topicID = flag.String("topic-id", "relui-development", "Pubsub topic ID for communicating with relui.") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
ctx := context.Background() | ||
|
||
sub := getSubscription(ctx, *projectID, *topicID, "relworker") | ||
log.Fatal(sub.Receive(ctx, func(ctx context.Context, msg *pubsub.Message) { | ||
log.Println(string(msg.Data)) | ||
msg.Ack() | ||
})) | ||
} | ||
|
||
// getSubscription creates and returns a pubsub subscription from the project | ||
// specified in projectId, which is to be used for communicating with relui. | ||
// | ||
// It is safe to call if a subscription already exists. A reference to the | ||
// subscription will be returned. | ||
func getSubscription(ctx context.Context, projectID, topicID, subscriptionID string) *pubsub.Subscription { | ||
client, err := pubsub.NewClient(ctx, projectID) | ||
if err != nil { | ||
log.Fatalf("pubsub.NewClient(_, %q) = %v, wanted no error", projectID, err) | ||
} | ||
t := client.Topic(topicID) | ||
// TODO(golang.org/issue/40279): determine if these values are appropriate, move to const/config. | ||
scfg := pubsub.SubscriptionConfig{Topic: t, AckDeadline: 10 * time.Second, ExpirationPolicy: 24 * time.Hour} | ||
_, err = client.CreateSubscription(ctx, subscriptionID, scfg) | ||
if err != nil && status.Code(err) != codes.AlreadyExists { | ||
log.Fatalf("client.CreateSubscription(_, %q, %v) = _, %q, wanted no error or already exists error", subscriptionID, scfg, err) | ||
} | ||
return client.Subscription(subscriptionID) | ||
} |