Skip to content

Commit

Permalink
feat(scraper): Added status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Nov 11, 2020
1 parent 927c5d1 commit 14f121c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps/api/src/status/status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HttpService, Inject, Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { checkSync } from 'diskusage'
import * as getFolderSize from 'get-folder-size'
import { formatBytes, formatMsToRemaining } from '@pct-org/torrent/utils'
import { formatBytes } from '@pct-org/torrent/utils'
import { MovieModel, ShowModel, EpisodeModel } from '@pct-org/mongo-models'

import { Status } from './status.object-type'
Expand Down Expand Up @@ -66,7 +66,7 @@ export class StatusService {
status: response.data.status,
updated: response.data.updated,
nextUpdate: response.data.nextUpdate,
uptime: formatMsToRemaining(response.data.uptime * 1000)
uptime: response.data.uptime,
}

} catch (e) {
Expand Down
30 changes: 30 additions & 0 deletions apps/scraper/src/routes/status/status.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Controller, Get, Inject, OnApplicationBootstrap } from '@nestjs/common'
import { SchedulerRegistry } from '@nestjs/schedule'
import { formatMsToRemaining } from '@pct-org/torrent/utils'

@Controller()
export class StatusController implements OnApplicationBootstrap {

@Inject()
private schedulerRegistry: SchedulerRegistry

private bootedSince: number

public onApplicationBootstrap(): void {
this.bootedSince = Date.now()
}

@Get('status')
public watch() {
const cron = this.schedulerRegistry.getCronJob('scraper')

return {
status: 'ok',
version: 'beta',
updated: cron.lastDate() || 'never',
nextUpdate: cron.nextDates(),
uptime: formatMsToRemaining(Date.now() - this.bootedSince)
}
}

}
11 changes: 11 additions & 0 deletions apps/scraper/src/routes/status/status.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'

import { StatusController } from './status.controller'

@Module({
controllers: [
StatusController
]
})
export class StatusModule {
}
3 changes: 3 additions & 0 deletions apps/scraper/src/scraper.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import { ConfigService } from './shared/config/config.service'
import { ProvidersModule } from './providers/providers.module'
import { ProvidersService } from './providers/providers.service'

import { StatusModule } from './routes/status/status.module'

@Module({
imports: [
ConfigModule,
ModelsModule,

ProvidersModule,
StatusModule,

// Enable Mongoose
MongooseModule.forRootAsync({
Expand Down

0 comments on commit 14f121c

Please sign in to comment.