|
|
@ -27,6 +27,12 @@ import { format, subDays } from 'date-fns'; |
|
|
|
|
|
|
|
|
import { BetterStackUptimeSlaResponse } from './interfaces/interfaces'; |
|
|
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 { |
|
|
@ -39,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() { |
|
|
@ -60,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() { |
|
|
@ -85,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() { |
|
|
@ -108,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() { |
|
|
@ -142,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) { |
|
|
@ -159,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', { |
|
|
@ -191,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) { |
|
|
@ -215,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( |
|
|
|