Skip to content

Commit 824bf8c

Browse files
committed
feat: write hash of actions to the worker
1 parent 48df8e5 commit 824bf8c

6 files changed

Lines changed: 51 additions & 13 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
ALTER TABLE "Worker" ADD COLUMN "actionsHash" BYTEA;
4+
-- +goose StatementEnd
5+
6+
-- +goose Down
7+
-- +goose StatementBegin
8+
ALTER TABLE "Worker" DROP COLUMN "actionsHash";
9+
-- +goose StatementEnd

pkg/repository/sqlcv1/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/repository/sqlcv1/workers.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ INSERT INTO "Worker" (
434434
"language",
435435
"languageVersion",
436436
"os",
437-
"runtimeExtra"
437+
"runtimeExtra",
438+
"actionsHash"
438439
) VALUES (
439440
gen_random_uuid(),
440441
CURRENT_TIMESTAMP,
@@ -447,7 +448,8 @@ INSERT INTO "Worker" (
447448
sqlc.narg('language')::"WorkerSDKS",
448449
sqlc.narg('languageVersion')::text,
449450
sqlc.narg('os')::text,
450-
sqlc.narg('runtimeExtra')::text
451+
sqlc.narg('runtimeExtra')::text,
452+
@actionsHash::bytea
451453
) RETURNING *;
452454

453455
-- name: LinkServicesToWorker :exec

pkg/repository/sqlcv1/workers.sql.go

Lines changed: 24 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/repository/worker.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package repository
22

33
import (
44
"context"
5+
"crypto/sha256"
56
"errors"
67
"fmt"
78
"time"
@@ -392,6 +393,16 @@ func (w *workerRepository) GetWorkerForEngine(ctx context.Context, tenantId uuid
392393
})
393394
}
394395

396+
func hashActions(actions []string) []byte {
397+
h := sha256.New()
398+
399+
for _, action := range actions {
400+
h.Write([]byte(action))
401+
}
402+
403+
return h.Sum(nil)
404+
}
405+
395406
func (w *workerRepository) CreateNewWorker(ctx context.Context, tenantId uuid.UUID, opts *CreateWorkerOpts) (*sqlcv1.Worker, error) {
396407
preWorker, postWorker := w.m.Meter(ctx, sqlcv1.LimitResourceWORKER, tenantId, 1)
397408

@@ -428,6 +439,7 @@ func (w *workerRepository) CreateNewWorker(ctx context.Context, tenantId uuid.UU
428439
Tenantid: tenantId,
429440
Dispatcherid: opts.DispatcherId,
430441
Name: opts.Name,
442+
Actionshash: hashActions(opts.Actions),
431443
}
432444

433445
// Default to self hosted

sql/schema/v0.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ CREATE TABLE "Worker" (
864864
"runtimeExtra" TEXT,
865865
"sdkVersion" TEXT,
866866
"durableTaskDispatcherId" UUID,
867+
"actionsHash" BYTEA,
867868

868869
CONSTRAINT "Worker_pkey" PRIMARY KEY ("id")
869870
);

0 commit comments

Comments
 (0)