From the course: Node.js: Microservices

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Removing expired services

Removing expired services - Node.js Tutorial

From the course: Node.js: Microservices

Removing expired services

- [Instructor] Later services will register and unregister themselves, but there may be cases when a service just shuts down non-gracefully with no chance to unregister. Let's make it a rule that services need to send some kind of a heartbeat to reregister themselves continuously, and that the service that we haven't seen for some amount of time is considered to be expired. We already have everything to build this inner registry, services can update themselves and there is already a timeout property. So all that is left is to add one function that does the work. So I go into lib registry and there right on top, I will add a new method, cleanup. So the first thing we will do is we get the current term const now = Math.floor(new Date() ) and we divided by a thousand. This gives us the Unix timestamp in seconds. So that's the time since I think January 1st, 1970 in seconds. And if you remember, we also stored this…

Contents