# export-catalog-task UAT

## Background
In order to run the `export_catalog_task` fargate task, you need a valid `TASK_TOKEN`.
This project contains a script ([setup.py](./setup.py)) to upload assets using `ows-product-staging` endpoints
to get a valid `TASK_TOKEN`.


### Why do we need a valid token?
`/task-success/` and `/task-failure/` on qa-ows-product-staging return 500 because the task token doesn't exist in Redis. 
The task model expects a Redis entry keyed by the token before those endpoints can be called.

## What `setup.py` does

Creates the necessary Redis task entry by walking through the full bulk session upload flow, ending with `POST /assets/upload/google`. That final call creates a task record in Redis and kicks off a Fargate task with the token as `TASK_TOKEN`.

Steps:
1. Create a bulk session
2. Create a metadata upload record
3. Get a presigned S3 URL
4. Upload `bulk_upload_good_25824.xlsx` to S3
5. Complete the multipart upload
6. Finalize the metadata file (parses xlsx → JSON, creates asset records)
7. Mark the metadata file as valid (`PATCH /bulk-session/{id}` with `success_file`)
8. Start a Google asset transfer job (creates the Redis task entry)

## Usage

Add your auth token to a `.env` file:

```dotenv
AUTH_TOKEN=your-token-here
```

Then set up the environment and run:

```bash
make env
./env/bin/python setup.py
```

To reset the environment:

```bash
make clean && make env
```


## DD Logs
Search the APM for `google-drive-asset-transfer` traces to find a request that has 
the `TASK_TOKEN`.

[env:qa operation_name:http.request service:google-drive-asset-transfer @span.kind:client](https://sonymusic-pde.datadoghq.com/apm/traces?query=env%3Aqa%20operation_name%3Ahttp.request%20service%3Agoogle-drive-asset-transfer%20%40span.kind%3Aclient&agg_m=count&agg_m_source=base&agg_t=count&cols=core_service%2Ccore_resource_name%2Clog_duration%2Clog_http.method%2Clog_http.status_code&fromUser=false&graphType=waterfall&historicalData=false&messageDisplay=inline&query_translation_version=v0&shouldShowLegend=true&sort=desc&spanType=all&spanViewType=logs&storage=hot&traceQuery=&view=spans&start=1773680893478&end=1773681793478&paused=false)

After it completes, retrieve the `TASK_TOKEN` from the ECS task logs and use it to test:

- `POST /task-success/{token}`
- `POST /task-failure/{token}`


![dd_trace](./google-drive-asset-transfer__dd_trace.png)

# Now use the token

Now update `.env` to include the token that you found. In this case, our token was `<task-token>`.

```dotenv
ENVIRONMENT=qa

# Headers for GraphQL interactions
OA_USER=oa:101

# Fargate variables and parameters
TASK_TOKEN="<task-token>"
VENDOR_ID="<vendor-id>"
SUBACCOUNT_ID=

# Identity details
IDENTITY_ID="<identity-id>"
PROFILE_TYPE="ContentProfile"
PROFILE_ID="<profile-id>"
```
