commercetools / commercetools-email-retry-processor

Scheduled service which allows to send emails asynchronously and retry on errors.
1 stars 1 forks source link
commercetools email hacktoberfest retry

commercetools-email-retry-processor

codecov

Typically run as a cron job to ensure that an e-mail is sent (and re-tried) asynchronously, in case of potential down time of an e-mail provider.

Prerequisites

Configuration

The configuration can be passed via environment variables or via a configuration file, as follows:

Configuration via environment variable:

Please set the following environment variable:

export CTP_PROJECT_CONFIG="{\"tenants\": [{\"projectKey\": \"<ctp project key>\",\"clientId\": \"<ctp project ID>\", \"clientSecret\": \"<ctp project client secret>\", \"endpointUrl\": \"<endpoint url>\", \"encryptionKey\" : \"<blowfish encryptionkey>\", \"processAll\" : <true|false>}]}"

Configuration via configuration file:

Please pass the path to the configuration file as argument to the "main" method

The configuration file should contain the following "JSON-SNIPPET".

 {
   "tenants": [
     {
             "projectKey": "<ctp project key>",
             "clientId": "<ctp project ID>",
             "clientSecret": "<ctp project client secret>",
             "endpointUrl": "<endpoint url>",
             "encryptionKey" : "<blowfish encryptionkey, which is used to encrypt the email object id before passing it the post request>",
             "processAll" : true|false <if true, all email objects (pending/error) are processed, otherwise only "pending" email objects will be processed (Default: false).>
           }
   ]
 }

Develop the application

Build the application and run tests

   ./gradlew clean build

Run the application

API endpoint

The API endpoint should cover the following steps:

  1. Fetch the current e-mail object by the given id (commercetools CustomObject UUID)
  2. After fetching it, send the e-mail and process the result in the following way:
    • If the e-mail delivery is successful
      • Delete the current e-mail object
      • Set the response Http status code to 200
    • If the e-mail delivery fails for a temporary reason (e.g. connection error, slow network, etc..)
      • Set the status of the e-mail CustomObject to pending
      • Set the response Http status code to 503
    • If the e-mail delivery fails for a permanent reason (e.g. wrong e-mail address, etc..)
      • Set the status of the e-mail CustomObject to error
      • Set the response Http status code to 400

Build and deploy