|
1 | 1 | package commands
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "context" |
5 | 4 | "errors"
|
6 | 5 | "fmt"
|
7 | 6 | "net/http"
|
@@ -35,35 +34,6 @@ import (
|
35 | 34 |
|
36 | 35 | var log = logging.Logger("visor")
|
37 | 36 |
|
38 |
| -// RunContext wraps lens and DB connections. |
39 |
| -type RunContext struct { |
40 |
| - Opener lens.APIOpener |
41 |
| - Closer lens.APICloser |
42 |
| - DB *storage.Database |
43 |
| -} |
44 |
| - |
45 |
| -// SetupStorageAndAPI setups of the sentinel database and returns a |
46 |
| -// ready-to-use RunContext with Openers and Closers using the chosen lens. |
47 |
| -func SetupStorageAndAPI(cctx *cli.Context) (context.Context, *RunContext, error) { |
48 |
| - ctx := cctx.Context |
49 |
| - opener, closer, err := setupLens(cctx) |
50 |
| - if err != nil { |
51 |
| - return nil, nil, xerrors.Errorf("setup lens: %w", err) |
52 |
| - } |
53 |
| - |
54 |
| - db, err := setupDatabase(cctx) |
55 |
| - if err != nil { |
56 |
| - closer() |
57 |
| - return nil, nil, xerrors.Errorf("setup database: %w", err) |
58 |
| - } |
59 |
| - |
60 |
| - return ctx, &RunContext{ |
61 |
| - Opener: opener, |
62 |
| - Closer: closer, |
63 |
| - DB: db, |
64 |
| - }, nil |
65 |
| -} |
66 |
| - |
67 | 37 | func setupDatabase(cctx *cli.Context) (*storage.Database, error) {
|
68 | 38 | ctx := cctx.Context
|
69 | 39 | db, err := storage.NewDatabase(ctx, cctx.String("db"), cctx.Int("db-pool-size"), cctx.String("name"), cctx.Bool("db-allow-upsert"))
|
@@ -200,34 +170,6 @@ func setupLogging(cctx *cli.Context) error {
|
200 | 170 | return nil
|
201 | 171 | }
|
202 | 172 |
|
203 |
| -const ( |
204 |
| - ChainHeadIndexerLockID = 98981111 |
205 |
| - ChainHistoryIndexerLockID = 98981112 |
206 |
| - ChainVisRefresherLockID = 98981113 |
207 |
| - ProcessingStatsRefresherLockID = 98981114 |
208 |
| -) |
209 |
| - |
210 |
| -func NewGlobalSingleton(id int64, d *storage.Database) *GlobalSingleton { |
211 |
| - return &GlobalSingleton{ |
212 |
| - LockID: storage.AdvisoryLock(id), |
213 |
| - Storage: d, |
214 |
| - } |
215 |
| -} |
216 |
| - |
217 |
| -// GlobalSingleton is a task locker that ensures only one task can run across all processes |
218 |
| -type GlobalSingleton struct { |
219 |
| - LockID storage.AdvisoryLock |
220 |
| - Storage *storage.Database |
221 |
| -} |
222 |
| - |
223 |
| -func (g *GlobalSingleton) Lock(ctx context.Context) error { |
224 |
| - return g.LockID.LockExclusive(ctx, g.Storage.DB) |
225 |
| -} |
226 |
| - |
227 |
| -func (g *GlobalSingleton) Unlock(ctx context.Context) error { |
228 |
| - return g.LockID.UnlockExclusive(ctx, g.Storage.DB) |
229 |
| -} |
230 |
| - |
231 | 173 | func setupMetrics(cctx *cli.Context) error {
|
232 | 174 | // setup Prometheus
|
233 | 175 | registry := prom.NewRegistry()
|
|
0 commit comments