Skip to content

Commit

Permalink
Add scraper url (#526)
Browse files Browse the repository at this point in the history
* Updated the ids

* Refractored Events API and wrote tests fro the events and populapopularEvents endpoints

* Lint format

* Added more test cases

* Added test cases for unit test

* Fixed merge conflict and update tests

* Fixed merge conflict

* Fixed merge conflict

* Fixed merge conflict

* Fixed duplicate errror

* Fixed lint error

* Add comments

* Sync main

* Lint

* completed all the test cases

* Collapsed duplicate

* Lint

* Removed unnecessary console.log

* Separated wiki events category from wiki events title

* Lint

* Fixed testEvent Error

* Lint

* Updated resolver

* New events test

* Added new test suits

* Updating

* First part of the tests

* Update events tests

* Lint

* Lint

* Remove unused tests

---------

Co-authored-by: Cold Dev <[email protected]>
  • Loading branch information
AshakaE and icemedia001 authored Apr 4, 2024
1 parent e1eba30 commit c9a7801
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ BRAINPASS_DEFAULT_IMAGE =
BRAINPASS_DEFAULT_DESCRIPTION =
INDEXER_GITHUB_TOKEN =
API_LEVEL =
TRIGGER_SCRAPPER_URL=
TRIGGER_SCRAPPER_STATUS=

#Blockchain
ALCHEMY_NOTIFY_WIKI_SIGNING_KEY=
Expand Down
78 changes: 15 additions & 63 deletions src/App/utils/auto-injest.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,37 @@
import { HttpService } from '@nestjs/axios'
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { LockingService } from '../IQHolders/IQHolders.dto'

export const injestId = 'injest.action'
@Injectable()
class AutoInjestService {
constructor(
private configService: ConfigService,
private httpService: HttpService,
private lockingService: LockingService,
) {}

private INJEST_KEYS(): string {
return this.configService.get<string>('INDEXER_GITHUB_TOKEN') as string
}

async initiateInjest() {
const status = await this.checkWorkflowStatus()

const environment = this.configService.get<string>('API_LEVEL') as string

const locked = await this.lockingService.acquireLock(injestId)
console.debug({
injest_wait: locked,
workflow_status: status,
})
if (environment === 'dev' || !locked || !status) return

const scraperUrl = this.configService.get<string>(
'TRIGGER_SCRAPPER_URL',
) as string
const statusUrl = this.configService.get<string>(
'TRIGGER_SCRAPPER_STATUS',
) as string
try {
const payload = {
event_type: 'trigger-scraper',
client_payload: {
scraperName: 'IQ Wiki',
},
const statusResponse = await this.httpService.get(statusUrl).toPromise()

if (!statusResponse?.data.state) {
setTimeout(async () => {
await this.initiateInjest()
}, 30000)
return
}

await this.httpService
.post(
'https://api.github.com/repos/EveripediaNetwork/iq-gpt-ingester-js/dispatches',
payload,
{
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `token ${this.INJEST_KEYS()}`,
},
},
)
.toPromise()
await this.httpService.post(scraperUrl).toPromise()
console.log('Injest action emitted ! ! ⚙️')
} catch (e) {
} catch (e: any) {
console.error(e)
}

setTimeout(() => {
this.lockingService.releaseLock(injestId)
}, 30000)
}

async checkWorkflowStatus(): Promise<boolean> {
let status = false
try {
const response = await this.httpService
.get(
'https://api.github.com/repos/EveripediaNetwork/iq-gpt-ingester-js/actions/workflows/trigger.yml/runs',

{
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `token ${this.INJEST_KEYS()}`,
},
},
)
.toPromise()

status = response?.data.workflow_runs[0].status === 'completed'
} catch (e) {
console.error(e)
}

return status
}
}

Expand Down

0 comments on commit c9a7801

Please sign in to comment.