solid-adventure / trivial-api

Other
1 stars 1 forks source link

Feature/new interval events #262

Closed vgkids closed 3 months ago

vgkids commented 4 months ago

Before There's no mechanism to trigger calendar-based charges, such as a monthly fee.

After There is a rake task available which pushes "period started" event into a Kafka stream. If this task is scheduled to run nightly, contract apps can be written to test the date and perform an action. A separate event is sent for each customer_id tag created for an app. This has the effect of allowing the same contract to be executed multiple times, once for each customer.

Usage rake tasks:send_new_period_started_events

Event keys are skewer-cased with the event name, separated by a period with the customer's id, like so:

new-period-started.194
new-period-started.2789
new-period-started.306

The event payload is as follows:

{
  "key": "period.started.194",
  "name": "period.started",
  "period":
  {
    "started_at": "2024-07-18T00:00:00Z"
  },
  "event_name": "period.started"
}

The period.started_at field is midnight UTC, formatted as ISO8601.