Downtime protection
How the Builder protects you from downtime
The Builder is actually pretty simple: it clones or updates a local copy of your repository at the commit that was the HEAD in the webhook delivery. Then it runs a few tasks in a specific order. Every task is revertable and has to clean up its own mess on error. They all have a run, revert and finalize method. When a task fails, every task up to that point will be reverted.
run: run the task logic in a non-destructive manner. Create.tmpor.bakfiles/directories.revert: undo everything that has been done inrun.finalize: complete therunmethod. Remove all backups or rename.tmpfiles to their definitive name.
Examples
The Builder has the following tasks:
Task1Task2Task3
The Builder cloned your repo, now it runs the tasks.
Normal flow:
Task1.run()âĄī¸ âī¸Task2.run()âĄī¸ âī¸Task3.run()âĄī¸ âī¸Task1.finalize()Task2.finalize()Task3.finalize()- Done, built successfully!
Scenario with a crashing task:
Task1.run()âĄī¸ âī¸Task2.run()âĄī¸ âī¸Task3.run()âĄī¸ âTask3manually reverts everything that has to be reverted up to the point of error.Task1.revert()Task2.revert()- Done, build failed.
âšī¸ Notes
All Tasks also define a
needsToRungetter. This can returntrueto indicate the Task'srunmethod has to be called, or returnfalseto skip this task. However, it can also decide to crash the build intentionally, for example when something absolutely crucial is missing and the build should be canceled right away.revertandfinalizemethods can NOT crash, they just can't, because you can't revert after you've already started reverting or finalizing. If you're writing new Tasks or modifying existing ones, do everything you can to prevent errors, and log to Slack whenever a errorous or suspicious scenario occurs.