Skip to content

Commit b4750c5

Browse files
committed
feat(emailworker): Wire up email worker subscriber
This commit connects the email worker's Pub/Sub subscriber to the message handler. It initializes the HTML renderer and the sender, and starts the subscription to process incoming email jobs. The frontend base URL is now configured via an environment variable to support link generation in emails.
1 parent 5d336cd commit b4750c5

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

workers/email/cmd/job/main.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ package main
1717
import (
1818
"context"
1919
"log/slog"
20+
"net/url"
2021
"os"
2122

23+
"github.com/GoogleChrome/webstatus.dev/lib/email/chime/chimeadapters"
2224
"github.com/GoogleChrome/webstatus.dev/lib/gcppubsub"
25+
"github.com/GoogleChrome/webstatus.dev/lib/gcppubsub/gcppubsubadapters"
2326
"github.com/GoogleChrome/webstatus.dev/lib/gcpspanner"
27+
"github.com/GoogleChrome/webstatus.dev/lib/gcpspanner/spanneradapters"
28+
"github.com/GoogleChrome/webstatus.dev/workers/email/pkg/digest"
29+
"github.com/GoogleChrome/webstatus.dev/workers/email/pkg/sender"
2430
)
2531

2632
func main() {
@@ -48,6 +54,18 @@ func main() {
4854
spannerClient.SetMisingOneImplementationQuery(gcpspanner.LocalMissingOneImplementationQuery{})
4955
}
5056

57+
baseURL := os.Getenv("FRONTEND_BASE_URL")
58+
if baseURL == "" {
59+
slog.ErrorContext(ctx, "FRONTEND_BASE_URL is not set. exiting...")
60+
os.Exit(1)
61+
}
62+
63+
parsedBaseURL, err := url.Parse(baseURL)
64+
if err != nil {
65+
slog.ErrorContext(ctx, "failed to parse FRONTEND_BASE_URL", "error", err.Error())
66+
os.Exit(1)
67+
}
68+
5169
// For subscribing to email events
5270
emailSubID := os.Getenv("EMAIL_SUBSCRIPTION_ID")
5371
if emailSubID == "" {
@@ -61,11 +79,20 @@ func main() {
6179
os.Exit(1)
6280
}
6381

64-
// TODO: https://github.com/GoogleChrome/webstatus.dev/issues/1852
65-
// Nil handler for now. Will fix later
66-
err = queueClient.Subscribe(ctx, emailSubID, nil)
82+
renderer, err := digest.NewHTMLRenderer(parsedBaseURL.String())
6783
if err != nil {
68-
slog.ErrorContext(ctx, "unable to connect to subscription", "error", err)
84+
// If the template is not valid, the renderer will fail.
85+
slog.ErrorContext(ctx, "unable to create renderer", "error", err)
86+
os.Exit(1)
87+
}
88+
89+
listener := gcppubsubadapters.NewEmailWorkerSubscriberAdapter(sender.NewSender(
90+
chimeadapters.NewEmailWorkerChimeAdapter(nil),
91+
spanneradapters.NewEmailWorkerChannelStateManager(spannerClient),
92+
renderer,
93+
), queueClient, emailSubID)
94+
if err := listener.Subscribe(ctx); err != nil {
95+
slog.ErrorContext(ctx, "worker subscriber failed", "error", err)
6996
os.Exit(1)
7097
}
7198
}

workers/email/go.mod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ require (
1616
cloud.google.com/go v0.123.0 // indirect
1717
cloud.google.com/go/auth v0.17.0 // indirect
1818
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
19+
cloud.google.com/go/cloudtasks v1.13.7 // indirect
1920
cloud.google.com/go/compute/metadata v0.9.0 // indirect
21+
cloud.google.com/go/datastore v1.21.0 // indirect
2022
cloud.google.com/go/iam v1.5.3 // indirect
23+
cloud.google.com/go/logging v1.13.1 // indirect
24+
cloud.google.com/go/longrunning v0.7.0 // indirect
2125
cloud.google.com/go/monitoring v1.24.3 // indirect
2226
cloud.google.com/go/pubsub/v2 v2.0.0 // indirect
27+
cloud.google.com/go/secretmanager v1.16.0 // indirect
2328
cloud.google.com/go/spanner v1.86.1 // indirect
2429
github.com/GoogleChrome/webstatus.dev/lib/gen v0.0.0-20251119220853-b545639c35ae // indirect
2530
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.3 // indirect
@@ -28,6 +33,7 @@ require (
2833
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
2934
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3035
github.com/cncf/xds/go v0.0.0-20251110193048-8bfbf64dc13e // indirect
36+
github.com/deckarep/golang-set v1.8.0 // indirect
3137
github.com/envoyproxy/go-control-plane/envoy v1.36.0 // indirect
3238
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
3339
github.com/felixge/httpsnoop v1.0.4 // indirect
@@ -38,10 +44,16 @@ require (
3844
github.com/go-openapi/jsonpointer v0.22.3 // indirect
3945
github.com/go-openapi/swag/jsonname v0.25.3 // indirect
4046
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
47+
github.com/gomodule/redigo v1.9.3 // indirect
48+
github.com/google/go-github/v77 v77.0.0 // indirect
49+
github.com/google/go-querystring v1.1.0 // indirect
4150
github.com/google/s2a-go v0.1.9 // indirect
4251
github.com/google/uuid v1.6.0 // indirect
4352
github.com/googleapis/enterprise-certificate-proxy v0.3.7 // indirect
4453
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
54+
github.com/gorilla/handlers v1.5.2 // indirect
55+
github.com/gorilla/mux v1.8.1 // indirect
56+
github.com/gorilla/securecookie v1.1.2 // indirect
4557
github.com/josharian/intern v1.0.0 // indirect
4658
github.com/mailru/easyjson v0.9.1 // indirect
4759
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
@@ -50,7 +62,9 @@ require (
5062
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
5163
github.com/perimeterx/marshmallow v1.1.5 // indirect
5264
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
65+
github.com/sirupsen/logrus v1.9.3 // indirect
5366
github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect
67+
github.com/web-platform-tests/wpt.fyi v0.0.0-20251118162843-54f805c8a632 // indirect
5468
github.com/woodsbury/decimal128 v1.4.0 // indirect
5569
go.opencensus.io v0.24.0 // indirect
5670
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
@@ -76,4 +90,5 @@ require (
7690
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba // indirect
7791
google.golang.org/grpc v1.77.0 // indirect
7892
google.golang.org/protobuf v1.36.10 // indirect
93+
gopkg.in/yaml.v3 v3.0.1 // indirect
7994
)

workers/email/go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,8 @@ github.com/google/go-github/v77 v77.0.0 h1:9DsKKbZqil5y/4Z9mNpZDQnpli6PJbqipSuuN
842842
github.com/google/go-github/v77 v77.0.0/go.mod h1:c8VmGXRUmaZUqbctUcGEDWYnMrtzZfJhDSylEf1wfmA=
843843
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
844844
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
845+
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
846+
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
845847
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
846848
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
847849
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -973,6 +975,8 @@ github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJw
973975
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
974976
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
975977
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
978+
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI=
979+
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
976980
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
977981
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
978982
github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
@@ -1083,6 +1087,8 @@ go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42s
10831087
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
10841088
go.opentelemetry.io/proto/otlp v0.15.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U=
10851089
go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U=
1090+
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
1091+
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
10861092
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
10871093
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
10881094
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -1328,6 +1334,7 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
13281334
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13291335
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13301336
golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1337+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13311338
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13321339
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13331340
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

workers/email/manifests/pod.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ spec:
3636
value: 'pubsub:8060'
3737
- name: EMAIL_SUBSCRIPTION_ID
3838
value: 'chime-delivery-sub-id'
39+
- name: FRONTEND_BASE_URL
40+
value: 'http://localhost:5555'
3941
resources:
4042
limits:
4143
cpu: 250m

0 commit comments

Comments
 (0)