alphagov / trade-tariff-backend

Enabling the population and distribution via API of UK Customs tariffs and duties
MIT License
7 stars 6 forks source link

CircleCI Code Climate

Trade Tariff Backend

Now maintained at https://github.com/bitzesty/trade-tariff-backend

The API back-end for:

Other related projects:

Development

Dependencies

Setup

  1. Setup your environment.

    bin/setup

  2. Update .env file with valid data.

  3. Start Foreman.

    foreman start

  4. Verify that the app is up and running.

    open http://localhost:3018/healthcheck

Load database

Check out wiki article on the subject, or get a recent database snapshot.

Performing daily updates

These are run hourly by a background worker UpdatesSynchronizerWorker.

Sync process

Updates are performed in portions and protected by redis lock (see TariffSynchronizer#apply).

BaseUpdate#apply is responsible for most of the logging/checking job and running import! methods located in Taric/ChiefUpdate classes. Then it runs TaricImporter and ChiefImporter to parse and store xml/csv files.

Whole process is quite similar for both TARIC and CHIEF, but CHIEF updates undergo a tranformation transformation process to convert them into a TARIC format. Check ChiefTransformer class for more info (and ChiefUpdate#import!).

In case of any errors, changes (per single update) are roll-backed and record itself is marked as failed. The sync would need to be rerun after a rollback.

Deployment

We deploy to cloud foundry, so you need to have the CLI installed, and the following cf plugin installed:

Download the plugin for your os: https://github.com/contraband/autopilot/releases

chmod +x autopilot-(YOUR_OS)
cf install-plugin autopilot-(YOUR_OS)

Set the following ENV variables:

Then run

./bin/deploy

NB: In the newer Diego architecture from CloudFoundry, no-route skips creating and binding a route for the app, but does not specify which type of health check to perform. If your app does not listen on a port, for example the sidekiq worker, then it does not satisfy the port-based health check and Cloud Foundry marks it as crashed. To prevent this, disable the port-based health check with cf set-health-check APP_NAME none.

Notes

Contributing

Please check out the Contributing guide

Licence

Trade Tariff is licenced under the MIT licence