mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-23 01:22:03 -07:00
66 lines
1.6 KiB
JavaScript
66 lines
1.6 KiB
JavaScript
/*
|
|
This Controller library is concerned with timer-based functions that are
|
|
kicked off periodicially.
|
|
*/
|
|
|
|
import config from '../../config/index.js'
|
|
|
|
class TimerControllers {
|
|
constructor (localConfig = {}) {
|
|
// Dependency Injection.
|
|
this.adapters = localConfig.adapters
|
|
if (!this.adapters) {
|
|
throw new Error(
|
|
'Instance of Adapters library required when instantiating Timer Controller libraries.'
|
|
)
|
|
}
|
|
this.useCases = localConfig.useCases
|
|
if (!this.useCases) {
|
|
throw new Error(
|
|
'Instance of Use Cases library required when instantiating Timer Controller libraries.'
|
|
)
|
|
}
|
|
|
|
this.debugLevel = localConfig.debugLevel
|
|
|
|
// Encapsulate dependencies
|
|
this.config = config
|
|
|
|
// Bind 'this' object to all subfunctions.
|
|
this.exampleTimerFunc = this.exampleTimerFunc.bind(this)
|
|
|
|
this.startTimers()
|
|
}
|
|
|
|
// Start all the time-based controllers.
|
|
startTimers () {
|
|
// Any new timer control functions can be added here. They will be started
|
|
// when the server starts.
|
|
this.optimizeWalletHandle = setInterval(this.exampleTimerFunc, 60000 * 10)
|
|
|
|
return true
|
|
}
|
|
|
|
stopTimers () {
|
|
clearInterval(this.optimizeWalletHandle)
|
|
}
|
|
|
|
// Replace this example function with your own timer handler.
|
|
exampleTimerFunc (negativeTest) {
|
|
try {
|
|
console.log('Example timer controller executed.')
|
|
|
|
if (negativeTest) throw new Error('test error')
|
|
|
|
return true
|
|
} catch (err) {
|
|
console.error('Error in exampleTimerFunc(): ', err)
|
|
|
|
// Note: Do not throw an error. This is a top-level function.
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
export default TimerControllers
|