# YouTube Ownership Update Daemon #

An SQS queue reader daemon, that executes ownership update requests over the YouTube API.

## Installation
```
python3.6 -m venv env
source env/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
```

### Environment:
The following environment variables should be set:

Variable | Description | Default
-------- | ----------- | -------
Environment | (dev, test, qa, prod) | dev
DB_CONNECTION_STRING | Connection string to yt_ownership RDS instance |
TRACK_SUCCESSES | Should be set to 1 in order to track both successful and failed YouTube API calls. | 0
AWS_REGION | Amazon region | us-east
AWS_ACCESS_KEY_ID | Amazon Access Key ID |
AWS_SECRET_ACCESS_KEY | Amazon Secret Access Key |
SENTRY_DSN | DSN for Sentry service |
LOGGER_DSN | DSN for Loggly |
QUEUE_READER_THREADS | (optional) Number of workers to pick the messages from SQS. | 1
API_EXECUTOR_THREADS | (optional) Number of workers to execute the YouTube API requests. | 6
API_RATE_LIMIT | Rate limit for requesting to Youtube API | 2

### Google API config:
Google API key in json format should be placed at the root project folder.
Key name format is `{ENV}_google_api_key.json`, where `ENV` is the current environment name.

### Test:
```
py.test --cov tests/
```

### Running The YouTube Ownership service
```
python main.py
```

### Running the Dockerfile

#### Authenticate
In order to pull down the base image to build containers, you need to authenticate with the AWS account using MFA, then register that login via docker app on your host machine.
* Authenticate to AWS account using [this process for MFA](https://github.com/theorchard/collab/tree/master/lvona/aws-creds-generator#aws-creds-generator-multi)
* Login to ECR so the base image can be fetched
```bash
$ aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 086679231553.dkr.ecr.us-east-1.amazonaws.com
```

#### Start Container
```
$ docker-compose up --build -d deploy
```

#### Linting and Testing
```
$ docker-compose up --build lint-and-test
```
