Skip to content

Commit 6f0aa4e

Browse files
committed
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]>
1 parent 024bd71 commit 6f0aa4e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

cmd/relworker/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# golang.org/x/build/cmd/relui
2+
3+
```
4+
▀▀█ █
5+
▄ ▄▄ ▄▄▄ █ ▄ ▄ ▄▄▄ ▄ ▄▄ █ ▄ ▄▄▄ ▄ ▄▄
6+
█▀ ▀ █▀ █ █ ▀▄ ▄ ▄▀ █▀ ▀█ █▀ ▀ █ ▄▀ █▀ █ █▀ ▀
7+
█ █▀▀▀▀ █ █▄█▄█ █ █ █ █▀█ █▀▀▀▀ █
8+
█ ▀█▄▄▀ ▀▄▄ █ █ ▀█▄█▀ █ █ ▀▄ ▀█▄▄▀ █
9+
10+
```
11+
12+
relworker is a worker process for running tasks from relui.

cmd/relworker/main.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// relworker is a worker process for managing the release process of Go.
6+
package main
7+
8+
import (
9+
"context"
10+
"flag"
11+
"log"
12+
"os"
13+
"time"
14+
15+
"cloud.google.com/go/pubsub"
16+
"google.golang.org/grpc/codes"
17+
"google.golang.org/grpc/status"
18+
)
19+
20+
var (
21+
projectID = flag.String("project-id", os.Getenv("PUBSUB_PROJECT_ID"), "Pubsub project ID for communicating with relui. Uses PUBSUB_PROJECT_ID by default.")
22+
topicID = flag.String("topic-id", "relui-development", "Pubsub topic ID for communicating with relui.")
23+
)
24+
25+
func main() {
26+
flag.Parse()
27+
ctx := context.Background()
28+
29+
sub := getSubscription(ctx, *projectID, *topicID, "relworker")
30+
log.Fatal(sub.Receive(ctx, func(ctx context.Context, msg *pubsub.Message) {
31+
log.Println(string(msg.Data))
32+
msg.Ack()
33+
}))
34+
}
35+
36+
// getSubscription creates and returns a pubsub subscription from the project
37+
// specified in projectId, which is to be used for communicating with relui.
38+
//
39+
// It is safe to call if a subscription already exists. A reference to the
40+
// subscription will be returned.
41+
func getSubscription(ctx context.Context, projectID, topicID, subscriptionID string) *pubsub.Subscription {
42+
client, err := pubsub.NewClient(ctx, projectID)
43+
if err != nil {
44+
log.Fatalf("pubsub.NewClient(_, %q) = %v, wanted no error", projectID, err)
45+
}
46+
t := client.Topic(topicID)
47+
// TODO(golang.org/issue/40279): determine if these values are appropriate, move to const/config.
48+
scfg := pubsub.SubscriptionConfig{Topic: t, AckDeadline: 10 * time.Second, ExpirationPolicy: 24 * time.Hour}
49+
_, err = client.CreateSubscription(ctx, subscriptionID, scfg)
50+
if err != nil && status.Code(err) != codes.AlreadyExists {
51+
log.Fatalf("client.CreateSubscription(_, %q, %v) = _, %q, wanted no error or already exists error", subscriptionID, scfg, err)
52+
}
53+
return client.Subscription(subscriptionID)
54+
}

0 commit comments

Comments
 (0)