engine: Add a ctx to the CheckApply API

This is just a rough port, there are lots of optimizations to be done
and lots of timeout values that should be replaced by a new timeout meta
param!
This commit is contained in:
James Shubin
2023-09-01 22:56:32 -04:00
parent 567de2e115
commit 7ccda7e99b
37 changed files with 175 additions and 120 deletions

View File

@@ -317,16 +317,16 @@ func (obj *CronRes) Watch(ctx context.Context) error {
// CheckApply is run to check the state and, if apply is true, to apply the
// necessary changes to reach the desired state. This is run before Watch and
// again if Watch finds a change occurring to the state.
func (obj *CronRes) CheckApply(apply bool) (bool, error) {
func (obj *CronRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
checkOK := true
// use the embedded file resource to apply the correct state
if c, err := obj.file.CheckApply(apply); err != nil {
if c, err := obj.file.CheckApply(ctx, apply); err != nil {
return false, errwrap.Wrapf(err, "nested file failed")
} else if !c {
checkOK = false
}
// check timer state and apply the defined state if needed
if c, err := obj.unitCheckApply(apply); err != nil {
if c, err := obj.unitCheckApply(ctx, apply); err != nil {
return false, errwrap.Wrapf(err, "unitCheckApply error")
} else if !c {
checkOK = false
@@ -336,7 +336,7 @@ func (obj *CronRes) CheckApply(apply bool) (bool, error) {
// unitCheckApply checks the state of the systemd-timer unit and, if apply is
// true, applies the defined state.
func (obj *CronRes) unitCheckApply(apply bool) (bool, error) {
func (obj *CronRes) unitCheckApply(ctx context.Context, apply bool) (bool, error) {
var conn *sdbus.Conn
var godbusConn *dbus.Conn
var err error
@@ -383,7 +383,7 @@ func (obj *CronRes) unitCheckApply(apply bool) (bool, error) {
}
// context for stopping/restarting the unit
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout*time.Second)
ctx, cancel := context.WithTimeout(ctx, ctxTimeout*time.Second)
defer cancel()
// godbus connection for stopping/restarting the unit