# Loyalty - scheduled tasks ### Dynamo table keys `uuid` = random gen `expires_at` = timestamp `task` = JSON object ### Task object ``` { task_type: "expire_reward"|"validate_reward"|"validate_credit", item_id: reward or credit id } ``` ### API scenarios * loyalty-service `/task` private endpoint handles list of task objects * `item_type` == "validate" => looks up reward/credit by id, checks if it's in a pending state. If so, gets order info from admin and updates the reward/credit to either `STATE_REDEEMED` (for reward) or `STATE_VOIDED` or `STATE_EARNED` (for credit) * `item_type` == "expire" => looks up reward/credit by the id and sets state to `STATE_EXPIRED` ### Failures / edge cases * request to loyalty-service fails => worker recreates the task in the db with new TTL of 30(?) minutes. * loyalty-service fails during processing: * reward/credit not found => do nothing * order not found => void the credit * API call for order lookup fails => recreate the task in the db with new TTL of 30(?) minutes * API call for order lookup shows that the order is still processing => recreate the task in the db with new TTL of 12(?) hours.