(stopCh <-chan struct{}, finishCh chan struct{})
| 31 | ) |
| 32 | |
| 33 | func (f *Funclet) RecycleTask(stopCh <-chan struct{}, finishCh chan struct{}) { |
| 34 | ticker := time.NewTicker(30 * time.Second) |
| 35 | defer ticker.Stop() |
| 36 | for { |
| 37 | select { |
| 38 | case <-stopCh: |
| 39 | f.logger.Infof("funclet stopped") |
| 40 | // graceful exit task |
| 41 | // ... |
| 42 | list, _ := f.RuntimeClient.ListContainers() |
| 43 | for _, container := range list { |
| 44 | ID := container.ID |
| 45 | f.RuntimeClient.ThawContainer(ID) |
| 46 | } |
| 47 | return |
| 48 | case <-ticker.C: |
| 49 | taskID := id.GetTaskID() |
| 50 | taskLogger := f.logger.WithField("task-id", taskID) |
| 51 | taskLogger.Infof("start recycle task") |
| 52 | defer taskLogger.Infof("finish recycle task") |
| 53 | if err := f.tmpRecycleTask(taskLogger); err != nil { |
| 54 | taskLogger.Errorf("tmp recycle task failed: %s", err) |
| 55 | } |
| 56 | // other recycle task |
| 57 | // ... |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func (f *Funclet) tmpRecycleTask(tlog *logs.Logger) (err error) { |
| 63 | tlog.Infof("[tmp recycle task] start task") |
no test coverage detected