ЕСОЗ - публічна документація

RC_Rx_SMS timeout procedure

Purpose

This procedure is designed for using timeout in resending SMS flow.

Key Point

  • In order to remove expired attempts records are saving in redis db with expire parameter.

Input Parameters

  • MAX_ATTEMPTS_COUNT - specifies the maximum number of retries before resend is rejected

  • SEND_TIMEOUT -specifies a number of seconds to wait to retry sending after an error condition (attempts.count() >= MAX_ATTEMPTS_COUNT)

  • entity_name - i.e. “medication_request”

  • entity_id - i.e. medication_request_id

Logic

  1. Get array with all attempts which start with “{entity_name}:{entity_id}” from from redis db using script:

    [redis] KEYS $"{entity_name}:{entity_id}_*"
  2. Get attempts.count();

  3. If attempts.count() < MAX_ATTEMPTS_COUNT

    • generate attempt_id using structure: {entity_name}:{entity_id}_{datetime.now()},
      (i.e. "medication_request:b075f148-7f93-4fc2-b2ec-2d81b19a9b7_2022-12-22T10:30:45.255687")

    • save attempt to redis db using attempt_id as key and datetime.now() as value using script:

      [redis] set attempt_id $"{datetime.now()}"
    • set timeout to attempt with SEND_TIMEOUT parameter using script:

      [redis] expire key SEND_TIMEOUT
    • return 200 (ok)20

  4. Else (attempts.count() >= MAX_ATTEMPTS_COUNT)

    • do not save attempt

    • return error 429 ("Sending SMS timeout. Try later. Next attempt will be available at <attempts.oldest.value + SEND_TIMEOUT>")

 

ЕСОЗ - публічна документація