Skip to content

Commit

Permalink
new disc next crawl random(5 min)
Browse files Browse the repository at this point in the history
  • Loading branch information
angaz committed Mar 21, 2024
1 parent 6db1f75 commit 3110b31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/database/disc.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (db *DB) UpsertNode(ctx context.Context, tx pgx.Tx, node *enode.Node) error
) VALUES (
@node_id,
now(),
now()
now() + random_seconds(300)
) ON CONFLICT (node_id) DO UPDATE
SET
last_found = now(),
Expand Down
1 change: 1 addition & 0 deletions pkg/database/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (db *DB) Migrate(geoipdb string) error {
},
"function client.upsert": migrations.ClientUpsertStrings,
"function execution.capabilities_upsert": migrations.ExecutionCapabilitiesUpsert,
"function random_seconds": migrations.RandomSeconds,
"geoip": func(ctx context.Context, tx pgx.Tx) error {
return migrations.UpdateGeoIPData(ctx, tx, geoipdb)
},
Expand Down
17 changes: 17 additions & 0 deletions pkg/database/migrations/upsert_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ import (
"github.com/jackc/pgx/v5"
)

func RandomSeconds(ctx context.Context, tx pgx.Tx) error {
_, err := tx.Exec(
ctx,
`
CREATE OR REPLACE FUNCTION random_seconds(max_seconds INTEGER) RETURNS INTERVAL
AS 'SELECT make_interval(secs => random() * max_seconds);'
IMMUTABLE
LANGUAGE SQL
`,
)
if err != nil {
return fmt.Errorf("exec: %w", err)
}

return nil
}

func ExecutionCapabilitiesUpsert(ctx context.Context, tx pgx.Tx) error {
_, err := tx.Exec(
ctx,
Expand Down

0 comments on commit 3110b31

Please sign in to comment.