mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-03 17:38:51 +00:00
chore!: Introduce ZITADEL v3 (#9645)
This PR summarizes multiple changes specifically only available with ZITADEL v3: - feat: Web Keys management (https://github.com/zitadel/zitadel/pull/9526) - fix(cmd): ensure proper working of mirror (https://github.com/zitadel/zitadel/pull/9509) - feat(Authz): system user support for permission check v2 (https://github.com/zitadel/zitadel/pull/9640) - chore(license): change from Apache to AGPL (https://github.com/zitadel/zitadel/pull/9597) - feat(console): list v2 sessions (https://github.com/zitadel/zitadel/pull/9539) - fix(console): add loginV2 feature flag (https://github.com/zitadel/zitadel/pull/9682) - fix(feature flags): allow reading "own" flags (https://github.com/zitadel/zitadel/pull/9649) - feat(console): add Actions V2 UI (https://github.com/zitadel/zitadel/pull/9591) BREAKING CHANGE - feat(webkey): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9445) - chore!: remove CockroachDB Support (https://github.com/zitadel/zitadel/pull/9444) - feat(actions): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9489) --------- Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Stefan Benz <[email protected]> Co-authored-by: Silvan <[email protected]> Co-authored-by: Ramon <[email protected]> Co-authored-by: Elio Bischof <[email protected]> Co-authored-by: Kenta Yamaguchi <[email protected]> Co-authored-by: Harsha Reddy <[email protected]> Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Max Peintner <[email protected]> Co-authored-by: Iraq <[email protected]> Co-authored-by: Florian Forster <[email protected]> Co-authored-by: Tim Möhlmann <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Max Peintner <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
Stefan Benz
Silvan
Ramon
Elio Bischof
Kenta Yamaguchi
Harsha Reddy
Livio Spring
Max Peintner
Iraq
Florian Forster
Tim Möhlmann
Copilot
Max Peintner
parent
d14a23ae7e
commit
07ce3b6905
@@ -0,0 +1,90 @@
|
||||
package execution
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/riverqueue/river"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
exec_repo "github.com/zitadel/zitadel/internal/repository/execution"
|
||||
)
|
||||
|
||||
type Worker struct {
|
||||
river.WorkerDefaults[*exec_repo.Request]
|
||||
|
||||
config WorkerConfig
|
||||
now nowFunc
|
||||
}
|
||||
|
||||
// Timeout implements the Timeout-function of [river.Worker].
|
||||
// Maximum time a job can run before the context gets cancelled.
|
||||
// The time can be shorter than the sum of target timeouts, this is expected behavior to not block the request indefinitely.
|
||||
func (w *Worker) Timeout(*river.Job[*exec_repo.Request]) time.Duration {
|
||||
return w.config.TransactionDuration
|
||||
}
|
||||
|
||||
// Work implements [river.Worker].
|
||||
func (w *Worker) Work(ctx context.Context, job *river.Job[*exec_repo.Request]) error {
|
||||
ctx = ContextWithExecuter(ctx, job.Args.Aggregate)
|
||||
|
||||
// if the event is too old, we can directly return as it will be removed anyway
|
||||
if job.CreatedAt.Add(w.config.MaxTtl).Before(w.now()) {
|
||||
return river.JobCancel(errors.New("event is too old"))
|
||||
}
|
||||
|
||||
targets, err := TargetsFromRequest(job.Args)
|
||||
if err != nil {
|
||||
// If we are not able to get the targets from the request, we can cancel the job, as we have nothing to call
|
||||
return river.JobCancel(fmt.Errorf("unable to unmarshal targets because %w", err))
|
||||
}
|
||||
|
||||
_, err = CallTargets(ctx, targets, exec_repo.ContextInfoFromRequest(job.Args))
|
||||
if err != nil {
|
||||
// If there is an error returned from the targets, it means that the execution was interrupted
|
||||
return river.JobCancel(fmt.Errorf("interruption during call of targets because %w", err))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// nowFunc makes [time.Now] mockable
|
||||
type nowFunc func() time.Time
|
||||
|
||||
type WorkerConfig struct {
|
||||
Workers uint8
|
||||
TransactionDuration time.Duration
|
||||
MaxTtl time.Duration
|
||||
}
|
||||
|
||||
func NewWorker(
|
||||
config WorkerConfig,
|
||||
) *Worker {
|
||||
return &Worker{
|
||||
config: config,
|
||||
now: time.Now,
|
||||
}
|
||||
}
|
||||
|
||||
var _ river.Worker[*exec_repo.Request] = (*Worker)(nil)
|
||||
|
||||
func (w *Worker) Register(workers *river.Workers, queues map[string]river.QueueConfig) {
|
||||
river.AddWorker(workers, w)
|
||||
queues[exec_repo.QueueName] = river.QueueConfig{
|
||||
MaxWorkers: int(w.config.Workers),
|
||||
}
|
||||
}
|
||||
|
||||
func TargetsFromRequest(e *exec_repo.Request) ([]Target, error) {
|
||||
var execTargets []*query.ExecutionTarget
|
||||
if err := json.Unmarshal(e.TargetsData, &execTargets); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
targets := make([]Target, len(execTargets))
|
||||
for i, target := range execTargets {
|
||||
targets[i] = target
|
||||
}
|
||||
return targets, nil
|
||||
}
|
||||
Reference in New Issue
Block a user