Skip to main content
Post Deploy Tasks
Matt Gray avatar
Written by Matt Gray
Updated over a year ago

When deploying changes to a Craft project, it's often the case that you'll want to do a few things after the new code has been deployed, such as...

  • Run any new migrations

  • Apply any project config changes

  • Clear some of Craft's caches

To help with this, Servd provides the option to run Post Deploy Tasks when a new bundle is selected and synced to an environment. If you haven't changed the bundle, and just perform a sync, then they won't be run.

These tasks can be either Craft console commands or `wget` HTTP requests.

Default Tasks

By default Servd, has the following tasks setup which will be run from top to bottom:

`./craft migrate/all --interactive=0`

`./craft project-config/sync --interactive=0`

`./craft clear-caches/compiled-templates --interactive=0`

`./craft clear-caches/cp-resources --interactive=0`

`./craft clear-caches/data --interactive=0`

Note the `--interactive=0` flag on each of the commands. If any of the commands opens a user prompt it will wait indefinitely and prevent the remaining tasks from completing.

Updating Tasks

To view and edit a project's Post Deploy Tasks, do the following:

  1. Navigate to the "Post Deploy Tasks" section in the project's Build & Deploy settings page.

  2. Edit or delete an existing task, or click the "Add Another" button to add more post deploy tasks.

  3. Click "Save".

  4. Select a new bundle to deploy in one of the project's environment settings pages.

  5. Perform a sync.

  6. The commands will be run after the new bundle is deployed. To view the logs, navigate to the project's Logs page and select "post-deploy-production" or "post-deploy-staging" from the filter dropdown.

Problems With Long Running Tasks

If your Post Deploy Tasks take too long to complete, you my see the following error:

`Deployment timed out after 600 seconds. Post deploy tasks may still be running.`

A common culprit is refreshing the Blitz cache.

After you've identified the long-running task, we recommend either attempting to optimise the command so it completes quicker, or remove it as a post deploy task and run it manually instead.

Did this answer your question?