Skip to content

Commit

Permalink
feat: Konnector worker honors skip-maintenance-for
Browse files Browse the repository at this point in the history
  The `harvest.skip-maintenance-for` flag can be set to a list of
  konnector slugs to unlock these in Harvest and allow requesting an
  execution even if it's maintenance mode has been activated either in
  the registry or cozy-stack.

  However, the flag was not honored in the konnector worker thus
  preventing its execution.
  We'll now check if the konnector to be executed is part of the list
  (if set) and skip the maintenance mode when appropriate.
  • Loading branch information
taratatach committed Feb 15, 2024
1 parent 446f57b commit afec83c
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions worker/exec/konnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/cozy/cozy-stack/model/account"
"github.com/cozy/cozy-stack/model/app"
"github.com/cozy/cozy-stack/model/feature"
"github.com/cozy/cozy-stack/model/instance"
"github.com/cozy/cozy-stack/model/instance/lifecycle"
"github.com/cozy/cozy-stack/model/job"
Expand Down Expand Up @@ -126,6 +127,21 @@ func beforeHookKonnector(j *job.Job) (bool, error) {

if err := json.Unmarshal(j.Message, &msg); err == nil {
slug = msg.Konnector

inst, err := lifecycle.GetInstance(j.DomainName())
if err != nil {
return false, err
}

flags, err := feature.GetFlags(inst)
if err != nil {
return false, err
}
skipMaintenance, err := flags.HasListItem("harvest.skip-maintenance-for", slug)
if err != nil {
return false, err
}

doc, err := app.GetMaintenanceOptions(slug)
if err != nil {
j.Logger().Warnf("konnector %q could not get local maintenance status", slug)
Expand All @@ -136,22 +152,31 @@ func beforeHookKonnector(j *job.Job) (bool, error) {
return true, nil
}
}
j.Logger().Infof("konnector %q has not been triggered because of its maintenance status", slug)
return false, nil
}
inst, err := lifecycle.GetInstance(j.DomainName())
if err != nil {
return false, err

if skipMaintenance {
j.Logger().Infof("skipping konnector %q's maintenance", slug)
return true, nil
} else {
j.Logger().Infof("konnector %q has not been triggered because of its maintenance status", slug)
return false, nil
}
}

app, err := registry.GetApplication(slug, inst.Registries())
if err != nil {
j.Logger().Warnf("konnector %q could not get application to fetch maintenance status", slug)
} else if app.MaintenanceActivated {
if j.Manual && !app.MaintenanceOptions.FlagDisallowManualExec {
return true, nil
}
j.Logger().Infof("konnector %q has not been triggered because of its maintenance status", slug)
return false, nil

if skipMaintenance {
j.Logger().Infof("skipping konnector %q's maintenance", slug)
return true, nil
} else {
j.Logger().Infof("konnector %q has not been triggered because of its maintenance status", slug)
return false, nil
}
}

if msg.BIWebhook {
Expand Down

0 comments on commit afec83c

Please sign in to comment.