# Sales Sheets Daemon #

An SQS queue reader daemon, that executes generating of pdf files over wkhtmltopdf lib and uploads it to the S3 bucket.

## Installation
First of all you have to install wkhtmltopdf library:

```
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
tar xvf wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
sudo mv wkhtmltox /libs/
export PATH=$PATH:/libs/wkhtmltox/bin
```

or you can use homebrew:

```
brew cask install wkhtmltopdf
```

Then you should create virtual environment and install all requirements:
```
python3.13 -m venv env
source env/bin/activate
pip3.13 install -r requirements.txt
pip3.13 install -r requirements-dev.txt
```

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

Variable | Description | Default
-------- | ----------- | -------
Environment | (dev, test, qa, prod) | dev
AR_MYSQL_DATABASE | Database that will be used for taking info about salesshets |
AR_MYSQL_HOST | Host of database |
AR_MYSQL_PASSWORD | Password of database user |
AR_MYSQL_PORT | Port of database |
AR_MYSQL_USER | Username of database user |
SS_MYSQL_DATABASE | Database that will be used for storing history of salessheets generating|
SS_MYSQL_HOST | Host of history database |
SS_MYSQL_PASSWORD | Password of history database user |
SS_MYSQL_PORT | Port of history database |
SS_MYSQL_USER | Username of history database user |
AWS_REGION | Amazon region | us-east-1
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 |
IMAGE_BASE_URL | URL for server with images for Sales Sheets releases. | https://images.qaorch.com
QUEUE_READER_THREADS | (optional) Number of workers to pick the messages from SQS. | 1

### Amazon S3 config:
According to Tech Design, application uses bucket named in format `{env}-orcdbucket` where `env` is the current environment name.
All pdf files after generating will be uploaded to bucket by this key: `sales-sheets/{product_id}.pdf` where `product_id` is id of product for which pdf was generated.

### Amazon SQS config:
According to Tech Design, application uses queue named in format `{env}-sales_sheets_generation` where `env` is the current environment name.

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

### Running The Sales Sheets service
```
python main.py
```

## Docker Development

### Create the image
```bash
docker build -t salessheets .
```

### Run the container, and mount the repo

```bash
docker run -it --volume /Users/username/Code/daemon-sales-sheets:/reporoot salessheets /bin/bash
```

Go to /reporoot
```bash
cd /reporoot
```

Install dependencies
```bash
make pip_dev
```

### Develop

You can load your local checkout files into an IDE and make changes to the repo, and they will be reflected in the Docker container in /reporoot.