exported promote and demote funcs

This commit is contained in:
pippellia-btc
2025-06-10 16:16:20 +02:00
parent a0d4dd5ad8
commit 0ae6b223b7

View File

@@ -127,7 +127,7 @@ func arbiterScan(ctx context.Context, config ArbiterConfig, db redb.RedisDB, sen
case graph.StatusActive: case graph.StatusActive:
// active --> inactive // active --> inactive
if ranks[i] < demotionThreshold { if ranks[i] < demotionThreshold {
if err := demote(db, node.ID); err != nil { if err := Demote(db, node.ID); err != nil {
return promoted, demoted, err return promoted, demoted, err
} }
@@ -142,7 +142,7 @@ func arbiterScan(ctx context.Context, config ArbiterConfig, db redb.RedisDB, sen
} }
if ranks[i] >= promotionThreshold && time.Since(added) > config.PromotionWait { if ranks[i] >= promotionThreshold && time.Since(added) > config.PromotionWait {
if err := promote(db, node.ID); err != nil { if err := Promote(db, node.ID); err != nil {
return promoted, demoted, err return promoted, demoted, err
} }
@@ -172,8 +172,8 @@ func minPagerank(ctx context.Context, db redb.RedisDB) (float64, error) {
return float64(walks.N) / float64(total), nil return float64(walks.N) / float64(total), nil
} }
// demote removes all walks that start from the node and changes its status to inactive. // Demote removes all walks that start from the node and changes its status to inactive.
func demote(db redb.RedisDB, node graph.ID) error { func Demote(db redb.RedisDB, node graph.ID) error {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel() defer cancel()
@@ -194,8 +194,8 @@ func demote(db redb.RedisDB, node graph.ID) error {
return db.Demote(ctx, node) return db.Demote(ctx, node)
} }
// promote generates random walks for the node and changes its status to active. // Promote generates random walks for the node and changes its status to active.
func promote(db redb.RedisDB, node graph.ID) error { func Promote(db redb.RedisDB, node graph.ID) error {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel() defer cancel()