Skip to content

Commit 1698b1f

Browse files
committed
auto disable indexer + deploy committer
1 parent b65bcb5 commit 1698b1f

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

configs/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ type Config struct {
305305
RPCBatchSize uint64 `env:"RPC_BATCH_SIZE" envDefault:"10"`
306306
RPCBatchMaxMemoryUsageMB uint64 `env:"RPC_BATCH_MAX_MEMORY_USAGE_MB" envDefault:"32"`
307307
ParquetMaxFileSizeMB int64 `env:"PARQUET_MAX_FILE_SIZE_MB" envDefault:"512"`
308+
InsightServiceUrl string `env:"INSIGHT_SERVICE_URL" envDefault:"https://insight.thirdweb.com"`
309+
InsightServiceApiKey string `env:"INSIGHT_SERVICE_API_KEY"`
308310
}
309311

310312
var Cfg Config
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package backfill
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
8+
"time"
9+
10+
"github.com/rs/zerolog/log"
11+
config "github.com/thirdweb-dev/indexer/configs"
12+
"github.com/thirdweb-dev/indexer/internal/libs"
13+
)
14+
15+
type DeployS3CommitterRequest struct {
16+
ZeetDeploymentId string `json:"zeetDeploymentId"`
17+
}
18+
19+
func DisableIndexerMaybeStartCommitter() {
20+
serviceURL := config.Cfg.InsightServiceUrl
21+
apiKey := config.Cfg.InsightServiceApiKey
22+
zeetDeploymentId := config.Cfg.ZeetDeploymentId
23+
24+
// Prepare request payload
25+
requestBody := DeployS3CommitterRequest{
26+
ZeetDeploymentId: zeetDeploymentId,
27+
}
28+
29+
jsonData, err := json.Marshal(requestBody)
30+
if err != nil {
31+
log.Error().Err(err).Msg("Failed to marshal request body")
32+
return
33+
}
34+
35+
// Create HTTP request
36+
url := fmt.Sprintf("%s/service/chains/%s/deploy-s3-committer", serviceURL, libs.ChainIdStr)
37+
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
38+
if err != nil {
39+
log.Error().Err(err).Msg("Failed to create HTTP request")
40+
return
41+
}
42+
43+
// Set headers
44+
req.Header.Set("Content-Type", "application/json")
45+
req.Header.Set("x-service-api-key", apiKey)
46+
47+
// Create HTTP client with timeout
48+
client := &http.Client{
49+
Timeout: 30 * time.Second,
50+
}
51+
52+
// Send request
53+
log.Info().
54+
Str("url", url).
55+
Str("zeetDeploymentId", zeetDeploymentId).
56+
Msg("Sending deploy-s3-committer request to disable indexer")
57+
58+
resp, err := client.Do(req)
59+
if err != nil {
60+
log.Error().Err(err).Msg("Failed to send HTTP request")
61+
return
62+
}
63+
defer resp.Body.Close()
64+
65+
// Check response status
66+
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
67+
log.Info().
68+
Int("statusCode", resp.StatusCode).
69+
Msg("Successfully sent deploy-s3-committer request. Indexer disabled")
70+
} else {
71+
log.Error().
72+
Int("statusCode", resp.StatusCode).
73+
Msg("Deploy-s3-committer request failed. Could not disable indexer")
74+
}
75+
}

internal/backfill/getbackfillboundaries.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ func GetBackfillBoundaries() (uint64, uint64) {
2121
}
2222

2323
if startBlock > endBlock {
24+
// since indexing is done, we call insight service to disable the indexer
25+
DisableIndexerMaybeStartCommitter()
26+
// most likely this will not be called as this service will be paused. but a panic just incase
2427
log.Panic().
2528
Uint64("start_block", startBlock).
2629
Uint64("end_block", endBlock).

0 commit comments

Comments
 (0)