Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cmd/worker/aiscmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ func (m *Main) Run(ctx context.Context) error {
}
m.bucket = b

if err := ais.RegisterWorkflow(ctx, w, m.cfg, b); err != nil {
return fmt.Errorf("AIS: %w", err)
amssClient, err := ais.NewAMSSClient(m.cfg.AMSS)
if err != nil {
return fmt.Errorf("RegisterWorkflow: %w", err)
}

ais.RegisterWorkflow(w, m.cfg, amssClient)
ais.RegisterActivities(w, amssClient, m.bucket)

if err := w.Start(); err != nil {
m.logger.Error(err, "AIS worker failed to start.")
return err
Expand Down
31 changes: 13 additions & 18 deletions internal/ais/workflow.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ais

import (
"context"
"errors"
"fmt"
"path/filepath"
Expand Down Expand Up @@ -229,40 +228,36 @@ func (w *Workflow) SessionHandler(ctx temporalsdk_workflow.Context, aipUUID, aip
return uploadResult.Key, nil
}

func RegisterWorkflow(ctx context.Context, tw temporalsdk_worker.Worker, config Config, bucket *blob.Bucket) error {
amssclient, err := NewAMSSClient(config.AMSS)
if err != nil {
return fmt.Errorf("RegisterWorkflow: %w", err)
}

tw.RegisterWorkflowWithOptions(
NewWorkflow(config, amssclient).Execute,
func RegisterWorkflow(w temporalsdk_worker.Worker, config Config, amssClient *AMSSClient) {
w.RegisterWorkflowWithOptions(
NewWorkflow(config, amssClient).Execute,
temporalsdk_workflow.RegisterOptions{Name: config.Temporal.WorkflowName},
)
tw.RegisterActivityWithOptions(
NewFetchActivity(amssclient).Execute,
}

func RegisterActivities(r temporalsdk_worker.ActivityRegistry, amssClient *AMSSClient, bucket *blob.Bucket) {
r.RegisterActivityWithOptions(
NewFetchActivity(amssClient).Execute,
temporalsdk_activity.RegisterOptions{Name: FetchActivityName},
)
tw.RegisterActivityWithOptions(
r.RegisterActivityWithOptions(
NewParseActivity().Execute,
temporalsdk_activity.RegisterOptions{Name: ParseActivityName},
)
tw.RegisterActivityWithOptions(
r.RegisterActivityWithOptions(
NewCombineMDActivity().Execute,
temporalsdk_activity.RegisterOptions{Name: CombineMDActivityName},
)
tw.RegisterActivityWithOptions(
r.RegisterActivityWithOptions(
archivezip.New().Execute,
temporalsdk_activity.RegisterOptions{Name: archivezip.Name},
)
tw.RegisterActivityWithOptions(
r.RegisterActivityWithOptions(
bucketupload.New(bucket).Execute,
temporalsdk_activity.RegisterOptions{Name: bucketupload.Name},
)
tw.RegisterActivityWithOptions(
r.RegisterActivityWithOptions(
removepaths.New().Execute,
temporalsdk_activity.RegisterOptions{Name: removepaths.Name},
)

return nil
}
31 changes: 1 addition & 30 deletions internal/ais/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (

"github.com/artefactual-sdps/temporal-activities/archivezip"
"github.com/artefactual-sdps/temporal-activities/bucketupload"
"github.com/artefactual-sdps/temporal-activities/removepaths"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
temporalsdk_activity "go.temporal.io/sdk/activity"
temporalsdk_testsuite "go.temporal.io/sdk/testsuite"
temporalsdk_worker "go.temporal.io/sdk/worker"

Expand All @@ -32,38 +30,11 @@ func (s *TestSuite) setup(cfg *ais.Config) {
s.testDir = s.T().TempDir()
cfg.WorkingDir = s.testDir

s.registerActivities()
ais.RegisterActivities(s.env, nil, nil)

s.workflow = ais.NewWorkflow(*cfg, nil)
}

func (s *TestSuite) registerActivities() {
s.env.RegisterActivityWithOptions(
ais.NewFetchActivity(nil).Execute,
temporalsdk_activity.RegisterOptions{Name: ais.FetchActivityName},
)
s.env.RegisterActivityWithOptions(
ais.NewParseActivity().Execute,
temporalsdk_activity.RegisterOptions{Name: ais.ParseActivityName},
)
s.env.RegisterActivityWithOptions(
ais.NewCombineMDActivity().Execute,
temporalsdk_activity.RegisterOptions{Name: ais.CombineMDActivityName},
)
s.env.RegisterActivityWithOptions(
archivezip.New().Execute,
temporalsdk_activity.RegisterOptions{Name: archivezip.Name},
)
s.env.RegisterActivityWithOptions(
bucketupload.New(nil).Execute,
temporalsdk_activity.RegisterOptions{Name: bucketupload.Name},
)
s.env.RegisterActivityWithOptions(
removepaths.New().Execute,
temporalsdk_activity.RegisterOptions{Name: removepaths.Name},
)
}

func TestWorkflow(t *testing.T) {
suite.Run(t, new(TestSuite))
}
Expand Down
Loading