Skip to content

Commit f44ae6d

Browse files
committed
Add logging to queue clients
1 parent 67cbd15 commit f44ae6d

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

src/InEngine.Core/Queuing/Clients/FileClient.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading;
6-
using System.Threading.Tasks;
76
using InEngine.Core.Exceptions;
7+
using InEngine.Core.Logging;
88
using InEngine.Core.Queuing.Message;
99

1010
namespace InEngine.Core.Queuing.Clients
1111
{
1212
public class FileClient : IQueueClient
1313
{
14+
public ILog Log { get; set; } = new Log();
1415
public int Id { get; set; } = 0;
1516
public string QueueBaseName { get; set; }
1617
public string QueueName { get; set; }
@@ -72,13 +73,14 @@ public void Consume(CancellationToken cancellationToken)
7273
cancellationToken.ThrowIfCancellationRequested();
7374
}
7475
}
75-
catch (OperationCanceledException)
76+
catch (OperationCanceledException exception)
7677
{
78+
Log.Debug(exception);
7779
return;
7880
}
7981
catch (Exception exception)
8082
{
81-
Console.WriteLine(exception.Message);
83+
Log.Error(exception);
8284
}
8385
}
8486

@@ -96,9 +98,10 @@ public ICommandEnvelope Consume()
9698
{
9799
fileInfo.MoveTo(inProgressFilePath);
98100
}
99-
catch (FileNotFoundException)
101+
catch (FileNotFoundException exception)
100102
{
101103
// Another process probably consumed the file when it was read and moved.
104+
Log.Debug(exception);
102105
return null;
103106
}
104107

@@ -114,6 +117,7 @@ public ICommandEnvelope Consume()
114117
}
115118
catch (Exception exception)
116119
{
120+
Log.Error(exception);
117121
if (command.CommandLifeCycle.ShouldRetry())
118122
File.Move(inProgressFilePath, Path.Combine(PendingQueuePath, fileInfo.Name));
119123
else
@@ -127,6 +131,7 @@ public ICommandEnvelope Consume()
127131
}
128132
catch (Exception exception)
129133
{
134+
Log.Error(exception);
130135
throw new CommandFailedException("Failed to move command from in-progress queue.", exception);
131136
}
132137

src/InEngine.Core/Queuing/Clients/RedisClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using InEngine.Core.Exceptions;
7+
using InEngine.Core.Logging;
78
using InEngine.Core.Queuing.Message;
89
using StackExchange.Redis;
910

1011
namespace InEngine.Core.Queuing.Clients
1112
{
1213
public class RedisClient : IQueueClient
1314
{
15+
public ILog Log { get; set; } = new Log();
1416
public int Id { get; set; } = 0;
1517
public string QueueBaseName { get; set; } = "InEngineQueue";
1618
public string QueueName { get; set; } = "Primary";
@@ -78,13 +80,14 @@ public void Consume(CancellationToken cancellationToken)
7880
Task.Factory.StartNew(Consume, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);
7981
});
8082
}
81-
catch (OperationCanceledException)
83+
catch (OperationCanceledException exception)
8284
{
85+
Log.Debug(exception);
8386
return;
8487
}
8588
catch (Exception exception)
8689
{
87-
Console.WriteLine(exception.Message);
90+
Log.Error(exception);
8891
}
8992
}
9093

@@ -108,6 +111,7 @@ public ICommandEnvelope Consume()
108111
}
109112
catch (Exception exception)
110113
{
114+
Log.Error(exception);
111115
Redis.ListRemove(InProgressQueueName, serializedMessage, 1);
112116
if (command.CommandLifeCycle.ShouldRetry())
113117
Redis.ListLeftPush(PendingQueueName, commandEnvelope.SerializeToJson());
@@ -124,6 +128,7 @@ public ICommandEnvelope Consume()
124128
}
125129
catch (Exception exception)
126130
{
131+
Log.Error(exception);
127132
throw new CommandFailedException($"Failed to remove completed commandEnvelope from queue: {InProgressQueueName}", exception);
128133
}
129134

src/InEngine.Core/Queuing/Clients/SyncClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Threading;
4+
using InEngine.Core.Logging;
45
using InEngine.Core.Queuing.Message;
56

67
namespace InEngine.Core.Queuing.Clients
78
{
89
public class SyncClient : IQueueClient
910
{
11+
public ILog Log { get; set; } = new Log();
1012
public int Id { get; set; } = 0;
1113
public string QueueBaseName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
1214
public string QueueName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

src/InEngine.Core/Queuing/Dequeue.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task StartAsync()
2424
{
2525
if (QueueSettings == null)
2626
QueueSettings = InEngineSettings.Make().Queue;
27-
27+
2828
var allTasks = new List<Task>();
2929
Log.Debug("Start dequeue tasks for primary queue...");
3030
allTasks.AddRange(MakeTasks(true, QueueSettings.PrimaryQueueConsumers));
@@ -44,6 +44,7 @@ IList<Task> MakeTasks(bool useSecondaryQueue = false, int numberOfTasks = 0)
4444
return Task.Factory.StartNew(() => {
4545
var queue = QueueAdapter.Make(useSecondaryQueue, QueueSettings);
4646
queue.Id = i;
47+
queue.Log = Log;
4748
queueAdapters.Add(queue);
4849
queue.Consume(CancellationTokenSource.Token);
4950
}, TaskCreationOptions.LongRunning);

src/InEngine.Core/Queuing/IQueueClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System.Collections.Generic;
22
using System.Threading;
3+
using InEngine.Core.Logging;
34
using InEngine.Core.Queuing.Message;
45

56
namespace InEngine.Core.Queuing
67
{
78
public interface IQueueClient
89
{
10+
ILog Log { get; set; }
911
int Id { get; set; }
1012
string QueueBaseName { get; set; }
1113
string QueueName { get; set; }

src/InEngine.Core/Queuing/QueueAdapter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Reflection;
43
using System.Threading;
54
using InEngine.Core.Exceptions;
5+
using InEngine.Core.Logging;
66
using InEngine.Core.Queuing.Clients;
77
using InEngine.Core.Queuing.Message;
88

99
namespace InEngine.Core.Queuing
1010
{
1111
public class QueueAdapter : IQueueClient
1212
{
13+
public ILog Log { get; set; } = new Log();
1314
public int Id { get { return QueueClient.Id; } set { QueueClient.Id = value; } }
1415
public IQueueClient QueueClient { get; set; }
1516
public string QueueBaseName { get => QueueClient.QueueBaseName; set => QueueClient.QueueBaseName = value; }

0 commit comments

Comments
 (0)