In this recipe, we will learn how to reconcile the state between the framework and Mesos.
Although our tasks persist after the framework restarts, they cannot be managed because the framework does not know about them. To make it aware of tasks it had scheduled previously, we need to keep them between restarts. We will do it in the same way as framework info. We will store the task state after every update and load it after registration.
Declare the global variable with the path to task state
file:
var stateFile = fmt.Sprintf("%s/%s", os.TempDir(), "state.json")
In the handle update
function, just after updating the task state, save it to the file:
stateJSON, _ := json.Marshal(tasksState) ioutil.WriteFile(stateFile, stateJSON, 0644)
We will load the previous state in the dedicated function and that should be called after the frameworkId
is stored in the framework info:
func reconcile() { oldState, err := ioutil.ReadFile(stateFile) if err == nil { ...