From 645103ef478cd728cb92f0fa7cbc191bd37aaa12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 12 Dec 2023 11:03:23 +0100 Subject: [PATCH 1/3] Move `ProcessingMode` enum out to separate file --- .../Commands/CalculatorCommand.cs | 15 ++++----------- .../Commands/ProcessingMode.cs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 osu.Server.DifficultyCalculator/Commands/ProcessingMode.cs diff --git a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs index 4b22d9b..84bbc8e 100644 --- a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs +++ b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs @@ -42,7 +42,7 @@ public abstract class CalculatorCommand : CommandBase public bool DryRun { get; set; } [Option(CommandOptionType.SingleValue, Template = "--processing-mode", Description = "The mode in which to process beatmaps.")] - public ProcessingModes ProcessingMode { get; set; } = ProcessingModes.All; + public ProcessingMode ProcessingMode { get; set; } = ProcessingMode.All; private int[] threadBeatmapIds = null!; private IReporter reporter = null!; @@ -94,15 +94,15 @@ public void OnExecute(CommandLineApplication app, IConsole console) switch (ProcessingMode) { - case ProcessingModes.All: + case ProcessingMode.All: calc.ProcessAll(beatmap); break; - case ProcessingModes.Difficulty: + case ProcessingMode.Difficulty: calc.ProcessDifficulty(beatmap); break; - case ProcessingModes.ScoreAttributes: + case ProcessingMode.ScoreAttributes: calc.ProcessLegacyAttributes(beatmap); break; } @@ -168,12 +168,5 @@ protected string CombineSqlConditions(params string?[] conditions) } protected abstract IEnumerable GetBeatmaps(); - - public enum ProcessingModes - { - All, - Difficulty, - ScoreAttributes - } } } diff --git a/osu.Server.DifficultyCalculator/Commands/ProcessingMode.cs b/osu.Server.DifficultyCalculator/Commands/ProcessingMode.cs new file mode 100644 index 0000000..8fd7bdb --- /dev/null +++ b/osu.Server.DifficultyCalculator/Commands/ProcessingMode.cs @@ -0,0 +1,12 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Server.DifficultyCalculator.Commands +{ + public enum ProcessingMode + { + All, + Difficulty, + ScoreAttributes + } +} From a8f2cc7d27a5fe90f431487c635c56eb2541e644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 12 Dec 2023 11:54:47 +0100 Subject: [PATCH 2/3] Extract common method to perform calculation in specified processing mode --- .../Commands/CalculatorCommand.cs | 15 +----------- .../ServerDifficultyCalculator.cs | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs index 84bbc8e..3575c96 100644 --- a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs +++ b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs @@ -92,20 +92,7 @@ public void OnExecute(CommandLineApplication app, IConsole console) // ensure the correct online id is set beatmap.BeatmapInfo.OnlineID = beatmapId; - switch (ProcessingMode) - { - case ProcessingMode.All: - calc.ProcessAll(beatmap); - break; - - case ProcessingMode.Difficulty: - calc.ProcessDifficulty(beatmap); - break; - - case ProcessingMode.ScoreAttributes: - calc.ProcessLegacyAttributes(beatmap); - break; - } + calc.Process(beatmap, ProcessingMode); reporter.Verbose($"Difficulty updated for beatmap {beatmapId}."); } diff --git a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs index d725717..0b7ea16 100644 --- a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs +++ b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs @@ -13,6 +13,7 @@ using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring.Legacy; +using osu.Server.DifficultyCalculator.Commands; namespace osu.Server.DifficultyCalculator { @@ -40,10 +41,26 @@ public ServerDifficultyCalculator(int[]? rulesetIds = null, bool processConverts } } - public void ProcessAll(WorkingBeatmap beatmap) + public void Process(WorkingBeatmap beatmap, ProcessingMode mode) { - ProcessDifficulty(beatmap); - ProcessLegacyAttributes(beatmap); + switch (mode) + { + case ProcessingMode.All: + ProcessDifficulty(beatmap); + ProcessLegacyAttributes(beatmap); + break; + + case ProcessingMode.Difficulty: + ProcessDifficulty(beatmap); + break; + + case ProcessingMode.ScoreAttributes: + ProcessLegacyAttributes(beatmap); + break; + + default: + throw new ArgumentOutOfRangeException(nameof(mode), mode, "Unsupported processing mode supplied"); + } } public void ProcessDifficulty(WorkingBeatmap beatmap) => run(beatmap, processDifficulty); From 3a077373eac7ee69d96cafb34b3cc66fee0f983f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 12 Dec 2023 11:55:12 +0100 Subject: [PATCH 3/3] Allow specifying queue name & scope of calculation in queue processor --- .../BeatmapProcessor.cs | 9 +++++--- osu.Server.Queues.BeatmapProcessor/Program.cs | 21 +++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs b/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs index 27c2a43..10edfbd 100644 --- a/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs +++ b/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs @@ -3,21 +3,24 @@ using Dapper; using osu.Server.DifficultyCalculator; +using osu.Server.DifficultyCalculator.Commands; using osu.Server.QueueProcessor; namespace osu.Server.Queues.BeatmapProcessor { internal class BeatmapProcessor : QueueProcessor { + private readonly ProcessingMode processingMode; private readonly ServerDifficultyCalculator calculator; - public BeatmapProcessor() + public BeatmapProcessor(ProcessingMode processingMode, string queueName) : base(new QueueConfiguration { - InputQueueName = "beatmap", + InputQueueName = queueName, MaxInFlightItems = 4, }) { + this.processingMode = processingMode; calculator = new ServerDifficultyCalculator(new[] { 0, 1, 2, 3 }); } @@ -34,7 +37,7 @@ protected override void ProcessResult(BeatmapItem item) // ensure the correct online id is set working.BeatmapInfo.OnlineID = (int)beatmapId; - calculator.ProcessAll(working); + calculator.Process(working, processingMode); } } } diff --git a/osu.Server.Queues.BeatmapProcessor/Program.cs b/osu.Server.Queues.BeatmapProcessor/Program.cs index ce545c9..5f4864f 100644 --- a/osu.Server.Queues.BeatmapProcessor/Program.cs +++ b/osu.Server.Queues.BeatmapProcessor/Program.cs @@ -1,13 +1,30 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using JetBrains.Annotations; +using McMaster.Extensions.CommandLineUtils; +using osu.Server.DifficultyCalculator.Commands; + namespace osu.Server.Queues.BeatmapProcessor { + [Command] public class Program { - public static void Main(string[] args) + [Argument(0, "mode", "The target mode to process the beatmaps from the queue in.")] + [UsedImplicitly] + private ProcessingMode processingMode { get; } = ProcessingMode.All; + + [Argument(1, "queue-name", "The name of the queue to watch. The `osu-queue:` prefix must be omitted.")] + [UsedImplicitly] + private string queueName { get; } = "beatmap"; + + public static void Main(string[] args) => CommandLineApplication.Execute(args); + + [UsedImplicitly] + public int OnExecute(CommandLineApplication app) { - new BeatmapProcessor().Run(); + new BeatmapProcessor(processingMode, queueName).Run(); + return 0; } } }