@sec-block/secjs-circle
This libary used to sync the local time and ntp server time and caculate the working group number
Last updated 2 years ago by abysmli .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @sec-block/secjs-circle 
SYNC missed versions from official npm registry.

SECJSTimeCircle

js-standard-style

This libaray would be used to get the next working group, which shoud begin to work. This libary used dgram third-party libary to use udp protocoll, in case to send and get message from ntp server.

  • Using ntp server pool to uniform unix time
  • Every 30s switch to next group, which should to work

API

new secjsCircle(config)

Instance a circle object and selected the nearest ntp server based on the timezone

  • config: config json for instance

secjsCircle.initialCircle()

Initialize the timestamp, when the first group begin to work. Save the time stamp to attribute this.timeStampOfLastGroup

secjsCircle.getWorkingGroupNumber(callback)

This API is a aync method to get the next group number after a while

  • callback: a callback function to get the caculated working group number

secjsCircle.getNextGroupBeginTimeDiff(currentUnixTime, callback)

This function used to get the time of next group begin to work

secjsCircle.getNextPeriodeBeginTimeDiff(currentUnixTime, callback)

This function used to get the time of the next periode

Usage

To use the libary to get the next working group, you need to do following steps.

  1. Select the nearest ntp server
const SECjsCircle = require('<path of src>')
const config = {
  circleTimeOut: 30,
  ntpTryOut: 0,
  timeServer: 'DE',
  sumOfGroups: 10,
  isMiningHost: true
}
let secjsCircle = new SECjsCircle(config)
  1. Initialize the time stamp of the circle if the group at the first time begin to work
secjsCircle.initial(() => {
    // do something
})
  1. Get the next group number, which should begin to work
secjsCircle.getWorkingGroupNumber((nextWorkingGroupNumber) => {
    let workingGroupNumber = nextWorkingGroupNumber
    console.log(`The next working group should be ${workingGroupNumber}`)
})

License

MIT

Current Tags

  • 1.0.2                                ...           latest (2 years ago)

3 Versions

  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |