Skip to content

Commit 35be50d

Browse files
hussedev0xKurt
andauthored
feat: fly indexer process http service (#670)
* Add port 8081 for indexer * fix * chore: added indexer web service --------- Co-authored-by: 0xKurt <[email protected]>
1 parent 64fd8e5 commit 35be50d

File tree

3 files changed

+132
-79
lines changed

3 files changed

+132
-79
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ npm run dev -- --from-block=12345 # start indexing from the 12345th block
4444
npm run dev -- --run-once # index and exit without watching for events
4545
npm run dev -- --no-cache # disable cache
4646
npm run dev -- --log-level=trace # set log level
47+
npm run dev -- --port=8081 # start web service on a given port
4748
```
4849

4950
## Running in production

fly.toml

+82-43
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,105 @@
1-
app = 'indexer-v2'
2-
primary_region = 'den'
3-
kill_signal = 'SIGINT'
4-
kill_timeout = '5s'
1+
2+
app = "indexer-v2"
3+
primary_region = "den"
4+
kill_signal = "SIGINT"
5+
kill_timeout = "5s"
56

67
[experimental]
78
auto_rollback = true
89

910
[build]
1011

1112
[deploy]
12-
wait_timeout = '6h0m0s'
13+
wait_timeout = "6h0m0s"
1314

1415
[env]
15-
PINO_PRETTY = 'true'
16-
DEPLOYMENT_ENVIRONMENT = 'production'
17-
ENABLE_RESOURCE_MONITOR = 'false'
18-
ESTIMATES_LINEARQF_WORKER_POOL_SIZE = '10'
19-
INDEXED_CHAINS = 'mainnet,optimism,fantom,pgn-testnet,pgn-mainnet,arbitrum,polygon,sepolia,avalanche,avalanche-fuji,scroll,scroll-sepolia,base,zksync-era-mainnet,lukso-mainnet,lukso-testnet,celo-mainnet,celo-testnet,sei-mainnet,metisAndromeda'
20-
LOG_LEVEL = 'debug'
21-
NODE_OPTIONS = '--max-old-space-size=4096'
22-
PORT = '8080'
23-
STORAGE_DIR = '/mnt/indexer'
24-
PASSPORT_SCORER_ID=335
16+
PINO_PRETTY = "true"
17+
DEPLOYMENT_ENVIRONMENT = "production"
18+
ENABLE_RESOURCE_MONITOR = "false"
19+
ESTIMATES_LINEARQF_WORKER_POOL_SIZE = "10"
20+
INDEXED_CHAINS = "mainnet,optimism,fantom,pgn-testnet,pgn-mainnet,arbitrum,polygon,sepolia,avalanche,avalanche-fuji,scroll,scroll-sepolia,base,zksync-era-mainnet,lukso-mainnet,lukso-testnet,celo-mainnet,celo-testnet,sei-mainnet,metisAndromeda"
21+
LOG_LEVEL = "debug"
22+
NODE_OPTIONS = "--max-old-space-size=4096"
23+
PORT = "8080"
24+
STORAGE_DIR = "/mnt/indexer"
25+
PASSPORT_SCORER_ID = 335
2526

2627
[processes]
27-
indexer = 'npm start -- --indexer --http'
28-
web = 'npm start -- --http --http-wait-for-sync=false'
28+
indexer = "npm start -- --indexer --http"
29+
web = "npm start -- --http --http-wait-for-sync=false"
2930

3031
[[mounts]]
31-
source = 'indexer_staging'
32-
destination = '/mnt/indexer'
33-
initial_size = '50GB'
32+
source = "indexer_staging"
33+
destination = "/mnt/indexer"
34+
initial_size = "50GB"
3435
auto_extend_size_threshold = 80
3536
auto_extend_size_increment = "5GB"
3637
auto_extend_size_limit = "100GB"
37-
processes = ['indexer', 'web']
38+
processes = ["indexer", "web"]
3839

39-
[http_service]
40+
[[services]]
4041
internal_port = 8080
41-
force_https = true
42-
auto_stop_machines = true
43-
auto_start_machines = true
44-
min_machines_running = 2
45-
processes = ['web']
46-
47-
[http_service.concurrency]
48-
type = 'requests'
42+
processes = ["indexer"]
43+
protocol = "tcp"
44+
script_checks = []
45+
46+
[services.concurrency]
4947
hard_limit = 250
5048
soft_limit = 200
49+
type = "requests"
50+
51+
[[services.ports]]
52+
force_https = true
53+
handlers = ["http"]
54+
port = 80
55+
56+
[[services.ports]]
57+
handlers = ["tls", "http"]
58+
port = 443
59+
60+
[[services.tcp_checks]]
61+
grace_period = "30s"
62+
interval = "15s"
63+
restart_limit = 0
64+
timeout = "10s"
65+
66+
[[services]]
67+
internal_port = 8080
68+
processes = ["web"]
69+
protocol = "tcp"
70+
script_checks = []
71+
72+
[services.concurrency]
73+
hard_limit = 250
74+
soft_limit = 200
75+
type = "requests"
76+
77+
[[services.ports]]
78+
force_https = true
79+
handlers = ["http"]
80+
port = 80
81+
82+
[[services.ports]]
83+
handlers = ["tls", "http"]
84+
port = 443
85+
86+
[[services.tcp_checks]]
87+
grace_period = "30s"
88+
interval = "15s"
89+
restart_limit = 0
90+
timeout = "10s"
5191

52-
[checks]
53-
[checks.http]
54-
port = 8080
55-
type = 'http'
56-
interval = '15s'
57-
timeout = '10s'
58-
grace_period = '30s'
59-
method = 'get'
60-
path = '/api/v1/status'
61-
processes = ['web', 'indexer']
92+
[checks.http]
93+
port = 8080
94+
type = "http"
95+
interval = "15s"
96+
timeout = "10s"
97+
grace_period = "30s"
98+
method = "get"
99+
path = "/api/v1/status"
100+
processes = ["web", "indexer"]
62101

63102
[[vm]]
64-
memory = '4gb'
65-
cpu_kind = 'performance'
66-
cpus = 2
103+
memory = "4gb"
104+
cpu_kind = "performance"
105+
cpus = 2

src/config.ts

+49-36
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,44 @@ export type Config = {
18391839
};
18401840

18411841
export function getConfig(): Config {
1842+
const { values: args } = parseArgs({
1843+
options: {
1844+
"to-block": {
1845+
type: "string",
1846+
},
1847+
"from-block": {
1848+
type: "string",
1849+
},
1850+
"drop-db": {
1851+
type: "boolean",
1852+
},
1853+
"rm-cache": {
1854+
type: "boolean",
1855+
},
1856+
"log-level": {
1857+
type: "string",
1858+
},
1859+
"run-once": {
1860+
type: "boolean",
1861+
},
1862+
"no-cache": {
1863+
type: "boolean",
1864+
},
1865+
"http-wait-for-sync": {
1866+
type: "string",
1867+
},
1868+
http: {
1869+
type: "boolean",
1870+
},
1871+
indexer: {
1872+
type: "boolean",
1873+
},
1874+
port: {
1875+
type: "string",
1876+
},
1877+
},
1878+
});
1879+
18421880
const buildTag = z
18431881
.union([z.string(), z.null()])
18441882
.default(null)
@@ -1849,7 +1887,17 @@ export function getConfig(): Config {
18491887
.transform((value) => value === "true")
18501888
.parse(process.env.ENABLE_RESOURCE_MONITOR);
18511889

1852-
const apiHttpPort = z.coerce.number().parse(process.env.PORT);
1890+
const portSchema = z.coerce.number().int().nonnegative().max(65535);
1891+
1892+
const portOverride = z
1893+
.union([portSchema, z.undefined()])
1894+
.optional()
1895+
.parse(args["port"]);
1896+
1897+
const apiHttpPort =
1898+
portOverride !== undefined
1899+
? portOverride
1900+
: portSchema.parse(z.coerce.number().parse(process.env.PORT));
18531901

18541902
const pinoPretty = z
18551903
.enum(["true", "false"])
@@ -1890,41 +1938,6 @@ export function getConfig(): Config {
18901938
.default(path.join(storageDir, "cache"))
18911939
.parse(process.env.CACHE_DIR);
18921940

1893-
const { values: args } = parseArgs({
1894-
options: {
1895-
"to-block": {
1896-
type: "string",
1897-
},
1898-
"from-block": {
1899-
type: "string",
1900-
},
1901-
"drop-db": {
1902-
type: "boolean",
1903-
},
1904-
"rm-cache": {
1905-
type: "boolean",
1906-
},
1907-
"log-level": {
1908-
type: "string",
1909-
},
1910-
"run-once": {
1911-
type: "boolean",
1912-
},
1913-
"no-cache": {
1914-
type: "boolean",
1915-
},
1916-
"http-wait-for-sync": {
1917-
type: "string",
1918-
},
1919-
http: {
1920-
type: "boolean",
1921-
},
1922-
indexer: {
1923-
type: "boolean",
1924-
},
1925-
},
1926-
});
1927-
19281941
const chains = z
19291942
.string()
19301943
.or(z.literal("all"))

0 commit comments

Comments
 (0)