上QQ阅读APP看书,第一时间看更新
Preparing a task
It all starts with defining exactly what task needs to be run, and designing it in a way that doesn't require human intervention to run.
Some ideal characteristic points are as follows:
- Single, clear entry point: No confusion on what the task to run is.
- Clear parameters: If there are any parameters, they should be very explicit.
- No interactivity: Stopping the execution to request information from the user is not possible.
- The result should be stored: To be able to be checked at a different time than when it runs.
- Clear result: If we are working interactively in a result, we accept more verbose results, or progress reports. But, for an automated task, the final result should be as concise and to the point as possible.
- Errors should be logged: To analyze what went wrong.
A command-line program has a lot of those characteristics already. It has a clear way of running, with defined parameters, and the result can be stored, even if just in text format. But, it can be improved with a config file to clarify the parameters, and an output file.
Note that point 6 is the objective of the Capturing errors and problems recipe, and will be covered there.
To avoid interactivity, do not use any command that stops for the user to input, like input. Remember to delete breakpoints for debugging!