Preflight Checks

Moya can alert you to potential problems in the project via preflight checks. These checks are code in a library which Moya can run for each application.

Running Preflight Checks

If enabled in project settings, Moya will run preflight checks prior to running the server. Any information from the preflight checks will be displayed in the console. You can also run preflight checks independently with the following command:

$ moya preflight

This will run all the preflight checks and display a table with a summary of the checks together with any error information.

Writing Preflight Checks

Preflight checks use the namespace http://moyaproject.com/preflight, which you will probably want to add to the root <moya> node. It is probably a good idea to gather all preflight checks in to a single file named preflight.xml.

When the preflight check process is run, Moya invokes the code in check tags within the library. A preflight check should call one of three tags depending on the result of the check; pass reports a pass (i.e. no problem detected), warning reports a potential issue, and fail reports a more serious problem (one which could result in broken links or data loss).

The following is an example of a preflight check that checks an application setting called discount is greater than or equal to 0:

<moya xmlns:preflight="http://moyaproject.com/preflight">
    <preflight:check>
        <preflight:fail if=".app.settings.discount.int gte 0">
            Discount percentage should be greater than or equal to zero!
        </preflight:fail>
    </preflight:check>
<moya>

The text in fail is used as the message in the logs, or table when ran from the command line.

If an unhandled exception occurs in a preflight check, it will be logged or reported in the preflight results.

Check Guidelines

Checks should be written to be quick, since they will run when starting the server in development mode. Most often they will validate initial settings or confirm that required objects in the database have been created. You can use all of the tags that you might use in a view, but bear in mind that there will be no .request value in the context since since preflight checks run prior to serving any requests.