https://github.com/hacknlove/meteor-primary
Primary / Secondary(s) cluster for Meteor
https://github.com/hacknlove/meteor-primary
Last synced: 6 months ago
JSON representation
Primary / Secondary(s) cluster for Meteor
- Host: GitHub
- URL: https://github.com/hacknlove/meteor-primary
- Owner: hacknlove
- Created: 2016-10-05T08:49:58.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-21T13:50:28.000Z (about 9 years ago)
- Last Synced: 2025-02-26T07:34:20.246Z (over 1 year ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Primary / Secondary(s) cluster for Meteor
### Important: All the server instances must share the mongo database.**
just add this package `meter add hacknlove:primary` and you'll get:
### `Primary.serverId`
Just a runtime uuid for the server set at startup.
Next startup, it will have a diferent value.
### `Primary.isPrimary` and `Primary.isSecondary`
During the startup they could be both false, until someone is choosen Primary, so use them only at runtime, not at startup time.
### `Primary.becomePrimary(callback)` and `Primary.becomeSecondary(callback)`
You can call those as many times as you want, attaching a new callback each time.
They returns a function that if called, dettaches callback.
When a new Primary is choosen:
* The Secondary that becomes Primary, calls becomePrimary callbacks.
* The Primary that becomess Secondary, calls becomeSecondary callbacks.
* The Secondaries that remains Secondaries, calls nothing.
The callbacks receive as parameter a callable that if called, dettaches the callback.
### How it works:
Every server insert himself in the HacknlovePrimary collection with a timestamp
The one with the oldest Timestamp becomes Primary.
Every hearthbeat, the servers update their timestamp.
The Primary set his timestamp in the future (Now + hearthbeat - 1), in order to remain Primary.
So it does not change every time a new server is added to the cluster, and we do not want the primary to change randomly in each hearthbeat.
The timestamp olders than `hearthbeat * 4` are cleaned.
---
# Disclaimer:
This package is still beta, and it is not ready for production, nevertheless I am using it in production, but at my own risk.