I'm planning to implement checkpointing to react to AWS Spot interruptions (which send a `SIGTERM`) in a Symfony application. I already implemented a listener for `console.signal` to log occurrences of such events, and `SignalableCommandInterface` on a specific Symfony command to log progress at interruption time for that command, and I was wondering if there was a library I should know about or a blog post I should read before implementing the checkpoint logic itself. What do you recommend? 🙂
@greg0ire I have already done the following code in the past:
```
switch($step) {
case 1:
a();
case 2:
b();
case 3:
c();
}
```
it's not sexy but it's efficient ;)
In PHP, another way to do is to use dynamic function name.
functions are named step_1, step_2, step_3,... and you can execute it using by assigning $step = "step_3"; then invoke it $step(); (then you increment a value to 4.)
@greg0ire using the second way, your invoke method should be :
```
public function __invoke($step = 1) {
while(!$isFinished) {
$currentStep = 'step_' . $step;
if (function_exists($$currentStep)) {
$currentStep();
$step++;
} else {
$isFinished = true;
}
}
}
```
that way if I want to declare a new step later I only need to declare a new function/method with the correct name.
@Vimar Oh yeah, I should definitely go with that rather than `goto`. 👍