-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b349844
commit d0a4e6b
Showing
13 changed files
with
1,833 additions
and
13 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,39 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/c4t-but-s4d/fastad/internal/checkers" | ||
"github.com/c4t-but-s4d/fastad/internal/logging" | ||
"github.com/sirupsen/logrus" | ||
"go.temporal.io/sdk/client" | ||
"go.temporal.io/sdk/worker" | ||
) | ||
|
||
func main() { | ||
logging.Init() | ||
|
||
temporalClient, err := client.Dial(client.Options{ | ||
HostPort: "localhost:7233", | ||
Logger: logging.NewTemporalAdapter( | ||
logrus.WithFields(logrus.Fields{ | ||
"component": "checkers_worker", | ||
}), | ||
), | ||
}) | ||
if err != nil { | ||
log.Fatalln("Unable to create client", err) | ||
} | ||
defer temporalClient.Close() | ||
|
||
checkersWorker := worker.New(temporalClient, "checkers", worker.Options{}) | ||
checkersWorker.RegisterWorkflow(checkers.WorkflowDefinition) | ||
|
||
checkersWorker.RegisterActivity(checkers.CheckActivityDefinition) | ||
checkersWorker.RegisterActivity(checkers.PutActivityDefinition) | ||
checkersWorker.RegisterActivity(checkers.GetActivityDefinition) | ||
|
||
if err := checkersWorker.Run(worker.InterruptCh()); err != nil { | ||
logrus.Fatalf("Unable to start workers: %v", err) | ||
} | ||
} |
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
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,37 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/c4t-but-s4d/fastad/internal/logging" | ||
"github.com/c4t-but-s4d/fastad/internal/ticker" | ||
"github.com/sirupsen/logrus" | ||
"go.temporal.io/sdk/client" | ||
) | ||
|
||
func main() { | ||
logging.Init() | ||
|
||
temporalClient, err := client.Dial(client.Options{ | ||
HostPort: "localhost:7233", | ||
Logger: logging.NewTemporalAdapter( | ||
logrus.WithFields(logrus.Fields{ | ||
"component": "ticker", | ||
}), | ||
), | ||
}) | ||
if err != nil { | ||
logrus.Fatalf("dialing temporal: %v", err) | ||
} | ||
defer temporalClient.Close() | ||
|
||
t := ticker.NewTicker(time.Second*10, temporalClient) | ||
|
||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) | ||
defer cancel() | ||
|
||
t.Run(ctx) | ||
} |
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
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,28 @@ | ||
package checkers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type CheckActivityParameters struct { | ||
Team string | ||
Service string | ||
} | ||
|
||
type CheckActivityResult struct { | ||
Success bool | ||
} | ||
|
||
func CheckActivityDefinition(ctx context.Context, params CheckActivityParameters) (*CheckActivityResult, error) { | ||
Check warning on line 19 in internal/checkers/activity_check.go GitHub Actions / lint-go
|
||
logrus.Infof("running check %s/%s", params.Team, params.Service) | ||
if params.Team == "team1" && params.Service == "service1" { | ||
return &CheckActivityResult{Success: true}, nil | ||
} | ||
if params.Team == "team2" && params.Service == "service1" { | ||
return &CheckActivityResult{Success: true}, nil | ||
} | ||
return nil, fmt.Errorf("unknown check %s/%s", params.Team, params.Service) | ||
Check failure on line 27 in internal/checkers/activity_check.go GitHub Actions / lint-go
|
||
} |
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,21 @@ | ||
package checkers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type GetActivityParameters struct { | ||
Team string | ||
Service string | ||
} | ||
|
||
type GetActivityResult struct { | ||
Success bool | ||
} | ||
|
||
func GetActivityDefinition(ctx context.Context, params GetActivityParameters) (*GetActivityResult, error) { | ||
Check warning on line 18 in internal/checkers/activity_get.go GitHub Actions / lint-go
|
||
logrus.Infof("running get %s/%s", params.Team, params.Service) | ||
return nil, nil | ||
} |
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,24 @@ | ||
package checkers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type LastActivityParameters struct { | ||
Team string | ||
Service string | ||
|
||
CheckResult *CheckActivityResult | ||
PutResults []*PutActivityResult | ||
GetResults []*GetActivityResult | ||
} | ||
|
||
func LastActivityDefinition(ctx context.Context, params LastActivityParameters) error { | ||
Check warning on line 18 in internal/checkers/activity_last.go GitHub Actions / lint-go
|
||
logrus.Infof("running last %s/%s", params.Team, params.Service) | ||
logrus.Infof("received check result: %v", params.CheckResult) | ||
logrus.Infof("received put results: %v", params.PutResults) | ||
logrus.Infof("received get results: %v", params.GetResults) | ||
return nil | ||
} |
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,21 @@ | ||
package checkers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type PutActivityParameters struct { | ||
Team string | ||
Service string | ||
} | ||
|
||
type PutActivityResult struct { | ||
Success bool | ||
} | ||
|
||
func PutActivityDefinition(ctx context.Context, params PutActivityParameters) (*PutActivityResult, error) { | ||
Check warning on line 18 in internal/checkers/activity_put.go GitHub Actions / lint-go
|
||
logrus.Infof("running put %s/%s", params.Team, params.Service) | ||
return nil, nil | ||
} |
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,138 @@ | ||
package checkers | ||
|
||
import ( | ||
"time" | ||
|
||
"go.temporal.io/sdk/workflow" | ||
) | ||
|
||
type WorkflowParameters struct { | ||
Teams []string | ||
Services []string | ||
} | ||
|
||
func WorkflowDefinition(ctx workflow.Context, params WorkflowParameters) error { | ||
logger := workflow.GetLogger(ctx) | ||
logger.Info("starting workflow") | ||
|
||
wg := workflow.NewWaitGroup(ctx) | ||
wg.Add(len(params.Teams) * len(params.Services)) | ||
for _, team := range params.Teams { | ||
for _, service := range params.Services { | ||
team := team | ||
service := service | ||
workflow.Go(ctx, func(ctx workflow.Context) { | ||
defer wg.Done() | ||
runCheckers(ctx, team, service) | ||
}) | ||
} | ||
} | ||
wg.Wait(ctx) | ||
|
||
return nil | ||
} | ||
|
||
func runCheckers(ctx workflow.Context, team string, service string) { | ||
logger := workflow.GetLogger(ctx) | ||
|
||
checkActivityOptions := workflow.ActivityOptions{ | ||
ScheduleToCloseTimeout: time.Second, | ||
} | ||
checkCtx := workflow.WithActivityOptions(ctx, checkActivityOptions) | ||
var checkResult *CheckActivityResult | ||
if err := workflow.ExecuteActivity(checkCtx, CheckActivityDefinition, CheckActivityParameters{ | ||
Team: team, | ||
Service: service, | ||
}).Get(ctx, &checkResult); err != nil { | ||
logger.Error("error in check", "team", team, "service", service, "error", err) | ||
return | ||
} | ||
|
||
if !checkResult.Success { | ||
logger.Info("check failed", "team", team, "service", service) | ||
return | ||
} | ||
|
||
putResultsChan := workflow.NewBufferedChannel(ctx, 3) | ||
|
||
putActivityOptions := workflow.ActivityOptions{ | ||
ScheduleToCloseTimeout: time.Second, | ||
} | ||
putCtx := workflow.WithActivityOptions(ctx, putActivityOptions) | ||
for i := 0; i < 3; i++ { | ||
workflow.Go(putCtx, func(ctx workflow.Context) { | ||
var putResult *PutActivityResult | ||
if err := workflow.ExecuteActivity( | ||
putCtx, | ||
PutActivityDefinition, | ||
PutActivityParameters{ | ||
Team: team, | ||
Service: service, | ||
}, | ||
); err != nil { | ||
logger.Error("error in put", "team", team, "service", service, "error", err) | ||
putResult = &PutActivityResult{Success: false} | ||
} | ||
putResultsChan.Send(ctx, putResult) | ||
}) | ||
} | ||
|
||
getResultsChan := workflow.NewBufferedChannel(ctx, 3) | ||
|
||
getActivityOptions := workflow.ActivityOptions{ | ||
ScheduleToCloseTimeout: time.Second, | ||
} | ||
getCtx := workflow.WithActivityOptions(ctx, getActivityOptions) | ||
for i := 0; i < 2; i++ { | ||
workflow.Go(getCtx, func(ctx workflow.Context) { | ||
var getResult *GetActivityResult | ||
if err := workflow.ExecuteActivity( | ||
getCtx, | ||
GetActivityDefinition, | ||
GetActivityParameters{ | ||
Team: team, | ||
Service: service, | ||
}, | ||
); err != nil { | ||
logger.Error("error in get", "team", team, "service", service, "error", err) | ||
getResult = &GetActivityResult{Success: false} | ||
} | ||
getResultsChan.Send(ctx, getResult) | ||
}) | ||
} | ||
|
||
putResults := make([]*PutActivityResult, 0, 3) | ||
for i := 0; i < 3; i++ { | ||
var putResult *PutActivityResult | ||
putResultsChan.Receive(ctx, &putResult) | ||
putResults = append(putResults, putResult) | ||
} | ||
|
||
getResults := make([]*GetActivityResult, 0, 2) | ||
for i := 0; i < 2; i++ { | ||
var getResult *GetActivityResult | ||
getResultsChan.Receive(ctx, &getResult) | ||
getResults = append(getResults, getResult) | ||
} | ||
|
||
lastActivityOptions := workflow.ActivityOptions{ | ||
ScheduleToCloseTimeout: time.Second, | ||
} | ||
lastCtx := workflow.WithActivityOptions(ctx, lastActivityOptions) | ||
if err := workflow.ExecuteActivity( | ||
lastCtx, | ||
LastActivityDefinition, | ||
LastActivityParameters{ | ||
Team: team, | ||
Service: service, | ||
|
||
CheckResult: checkResult, | ||
PutResults: putResults, | ||
GetResults: getResults, | ||
}, | ||
); err != nil { | ||
logger.Error("error in last", "team", team, "service", service, "error", err) | ||
} | ||
|
||
logger.Info("iteration finished", "team", team, "service", service) | ||
} |
Oops, something went wrong.