# Triggering a Sales Ingest

Ingesting a batch of sales data from StatementDB to Snowflake is done through the `sales_ingest` DAG.

The DAG is triggered by the `ingest_sales_{distro|nr}` Abacus event.

The Abacus event can be created with the `ows-abacus-event-create-ingest-sales-event` Jenkins job: https://scheduler.theorchard.io/job/ows-abacus-event-create-ingest-sales-event/

The Jenkins job takes the following parameters:

- `ENVIRONMENT` : This can be `qa` or `prod`
- `SALES_TYPE`: This can be `distro` or `nr`
    - If `distro` is selected, an `ingest_sales_distro` Abacus event will be created and the DAG will try to ingest sales from `sales_file_delivery.dig_sales_testfile_abacus` to `STMT_DB_SALES_DISTRO_STAGING`
    - If `nr` is selected, an `ingest_sales_nr` Abacus event will be created and the DAG will try to ingest sales from `sales_file_delivery.nr_sales_testfile_abacus` to `STMT_DB_SALES_NR_STAGING`
- `BATCH_ID` : The ID of the batch of sales to ingest. This should correspond to the `batch_id` column of the `{dig|nr}_sales_testfile_abacus` table.
    - **NOTE**: The `BATCH_ID` parameter needs to be an integer even though the `batch_id` column is a varchar.

The DAG run can be monitored from the Airflow UI which can be accessed from the AWS Console.

Once the DAG is finished the data should be available:

- In S3: `{qa|prod}-royalties-sales-file/extract-sales/{distro|nr}/{batch_id}`
- In Snowflake: `SELECT * FROM ROYALTY_ACCOUNTING.{QA|PROD}.STMT_DB_SALES_{DISTRO|NR}_STAGING WHERE BATCH_ID = '{batch_id}'`
