本文整理汇总了Golang中github.com/snapcore/snapd/overlord/state.State.EnsureBefore方法的典型用法代码示例。如果您正苦于以下问题:Golang State.EnsureBefore方法的具体用法?Golang State.EnsureBefore怎么用?Golang State.EnsureBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/snapcore/snapd/overlord/state.State
的用法示例。
在下文中一共展示了State.EnsureBefore方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newRunnerManager
func newRunnerManager(s *state.State) *runnerManager {
rm := &runnerManager{
runner: state.NewTaskRunner(s),
}
rm.runner.AddHandler("runMgr1", func(t *state.Task, _ *tomb.Tomb) error {
s := t.State()
s.Lock()
defer s.Unlock()
s.Set("runMgr1Mark", 1)
return nil
}, nil)
rm.runner.AddHandler("runMgr2", func(t *state.Task, _ *tomb.Tomb) error {
s := t.State()
s.Lock()
defer s.Unlock()
s.Set("runMgr2Mark", 1)
return nil
}, nil)
rm.runner.AddHandler("runMgrEnsureBefore", func(t *state.Task, _ *tomb.Tomb) error {
s := t.State()
s.Lock()
defer s.Unlock()
s.EnsureBefore(20 * time.Millisecond)
return nil
}, nil)
return rm
}
示例2: UpdateBootRevisions
// UpdateBootRevisions synchronizes the active kernel and OS snap versions
// with the versions that actually booted. This is needed because a
// system may install "os=v2" but that fails to boot. The bootloader
// fallback logic will revert to "os=v1" but on the filesystem snappy
// still has the "active" version set to "v2" which is
// misleading. This code will check what kernel/os booted and set
// those versions active.To do this it creates a Change and kicks
// start it directly.
func UpdateBootRevisions(st *state.State) error {
const errorPrefix = "cannot update revisions after boot changes: "
if release.OnClassic {
return nil
}
bootloader, err := partition.FindBootloader()
if err != nil {
return fmt.Errorf(errorPrefix+"%s", err)
}
m, err := bootloader.GetBootVars("snap_kernel", "snap_core")
if err != nil {
return fmt.Errorf(errorPrefix+"%s", err)
}
var tsAll []*state.TaskSet
for _, snapNameAndRevno := range []string{m["snap_kernel"], m["snap_core"]} {
name, rev, err := nameAndRevnoFromSnap(snapNameAndRevno)
if err != nil {
logger.Noticef("cannot parse %q: %s", snapNameAndRevno, err)
continue
}
info, err := CurrentInfo(st, name)
if err != nil {
logger.Noticef("cannot get info for %q: %s", name, err)
continue
}
if rev != info.SideInfo.Revision {
// FIXME: check that there is no task
// for this already in progress
ts, err := RevertToRevision(st, name, rev, Flags{})
if err != nil {
return err
}
tsAll = append(tsAll, ts)
}
}
if len(tsAll) == 0 {
return nil
}
msg := fmt.Sprintf("Update kernel and core snap revisions")
chg := st.NewChange("update-revisions", msg)
for _, ts := range tsAll {
chg.AddAll(ts)
}
st.EnsureBefore(0)
return nil
}
示例3: ensureStateSoonImpl
func ensureStateSoonImpl(st *state.State) {
st.EnsureBefore(0)
}