Skip to content

Commit f788d1b

Browse files
committed
Refactor queue commands
1 parent 8249eab commit f788d1b

File tree

3 files changed

+35
-30
lines changed

3 files changed

+35
-30
lines changed

src/InEngine.Core/Queue/Commands/ClearAll.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using CommandLine;
2+
using InEngine.Core.Exceptions;
3+
4+
namespace InEngine.Core.Queue.Commands
5+
{
6+
public class Flush : AbstractCommand
7+
{
8+
[Option("pending", HelpText = "Clear the pending queue.")]
9+
public bool ClearPendingQueue { get; set; }
10+
11+
[Option("failed", HelpText = "Clear the failed queue.")]
12+
public bool ClearFailedQueue { get; set; }
13+
14+
[Option("in-progress", HelpText = "Clear the in-progress queue.")]
15+
public bool ClearInProgressQueue { get; set; }
16+
17+
[Option("secondary", HelpText = "Clear secondary queues. Primary queues are cleared by default.")]
18+
public bool UseSecondaryQueue { get; set; }
19+
20+
public override void Run()
21+
{
22+
if (ClearPendingQueue == false && ClearFailedQueue == false && ClearInProgressQueue == false)
23+
throw new CommandFailedException("Must specify at least one queue to clear. Use -h to see available options.");
24+
var broker = Broker.Make(UseSecondaryQueue);
25+
if (ClearPendingQueue)
26+
Info($"Pending: {broker.ClearPendingQueue().ToString()}");
27+
if (ClearInProgressQueue)
28+
Info($"In-progress: {broker.ClearInProgressQueue().ToString()}");
29+
if (ClearFailedQueue)
30+
Info($"Failed: {broker.ClearFailedQueue().ToString()}");
31+
}
32+
}
33+
}

src/InEngine.Core/Queue/Options.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class Options : IOptions
1515
[VerbOption("queue:length", HelpText = "Get the number of messages in the primary and secondary queues.")]
1616
public Length Length { get; set; }
1717

18-
[VerbOption("queue:clear", HelpText = "Clear the primary or secondary queues, and optionally.")]
19-
public ClearAll ClearAll { get; set; }
18+
[VerbOption("queue:flush", HelpText = "Clear the primary or secondary queues, and optionally.")]
19+
public Flush Flush { get; set; }
2020

2121
[VerbOption("queue:republish", HelpText = "Republish failed messages to the queue.")]
2222
public RepublishFailed RepublishFailed { get; set; }

0 commit comments

Comments
 (0)