-
Notifications
You must be signed in to change notification settings - Fork 177
/
headless.ts
52 lines (40 loc) · 1.5 KB
/
headless.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import ua from 'universal-analytics'
import uuid4 from 'uuid4'
import { Engine } from './src-worker/engine'
import { parseArguments } from './src-lib/context'
import { AutomaticStrategy } from './src-worker/planing/automaticStrategy'
const arg = parseArguments()
let workers = (arg.workers !== undefined) ? arg.workers : 32
let useProxy = (arg.withProxy !== undefined) ? arg.withProxy : true
if (process.env.WORKERS) {
workers = Number(process.env.WORKERS)
}
if (process.env.USEPROXY) {
useProxy = process.env.USEPROXY === 'true'
}
console.log(`Using ${workers} workers, proxy - ${String(useProxy)}`)
const engine = new Engine()
engine.setExecutorStartegy((arg.planer !== undefined ? arg.planer : 'automatic') as 'manual' | 'automatic')
engine.config.useRealIP = !useProxy
engine.start()
if (engine.executionStartegy.type === 'automatic') {
(engine.executionStartegy as AutomaticStrategy).setMaxExecutorsCount(arg.maxWorkers !== undefined ? arg.maxWorkers : 128)
}
engine.executionStartegy.setExecutorsCount(workers)
engine.config.logTimestamp = arg.logTimestamp !== undefined ? arg.logTimestamp : true
engine.config.logRequests = arg.logRequests !== undefined ? arg.logRequests : true
const usr = ua('UA-222593827-1', uuid4())
const pageviewFn = () => {
try {
usr.pageview('/headless', (err) => {
if (err) {
console.log(err)
}
})
} catch (e) { console.log(e) }
}
pageviewFn()
setInterval(pageviewFn, 90000)
process.on('uncaughtException', function (err) {
console.error(err)
})