mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-consumer.git
synced 2026-09-21 16:52:03 -07:00
Merge pull request #174 from Permissionless-Software-Foundation/ct-unstable
fix(usage): Debugging issue with usage tracking
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This Controller library is concerned with timer-based functions that are
|
This Controller library is concerned with timer-based functions that are
|
||||||
kicked off periodicially.
|
kicked off periodically.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import config from '../../config/index.js'
|
import config from '../../config/index.js'
|
||||||
@@ -45,7 +45,7 @@ class TimerControllers {
|
|||||||
|
|
||||||
stopTimers () {
|
stopTimers () {
|
||||||
clearInterval(this.optimizeWalletHandle)
|
clearInterval(this.optimizeWalletHandle)
|
||||||
clearInterval(this.cleanusageHandle)
|
clearInterval(this.cleanUsageHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace this example function with your own timer handler.
|
// Replace this example function with your own timer handler.
|
||||||
@@ -67,6 +67,9 @@ class TimerControllers {
|
|||||||
// Clean the usage state so that stats reflect the last 24 hours.
|
// Clean the usage state so that stats reflect the last 24 hours.
|
||||||
cleanUsage () {
|
cleanUsage () {
|
||||||
try {
|
try {
|
||||||
|
const now = new Date()
|
||||||
|
console.log(`cleanUsage() Timer Controller executing at ${now.toLocaleString()}`)
|
||||||
|
|
||||||
this.useCases.usage.cleanUsage()
|
this.useCases.usage.cleanUsage()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -36,7 +36,11 @@ class UsageUseCases {
|
|||||||
const now = new Date()
|
const now = new Date()
|
||||||
const twentyFourHoursAgo = now.getTime() - (60000 * 60 * 24)
|
const twentyFourHoursAgo = now.getTime() - (60000 * 60 * 24)
|
||||||
|
|
||||||
|
console.log('cleanUsage() now: ', now)
|
||||||
|
console.log('cleanUsage() restCalls.length before filtering: ', restCalls.length)
|
||||||
restCalls = restCalls.filter(x => x.timestamp > twentyFourHoursAgo)
|
restCalls = restCalls.filter(x => x.timestamp > twentyFourHoursAgo)
|
||||||
|
console.log('cleanUsage() restCalls.length after filtering: ', restCalls.length)
|
||||||
|
|
||||||
return restCalls
|
return restCalls
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error in usage-use-cases.js/cleanUsage()')
|
console.error('Error in usage-use-cases.js/cleanUsage()')
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Unit tests for the use-cases/usage-use-cases.js business logic library.
|
Unit tests for the use-cases/usage-use-cases.js business logic library.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Public npm libraries
|
// Public npm libraries
|
||||||
@@ -58,7 +57,7 @@ describe('#usage-use-case', () => {
|
|||||||
|
|
||||||
// set older mock data
|
// set older mock data
|
||||||
restCalls.push({
|
restCalls.push({
|
||||||
timestamp: now.getTime() - (60000 * 60 * 24),
|
timestamp: now.getTime() - (60000 * 60 * 48), // 48 hours ago
|
||||||
ip: '127.0.0.1'
|
ip: '127.0.0.1'
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -88,6 +87,7 @@ describe('#usage-use-case', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#getRestSummary', () => {
|
describe('#getRestSummary', () => {
|
||||||
it('should get the number of rest calls', () => {
|
it('should get the number of rest calls', () => {
|
||||||
// Set mock data
|
// Set mock data
|
||||||
@@ -137,6 +137,7 @@ describe('#usage-use-case', () => {
|
|||||||
assert.equal(result[0].ip, 'localhost')
|
assert.equal(result[0].ip, 'localhost')
|
||||||
assert.equal(result[0].cnt, '2')
|
assert.equal(result[0].cnt, '2')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return a maximum of 20 values', () => {
|
it('should return a maximum of 20 values', () => {
|
||||||
// Fill Array with 21 values
|
// Fill Array with 21 values
|
||||||
for (let i = 0; i < 21; i++) {
|
for (let i = 0; i < 21; i++) {
|
||||||
@@ -154,6 +155,7 @@ describe('#usage-use-case', () => {
|
|||||||
|
|
||||||
assert.equal(result.length, 20)
|
assert.equal(result.length, 20)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle error', () => {
|
it('should handle error', () => {
|
||||||
try {
|
try {
|
||||||
// Set mock data
|
// Set mock data
|
||||||
@@ -194,6 +196,7 @@ describe('#usage-use-case', () => {
|
|||||||
assert.equal(result[0].endpoint, 'GET /api/v1/users')
|
assert.equal(result[0].endpoint, 'GET /api/v1/users')
|
||||||
assert.equal(result[0].cnt, '2')
|
assert.equal(result[0].cnt, '2')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return a maximum of 20 values', () => {
|
it('should return a maximum of 20 values', () => {
|
||||||
// Fill Array with 21 values
|
// Fill Array with 21 values
|
||||||
for (let i = 0; i < 21; i++) {
|
for (let i = 0; i < 21; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user