Vai al contenuto

Timer Service

The aim of Timer Service is to perform an action when a timer is expired. This allows to schedule a timeout for asynchrous actions that can fail without a notification of the called service.

Introduction

How does it works

Let's explain with an example.

You have a service named Payments that call an external API, named doPayment, with the following parameters:

  • orderId
  • amount
  • callback_url
  • timeout

Before calling doPayment API the Payments service schedules a timeout on Timer Service passing the following parameters:

  • output_mode → the details on the modality for the notification timeout (e.g. a fallback_url)
  • payload → a payload that will be sent into the timeout notification data
  • start_date → the date of start of the timer
  • expiration_interval_ms → the milliseconds that must pass from start_date for the timeout
  • applicant_service → the service who schedule the timer

for more details see usage.

The Payments service will wait for timeout seconds the result of doPayment on the callback_url. If Payments receives the callback before the expiration of the timeout, the service calls Timer Service abort (Figure 1).

Otherwise the Timer Service timeout occurs and Time Service calls the fallback_url to notify the expiration of the timeout (Figure 2).

alt_image

Figure 1 - Timer not expired - abort called



alt_image

Figure 2 - Timer expired - fallback_url called

Timer Service usage

The Timer Service can be used for more purposes, for example:

  • schedule a single action that must be executed after the timeout
  • send an alarm when a timeout is expired
  • monitor that an operation is completed in a predictable time
  • ...

Administration

Service Limitations

  • horizontal scaling: right now is not possible to horizontal scale the service because the service polls from the dedicated database and all instances would receive same pending timers
  • abort forgetfulness: the abort should be done just in case of pending timers but, right now, this check is missing (there is a dedicated section into the contributions file)
  • REST methods limit: the rest output allows just post, put or patch as REST Verbs, because it sends a payload; it would be nice to allow all the verbs and, in case of verbs without the body, ignore the payload (there is a dedicated section into the contributions file)

Further details

The Timer Service is easy to use and easy to configure: