Add context
This commit adds and passes context around to (almost) every function. This allows cancelling (almost) every function call globally.
This commit is contained in:
parent
996ecb9f80
commit
3455f491ca
104 changed files with 836 additions and 511 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package drush
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/meta"
|
||||
|
|
@ -18,8 +19,8 @@ var errBlindUpdateFailed = exit.Error{
|
|||
}
|
||||
|
||||
// Update performs a blind drush update
|
||||
func (drush *Drush) Update(io stream.IOStream) error {
|
||||
code, err := drush.Barrel.Shell(io, "/runtime/blind_update.sh")
|
||||
func (drush *Drush) Update(ctx context.Context, io stream.IOStream) error {
|
||||
code, err := drush.Barrel.Shell(ctx, io, "/runtime/blind_update.sh")
|
||||
if err != nil {
|
||||
return errBlindUpdateFailed.WithMessageF(drush.Slug, environment.ExecCommandError)
|
||||
}
|
||||
|
|
@ -27,13 +28,13 @@ func (drush *Drush) Update(io stream.IOStream) error {
|
|||
return errBlindUpdateFailed.WithMessageF(drush.Slug, code)
|
||||
}
|
||||
|
||||
return drush.setLastUpdate()
|
||||
return drush.setLastUpdate(ctx)
|
||||
}
|
||||
|
||||
const lastUpdate = mstore.For[int64]("lastUpdate")
|
||||
|
||||
func (drush *Drush) LastUpdate() (t time.Time, err error) {
|
||||
epoch, err := lastUpdate.Get(drush.MStore)
|
||||
func (drush *Drush) LastUpdate(ctx context.Context) (t time.Time, err error) {
|
||||
epoch, err := lastUpdate.Get(ctx, drush.MStore)
|
||||
if err == meta.ErrMetadatumNotSet {
|
||||
return t, nil
|
||||
}
|
||||
|
|
@ -45,8 +46,8 @@ func (drush *Drush) LastUpdate() (t time.Time, err error) {
|
|||
return time.Unix(epoch, 0), nil
|
||||
}
|
||||
|
||||
func (drush *Drush) setLastUpdate() error {
|
||||
return lastUpdate.Set(drush.MStore, time.Now().Unix())
|
||||
func (drush *Drush) setLastUpdate(ctx context.Context) error {
|
||||
return lastUpdate.Set(ctx, drush.MStore, time.Now().Unix())
|
||||
}
|
||||
|
||||
type LastUpdateFetcher struct {
|
||||
|
|
@ -56,6 +57,6 @@ type LastUpdateFetcher struct {
|
|||
}
|
||||
|
||||
func (lbr *LastUpdateFetcher) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.LastUpdate, err = lbr.Drush.LastUpdate()
|
||||
info.LastUpdate, err = lbr.Drush.LastUpdate(flags.Context)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue