# Schedule production runs

This quickstart walks you through the following steps to schedule production
runs in Dataform:

- [Create a Dataform repository](https://docs.cloud.google.com/dataform/docs/quickstart-schedule-production-executions.md.txt#create-repository).
- [Grant the required roles](https://docs.cloud.google.com/dataform/docs/quickstart-schedule-production-executions.md.txt#grant-required-roles).
- [Create a release configuration and a workflow configuration](https://docs.cloud.google.com/dataform/docs/quickstart-schedule-production-executions.md.txt#create-release-workflow-config).

  Create a `production` release configuration and set the frequency of
  creating `production` compilation results. Then, create a `production`
  workflow configuration, select the `production` release configuration, and
  set a schedule for running `production` compilation results.
- [View past compilation results](https://docs.cloud.google.com/dataform/docs/quickstart-schedule-production-executions.md.txt#past-compilation-results).

- [View past runs](https://docs.cloud.google.com/dataform/docs/quickstart-schedule-production-executions.md.txt#past-executions).

- [Clean up created assets](https://docs.cloud.google.com/dataform/docs/quickstart-schedule-production-executions.md.txt#clean-up).

## Before you begin

<br />

Additionally, select or create a
[custom service account](https://docs.cloud.google.com/iam/docs/service-accounts-create.md.txt)
to run workflows in BigQuery.

### Required roles


To get the permissions that
you need to perform all tasks in this quickstart,

ask your administrator to grant you the
following IAM roles:

- [Dataform Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/dataform.md.txt#dataform.admin) (`roles/dataform.admin`) on the repository
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the custom service account
- [Project IAM Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/resourcemanager.md.txt#resourcemanager.projectIamAdmin) (`roles/resourcemanager.projectIamAdmin`) on the project


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

### Grant required roles

To run workflows in BigQuery, you can use a custom service
account or your Google Account
([Preview](https://cloud.google.com/products#product-launch-stages)).
However, custom service account credentials are the default option for scheduled
runs. Using Google Account user account credentials is discouraged for scheduled runs.

Your custom service account must have the following required roles:

- [BigQuery Data Editor](https://docs.cloud.google.com/bigquery/docs/access-control.md.txt#bigquery.dataEditor) (`roles/bigquery.dataEditor`) on projects or specific BigQuery datasets to which Dataform needs both read and write access. This usually includes the project hosting your Dataform repository.
- [BigQuery Data Viewer](https://docs.cloud.google.com/bigquery/docs/access-control.md.txt#bigquery.dataViewer) (`roles/bigquery.dataViewer`) on projects or specific BigQuery datasets to which Dataform needs read-only access.
- [BigQuery Job User](https://docs.cloud.google.com/bigquery/docs/access-control.md.txt#bigquery.jobUser) (`roles/bigquery.jobUser`) on the project hosting your Dataform repository.

To let Dataform use your custom service account, the default
Dataform service agent must have the following roles on the
custom service account resource:

- [Service Account Token Creator](https://docs.cloud.google.com/iam/docs/service-account-permissions.md.txt#token-creator-role) (`roles/iam.serviceAccountTokenCreator`)
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`)

To grant these roles, follow these steps:

1. In the Google Cloud console, go to the **IAM** page.

   [Go to IAM](https://console.cloud.google.com/iam-admin)
2. Click **Grant access**.

3. In the **New principals** field, enter your custom service account ID.

4. In the **Select a role** menu, select the following roles one by one, using
   **Add another role** for each additional role:

   - **BigQuery Data Editor**
   - **BigQuery Data Viewer**
   - **BigQuery Job User**
5. Click **Save**.

6. In the Google Cloud console, go to the **Service accounts** page.

   [Go to Service accounts](https://console.cloud.google.com/iam-admin/serviceaccounts)
7. Select your custom service account.

8. Go to **Principals with access** , and then click **Grant access**.

9. In the **New principals** field, enter your default Dataform
   service agent ID.

   Your default Dataform service agent ID is in the following
   format:

       service-PROJECT_NUMBER@gcp-sa-dataform.iam.gserviceaccount.com

   Replace `PROJECT_NUMBER` with the numeral ID of your
   Google Cloud project. You can find your Google Cloud project ID in the
   Google Cloud console dashboard. For more information, see
   [Find the project name, number, and ID](https://docs.cloud.google.com/resource-manager/docs/view-update-projects.md.txt#identifying_projects).
10. In the **Select a role** list, add the following roles:

    - **Service Account User**
    - **Service Account Token Creator**
11. Click **Save**.

For more information on granting roles, see
[Grant Dataform the required access](https://docs.cloud.google.com/dataform/docs/access-control.md.txt#grant-dataform-required-access).

## Create a Dataform repository

1. In the Google Cloud console, go to the **Dataform** page.

   [Go to Dataform](https://console.cloud.google.com/bigquery/dataform)
2. Click **Create repository**.

3. On the **Create repository** page, do the following:

   1. In the **Repository ID** field, enter `quickstart-production`.

   2. In the **Region** list, select `europe-west4`.

   3. In the **Service account** list, select a custom service account for the
      repository.

   4. In the **actAs permission checks** section, enforce the permission checks
      on user actions on the repository.

   5. Click **Create**.

4. Click **Go to repositories**.

## Create a release configuration and workflow configuration

To create production compilation results of the `quickstart-production`
repository and schedule a run of `production` tables, follow these steps:

1. In the Google Cloud console, go to the **Dataform** page.

   [Go to Dataform](https://console.cloud.google.com/bigquery/dataform)
2. Click `quickstart-production`.

3. Click **Releases \& scheduling** , then click **Create production release**.

4. In the **Create release configuration** pane, configure the following
   settings:

   1. In the **Release ID** field, enter `production`.
   2. In the **Git commitish** field, leave the default value `main`. This field accepts a Git branch, tag, or commit SHA.
   3. In the **Schedule frequency** section, in the **Repeats** menu, select **Custom**.
   4. In the **Custom schedule** field, enter `0 16 * * *`.
   5. In the **Timezone** menu, select a UTC+1 timezone, for example,
      **Central European Standard Time (CET)**.

      Every day at 4 PM UTC+1, Dataform compiles the
      `quickstart-production` repository and applies the compilation settings
      configured in this release configuration to create `production`
      compilation results.
5. Click **Create**.

   The `production` release configuration creates a compilation result of the
   entire `quickstart-production` repository every day at 4PM UTC+1.
6. Ensure that you're on the **Releases \& scheduling** tab. Go to the
   **Workflow configurations** section and click **Create**.

7. In the **Create workflow configuration** pane, configure the following
   settings:

   1. In the **Configuration ID** field, enter `production`.
   2. In the **Release configuration** menu, select `production`.
   3. In the **Schedule frequency** section, in the **Repeats** menu, select **Custom**.
   4. In the **Custom schedule** field, enter `0 17 * * *`.
   5. In the **Timezone** menu, select a UTC+1 timezone, for example,
      **Central European Standard Time (CET)**.

      Every day at 5PM UTC+1, Dataform runs the latest `production`
      compilation result of the `quickstart-production` repository.

      > [!IMPORTANT]
      > **Important:** To ensure that Dataform runs the latest compilation result in the corresponding release configuration, keep a minimum 1 hour break between the compilation result creation time and the scheduled run time.

   6. Click **All actions**.

      Dataform runs all the workflow actions in
      the `production` compilation result.
8. Click **Create**.

   The `production` workflow configuration runs the entire latest
   compilation result created by the production release configuration
   every day at 5PM UTC+1.

## View past `production` compilation results

To view past scheduled `production` compilation results, follow these steps:

1. In the Google Cloud console, go to the **Dataform** page.

   [Go to Dataform](https://console.cloud.google.com/bigquery/dataform)
2. Select the `quickstart-production` repository.

3. Click **Releases \& scheduling**.

4. In the **Release configurations** section, click `production`.

## View past `production` workflow runs

To view past `production` workflow runs, follow these steps:

1. In the Google Cloud console, go to the **Dataform** page.

   [Go to Dataform](https://console.cloud.google.com/bigquery/dataform)
2. Select the `quickstart-production` repository.

3. Click **Workflow Execution Logs**.

4. Select a workflow run to see more detailed information, including the status
   of each action and any logs.

## Clean up


To avoid incurring charges to your Google Cloud account for
the resources used on this page, follow these steps.

### Delete the dataset created in BigQuery

To avoid incurring charges for BigQuery assets, follow these
steps to delete the dataset called `dataform_production`:

1. In the Google Cloud console, go to the **BigQuery** page.

   [Go to BigQuery](https://console.cloud.google.com/bigquery)
2. In the **Explorer** panel, expand your project and select `dataform_production`.

3. Click the **Actions** menu, and then select
   **Delete**.

4. In the **Delete dataset** dialog, enter <kbd>delete</kbd>, and then click **Delete**.

### Delete the Dataform release configuration

There are no costs associated with creating Dataform release
configurations. However, if you want to delete the `production` release
configuration, follow these steps:

1. In the Google Cloud console, go to the **Dataform** page.

   [Go to Dataform](https://console.cloud.google.com/bigquery/dataform)
2. Click `quickstart-production`.

3. Click **Releases \& scheduling** , and go to the
   **Release configurations** section.

4. By the `production` release configuration, click the
   **More** menu, and then click **Delete**.

5. In the **Delete release configuration** dialog, click **Delete**.

### Delete the Dataform workflow configuration

To avoid incurring charges for BigQuery assets, follow these
steps to delete the Dataform `production` workflow configuration:

1. In the Google Cloud console, go to the **Dataform** page.

   [Go to Dataform](https://console.cloud.google.com/bigquery/dataform)
2. Click `quickstart-production`.

3. Click **Releases \& scheduling** , and go to the
   **Workflow configurations** section.

4. By the `production` workflow configuration, click the
   **More** menu, and then click **Delete**.

5. In the **Delete release configuration** dialog, click **Delete**.

### Delete the Dataform repository

There are no costs associated with creating Dataform repositories.
However, if you want to delete a repository and all its contents, follow these
steps:

1. In the Google Cloud console, go to the **Dataform** page.

   [Go to Dataform](https://console.cloud.google.com/bigquery/dataform)
2. By `quickstart-production`, click the **More** menu,
   and then select **Delete**.

3. In the **Delete repository** window, enter the name of the
   repository to confirm deletion.

4. To confirm, click **Delete**.

## What's next

- To learn more about service accounts, see [About custom service accounts and Dataform service agents](https://docs.cloud.google.com/dataform/docs/access-control.md.txt#about-service-accounts).
- To learn more about code lifecycle in Dataform, see [Introduction to code lifecycle in Dataform](https://docs.cloud.google.com/dataform/docs/configure-compilation.md.txt#intro-code-lifecycle).
- To learn more about best practices for the workflow lifecycle in Dataform, see [Best practices for the workflow lifecycle](https://docs.cloud.google.com/dataform/docs/managing-code-lifecycle.md.txt).
- To learn more about release configurations in Dataform, see [Create a release configuration](https://docs.cloud.google.com/dataform/docs/configure-compilation.md.txt#create-release-configuration).
- To learn more about workflow configurations in Dataform, see [Schedule runs with workflow configurations](https://docs.cloud.google.com/dataform/docs/schedule-runs.md.txt#workflow-configurations).