-
Notifications
You must be signed in to change notification settings - Fork 643
/
Copy pathcrawlers.ts
37 lines (32 loc) · 916 Bytes
/
crawlers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { AtpAgent } from '@atproto/api'
import { crawlerLogger as log } from './logger'
import { MINUTE } from '@atproto/common'
const NOTIFY_THRESHOLD = 20 * MINUTE
export class Crawlers {
public agents: AtpAgent[]
public lastNotified = 0
constructor(public hostname: string, public crawlers: string[]) {
this.agents = crawlers.map((service) => new AtpAgent({ service }))
}
async notifyOfUpdate() {
const now = Date.now()
if (now - this.lastNotified < NOTIFY_THRESHOLD) {
return
}
await Promise.all(
this.agents.map(async (agent) => {
try {
await agent.api.com.atproto.sync.requestCrawl({
hostname: this.hostname,
})
} catch (err) {
log.warn(
{ err, cralwer: agent.service.toString() },
'failed to request crawl',
)
}
}),
)
this.lastNotified = now
}
}