@ -25,6 +25,14 @@ import { Injectable, Logger } from '@nestjs/common';
import * as cheerio from 'cheerio' ;
import * as cheerio from 'cheerio' ;
import { format , subDays } from 'date-fns' ;
import { format , subDays } from 'date-fns' ;
import { BetterStackUptimeSlaResponse } from './interfaces/interfaces' ;
const GATHER_STATISTICS_CONCURRENCY = parseInt (
process . env . PROCESSOR_GATHER_STATISTICS_CONCURRENCY ? ?
DEFAULT_PROCESSOR_GATHER_STATISTICS_CONCURRENCY . toString ( ) ,
10
) ;
@Injectable ( )
@Injectable ( )
@Processor ( STATISTICS_GATHERING_QUEUE )
@Processor ( STATISTICS_GATHERING_QUEUE )
export class StatisticsGatheringProcessor {
export class StatisticsGatheringProcessor {
@ -37,11 +45,7 @@ export class StatisticsGatheringProcessor {
) { }
) { }
@Process ( {
@Process ( {
concurrency : parseInt (
concurrency : GATHER_STATISTICS_CONCURRENCY ,
process . env . PROCESSOR_GATHER_STATISTICS_CONCURRENCY ? ?
DEFAULT_PROCESSOR_GATHER_STATISTICS_CONCURRENCY . toString ( ) ,
10
) ,
name : GATHER_STATISTICS_DOCKER_HUB_PULLS_PROCESS_JOB_NAME
name : GATHER_STATISTICS_DOCKER_HUB_PULLS_PROCESS_JOB_NAME
} )
} )
public async gatherDockerHubPullsStatistics() {
public async gatherDockerHubPullsStatistics() {
@ -58,11 +62,7 @@ export class StatisticsGatheringProcessor {
}
}
@Process ( {
@Process ( {
concurrency : parseInt (
concurrency : GATHER_STATISTICS_CONCURRENCY ,
process . env . PROCESSOR_GATHER_STATISTICS_CONCURRENCY ? ?
DEFAULT_PROCESSOR_GATHER_STATISTICS_CONCURRENCY . toString ( ) ,
10
) ,
name : GATHER_STATISTICS_GITHUB_CONTRIBUTORS_PROCESS_JOB_NAME
name : GATHER_STATISTICS_GITHUB_CONTRIBUTORS_PROCESS_JOB_NAME
} )
} )
public async gatherGitHubContributorsStatistics() {
public async gatherGitHubContributorsStatistics() {
@ -83,11 +83,7 @@ export class StatisticsGatheringProcessor {
}
}
@Process ( {
@Process ( {
concurrency : parseInt (
concurrency : GATHER_STATISTICS_CONCURRENCY ,
process . env . PROCESSOR_GATHER_STATISTICS_CONCURRENCY ? ?
DEFAULT_PROCESSOR_GATHER_STATISTICS_CONCURRENCY . toString ( ) ,
10
) ,
name : GATHER_STATISTICS_GITHUB_STARGAZERS_PROCESS_JOB_NAME
name : GATHER_STATISTICS_GITHUB_STARGAZERS_PROCESS_JOB_NAME
} )
} )
public async gatherGitHubStargazersStatistics() {
public async gatherGitHubStargazersStatistics() {
@ -106,11 +102,7 @@ export class StatisticsGatheringProcessor {
}
}
@Process ( {
@Process ( {
concurrency : parseInt (
concurrency : GATHER_STATISTICS_CONCURRENCY ,
process . env . PROCESSOR_GATHER_STATISTICS_CONCURRENCY ? ?
DEFAULT_PROCESSOR_GATHER_STATISTICS_CONCURRENCY . toString ( ) ,
10
) ,
name : GATHER_STATISTICS_UPTIME_PROCESS_JOB_NAME
name : GATHER_STATISTICS_UPTIME_PROCESS_JOB_NAME
} )
} )
public async gatherUptimeStatistics() {
public async gatherUptimeStatistics() {
@ -140,14 +132,14 @@ export class StatisticsGatheringProcessor {
private async countDockerHubPulls ( ) : Promise < number > {
private async countDockerHubPulls ( ) : Promise < number > {
try {
try {
const { pull_count } = ( await this . fetchService
const { pull_count } = await this . fetchService
. fetch ( 'https://hub.docker.com/v2/repositories/ghostfolio/ghostfolio' , {
. fetch ( 'https://hub.docker.com/v2/repositories/ghostfolio/ghostfolio' , {
headers : { 'User-Agent' : 'request' } ,
headers : { 'User-Agent' : 'request' } ,
signal : AbortSignal.timeout (
signal : AbortSignal.timeout (
this . configurationService . get ( 'REQUEST_TIMEOUT' )
this . configurationService . get ( 'REQUEST_TIMEOUT' )
)
)
} )
} )
. then ( ( res ) = > res . json ( ) ) ) as { pull_count : number } ;
. then < { pull_count : number } > ( ( res ) = > res . json ( ) ) ;
return pull_count ;
return pull_count ;
} catch ( error ) {
} catch ( error ) {
@ -157,7 +149,7 @@ export class StatisticsGatheringProcessor {
}
}
}
}
private async countGitHubContributors ( ) : Promise < number > {
private async countGitHubContributors ( ) : Promise < number | undefined > {
try {
try {
const body = await this . fetchService
const body = await this . fetchService
. fetch ( 'https://github.com/ghostfolio/ghostfolio' , {
. fetch ( 'https://github.com/ghostfolio/ghostfolio' , {
@ -189,14 +181,14 @@ export class StatisticsGatheringProcessor {
private async countGitHubStargazers ( ) : Promise < number > {
private async countGitHubStargazers ( ) : Promise < number > {
try {
try {
const { stargazers_count } = ( await this . fetchService
const { stargazers_count } = await this . fetchService
. fetch ( 'https://api.github.com/repos/ghostfolio/ghostfolio' , {
. fetch ( 'https://api.github.com/repos/ghostfolio/ghostfolio' , {
headers : { 'User-Agent' : 'request' } ,
headers : { 'User-Agent' : 'request' } ,
signal : AbortSignal.timeout (
signal : AbortSignal.timeout (
this . configurationService . get ( 'REQUEST_TIMEOUT' )
this . configurationService . get ( 'REQUEST_TIMEOUT' )
)
)
} )
} )
. then ( ( res ) = > res . json ( ) ) ) as { stargazers_count : number } ;
. then < { stargazers_count : number } > ( ( res ) = > res . json ( ) ) ;
return stargazers_count ;
return stargazers_count ;
} catch ( error ) {
} catch ( error ) {
@ -213,7 +205,7 @@ export class StatisticsGatheringProcessor {
` https://uptime.betterstack.com/api/v2/monitors/ ${ monitorId } /sla?from= ${ format (
` https://uptime.betterstack.com/api/v2/monitors/ ${ monitorId } /sla?from= ${ format (
subDays ( new Date ( ) , 90 ) ,
subDays ( new Date ( ) , 90 ) ,
DATE_FORMAT
DATE_FORMAT
) } & to $ { format ( new Date ( ) , DATE_FORMAT ) } ` ,
) } & to = $ { format ( new Date ( ) , DATE_FORMAT ) } ` ,
{
{
headers : {
headers : {
[ HEADER_KEY_TOKEN ] : ` Bearer ${ this . configurationService . get (
[ HEADER_KEY_TOKEN ] : ` Bearer ${ this . configurationService . get (
@ -225,7 +217,7 @@ export class StatisticsGatheringProcessor {
)
)
}
}
)
)
. then ( ( res ) = > res . json ( ) ) ;
. then < BetterStackUptimeSlaResponse > ( ( res ) = > res . json ( ) ) ;
return data . attributes . availability / 100 ;
return data . attributes . availability / 100 ;
} catch ( error ) {
} catch ( error ) {