Skip to content

Commit

Permalink
Merge pull request #138 from peppy/use-execute-async
Browse files Browse the repository at this point in the history
Update all remaining commands to use `OnExecuteAsync` instead of `OnExecute`
  • Loading branch information
smoogipoo authored Aug 15, 2023
2 parents 9b25596 + e0487c0 commit 0c12a8b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions osu.Server.Queues.ScorePump/Queue/ClearQueueCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

using System;
using System.Threading;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;

namespace osu.Server.Queues.ScorePump.Queue
{
[Command("clear", Description = "Completely empties the processing queue")]
public class ClearQueueCommand : BaseCommand
{
public int OnExecute(CancellationToken cancellationToken)
public Task<int> OnExecuteAsync(CancellationToken cancellationToken)
{
Queue.ClearQueue();
Console.WriteLine("Queue has been cleared!");
return 0;
return Task.FromResult(0);
}
}
}
5 changes: 3 additions & 2 deletions osu.Server.Queues.ScorePump/Queue/PumpAllScoresCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Threading;
using System.Threading.Tasks;
using Dapper;
using McMaster.Extensions.CommandLineUtils;
using osu.Server.Queues.ScoreStatisticsProcessor.Models;
Expand All @@ -21,7 +22,7 @@ public class PumpAllScoresCommand : BaseCommand
[Option("--sql", Description = "Specify a custom query to limit the scope of pumping")]
public string? CustomQuery { get; set; }

public int OnExecute(CancellationToken cancellationToken)
public async Task<int> OnExecuteAsync(CancellationToken cancellationToken)
{
using (var dbMainQuery = Queue.GetDatabaseConnection())
using (var db = Queue.GetDatabaseConnection())
Expand All @@ -46,7 +47,7 @@ public int OnExecute(CancellationToken cancellationToken)
Queue.PushToQueue(new ScoreItem(score, history));

if (Delay > 0)
Thread.Sleep(Delay);
await Task.Delay(Delay, cancellationToken);
}
}

Expand Down
5 changes: 3 additions & 2 deletions osu.Server.Queues.ScorePump/Queue/PumpTestDataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Threading;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using osu.Server.Queues.ScoreStatisticsProcessor.Models;

Expand All @@ -11,7 +12,7 @@ namespace osu.Server.Queues.ScorePump.Queue
[Command("pump-test", Description = "Pumps empty test scores to the queue")]
public class PumpTestDataCommand : BaseCommand
{
public int OnExecute(CancellationToken cancellationToken)
public Task<int> OnExecuteAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
Expand All @@ -23,7 +24,7 @@ public int OnExecute(CancellationToken cancellationToken)
Thread.Sleep(200);
}

return 0;
return Task.FromResult(0);
}
}
}
5 changes: 3 additions & 2 deletions osu.Server.Queues.ScorePump/Queue/WatchNewScoresCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Threading;
using System.Threading.Tasks;
using Dapper;
using JetBrains.Annotations;
using McMaster.Extensions.CommandLineUtils;
Expand All @@ -24,7 +25,7 @@ public class WatchNewScoresCommand : BaseCommand
[UsedImplicitly]
private ulong lastId;

public int OnExecute(CancellationToken cancellationToken)
public Task<int> OnExecuteAsync(CancellationToken cancellationToken)
{
if (StartId.HasValue)
lastId = StartId.Value - 1;
Expand Down Expand Up @@ -76,7 +77,7 @@ public int OnExecute(CancellationToken cancellationToken)
}
}

return 0;
return Task.FromResult(0);
}
}
}

0 comments on commit 0c12a8b

Please sign in to comment.