Skip to content

Commit

Permalink
Add dry run mode to preserved score marking
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Dec 27, 2023
1 parent 2801e4d commit 6ee0d9f
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ public class MarkNonPreservedScoresCommand
[Option(CommandOptionType.SingleValue, Template = "-r|--ruleset", Description = "The ruleset to process.")]
public int RulesetId { get; set; }

[Option(CommandOptionType.SingleOrNoValue, Template = "--dry-run", Description = "Don't actually mark, just output.")]
public bool DryRun { get; set; }

public async Task<int> OnExecuteAsync(CancellationToken cancellationToken)
{
LegacyDatabaseHelper.RulesetDatabaseInfo databaseInfo = LegacyDatabaseHelper.GetRulesetSpecifics(RulesetId);

Console.WriteLine($"Running for ruleset {RulesetId}");
if (DryRun)
Console.WriteLine("RUNNING IN DRY RUN MODE.");

using (var db = DatabaseAccess.GetConnection())
{
Expand Down Expand Up @@ -85,15 +90,18 @@ private async Task processUser(MySqlConnection db, int userId, CancellationToken

Console.WriteLine($"Marking score {score.id} non-preserved...");

await db.ExecuteAsync("UPDATE scores SET preserve = 0, unix_updated_at = CURRENT_TIMESTAMP WHERE id = @scoreId;", new
{
scoreId = score.id
});

elasticQueueProcessor.PushToQueue(new ElasticQueuePusher.ElasticScoreItem
if (!DryRun)
{
ScoreId = (long?)score.id
});
await db.ExecuteAsync("UPDATE scores SET preserve = 0, unix_updated_at = CURRENT_TIMESTAMP WHERE id = @scoreId;", new
{
scoreId = score.id
});

elasticQueueProcessor.PushToQueue(new ElasticQueuePusher.ElasticScoreItem
{
ScoreId = (long?)score.id
});
}
}
}

Expand Down

0 comments on commit 6ee0d9f

Please sign in to comment.