Skip to content

Commit b6807b6

Browse files
committed
Merge pull request #55 from airwareic/persistentQueue002
Added the ability to specify maximum # of attempts and age for queued items
2 parents 21c3e99 + 9dfc5b1 commit b6807b6

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

Source/Extras/ExceptionlessSection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ internal class ExceptionlessSection : ConfigurationSection {
1818
[ConfigurationProperty("enableLogging", DefaultValue = null)]
1919
public bool? EnableLogging { get { return (bool?)base["enableLogging"]; } set { base["enableLogging"] = value; } }
2020

21+
[ConfigurationProperty("queueMaxAge", DefaultValue = null)]
22+
public TimeSpan? QueueMaxAge { get { return (TimeSpan?)base["queueMaxAge"]; } set { base["queueMaxAge"] = value; } }
23+
24+
[ConfigurationProperty("queueMaxAttempts", DefaultValue = null)]
25+
public int? QueueMaxAttempts { get { return (int?)base["queueMaxAttempts"]; } set { base["queueMaxAttempts"] = value; } }
26+
2127
[ConfigurationProperty("logPath")]
2228
public string LogPath { get { return base["logPath"] as string; } set { base["logPath"] = value; } }
2329

Source/Extras/Extensions/ExceptionlessExtraConfigurationExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public static void ReadFromConfigSection(this ExceptionlessConfiguration config)
104104
if (section.EnableSSL.HasValue)
105105
config.EnableSSL = section.EnableSSL.Value;
106106

107+
if (section.QueueMaxAge.HasValue)
108+
config.QueueMaxAge = section.QueueMaxAge.Value;
109+
110+
if (section.QueueMaxAttempts.HasValue)
111+
config.QueueMaxAttempts = section.QueueMaxAttempts.Value;
112+
107113
if (!String.IsNullOrEmpty(section.StoragePath))
108114
config.UseFolderStorage(section.StoragePath);
109115

Source/Shared/Configuration/ExceptionlessConfiguration.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class ExceptionlessConfiguration {
1818
private bool _configLocked;
1919
private string _apiKey;
2020
private string _serverUrl;
21+
private TimeSpan _queueMaxAge;
22+
private int _queueMaxAttempts;
2123
private int _submissionBatchSize;
2224
private ValidationResult _validationResult;
2325
private readonly List<string> _exclusions = new List<string>();
@@ -28,6 +30,8 @@ public ExceptionlessConfiguration(IDependencyResolver resolver) {
2830
SubmissionBatchSize = DEFAULT_SUBMISSION_BATCH_SIZE;
2931
Enabled = true;
3032
EnableSSL = true;
33+
QueueMaxAge = TimeSpan.FromDays(7);
34+
QueueMaxAttempts = 3;
3135
DefaultTags = new TagSet();
3236
DefaultData = new DataDictionary();
3337
Settings = new SettingsDictionary();
@@ -100,6 +104,16 @@ public string ApiKey {
100104
[ObsoleteAttribute("This property will be removed in a future release.")]
101105
public bool EnableSSL { get; set; }
102106

107+
/// <summary>
108+
/// Maximum time (provided in days) that the queue will persist events
109+
/// </summary>
110+
public TimeSpan QueueMaxAge { get; set; }
111+
112+
/// <summary>
113+
/// Maximum number of times the client will try to upload an event in the queue
114+
/// </summary>
115+
public int QueueMaxAttempts { get; set; }
116+
103117
/// <summary>
104118
/// A default list of tags that will automatically be added to every report submitted to the server.
105119
/// </summary>

Source/Shared/Extensions/FileStorageExtensions.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ public static void Enqueue(this IObjectStorage storage, string queueName, Event
1212
storage.SaveObject(String.Concat(queueName, "\\q\\", Guid.NewGuid().ToString("N"), ".0.json"), ev);
1313
}
1414

15-
public static void CleanupQueueFiles(this IObjectStorage storage, string queueName, TimeSpan? maxAge = null, int? maxAttempts = 3) {
16-
if (!maxAge.HasValue)
17-
maxAge = TimeSpan.FromDays(1);
18-
19-
if (!maxAttempts.HasValue || maxAttempts.Value <= 0)
20-
maxAttempts = 3;
15+
public static void CleanupQueueFiles(this IObjectStorage storage, string queueName, TimeSpan? maxAge = null, int? maxAttempts = null) {
16+
maxAge = maxAge ?? TimeSpan.FromDays(7);
17+
maxAttempts = maxAttempts ?? 3;
2118

2219
foreach (var file in storage.GetObjectList(queueName + "\\q\\*", 500).ToList()) {
23-
if (file.Created < DateTime.Now.Subtract(maxAge.Value))
20+
if (DateTime.Now.Subtract(file.Created) > maxAge.Value)
2421
storage.DeleteObject(file.Path);
25-
if (GetAttempts(file) >= maxAttempts)
22+
if (GetAttempts(file) >= maxAttempts.Value)
2623
storage.DeleteObject(file.Path);
2724
}
2825
}

Source/Shared/Queue/DefaultEventQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void Process() {
6161
_processingQueue = true;
6262

6363
try {
64-
_storage.CleanupQueueFiles(_config.GetQueueName());
64+
_storage.CleanupQueueFiles(_config.GetQueueName(), _config.QueueMaxAge, _config.QueueMaxAttempts);
6565
_storage.ReleaseStaleLocks(_config.GetQueueName());
6666

6767
DateTime maxCreatedDate = DateTime.Now;

0 commit comments

Comments
 (0)