forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskQueue.cs
More file actions
75 lines (59 loc) · 2.06 KB
/
TaskQueue.cs
File metadata and controls
75 lines (59 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using NUnit.Framework;
using ServiceStack.Common.Extensions;
using ServiceStack.Logging;
using ServiceStack.Text;
namespace ServiceStack.Common.Tests.Models
{
public class TaskQueue
{
private static readonly ILog Log = LogManager.GetLogger(typeof(TaskQueue));
public const string TaskLoad = "Load";
public const string TaskIndex = "Index";
public const string StatusPending = "Pending";
public const string StatusStarted = "Started";
public const string StatusCompleted = "Completed";
public const string StatusFailed = "Failed";
public const int PriorityLow = 0;
public const int PriorityMedium = 1;
public const int PriorityHigh = 2;
public int Id { get; set; }
public Guid? UserId { get; set; }
public string Task { get; set; }
public string ContentUrn { get; set; }
public string Status { get; set; }
public DateTime CreatedDate { get; set; }
public int Priority { get; set; }
public int NoOfAttempts { get; set; }
public string ErrorMessage { get; set; }
public static TaskQueue Create(int id)
{
return new TaskQueue {
ContentUrn = "urn:track:" + id,
CreatedDate = DateTime.Now,
Task = TaskLoad,
Status = StatusPending,
NoOfAttempts = 0,
};
}
public static void AssertIsEqual(TaskQueue actual, TaskQueue expected)
{
Assert.That(actual.Id, Is.EqualTo(expected.Id));
Assert.That(actual.UserId, Is.EqualTo(expected.UserId));
Assert.That(actual.ContentUrn, Is.EqualTo(expected.ContentUrn));
Assert.That(actual.Status, Is.EqualTo(expected.Status));
try
{
Assert.That(actual.CreatedDate, Is.EqualTo(expected.CreatedDate));
}
catch (Exception ex)
{
Log.Error("Trouble with DateTime precisions, trying Assert again with rounding to seconds", ex);
Assert.That(actual.CreatedDate.RoundToSecond(), Is.EqualTo(expected.CreatedDate.RoundToSecond()));
}
Assert.That(actual.Priority, Is.EqualTo(expected.Priority));
Assert.That(actual.NoOfAttempts, Is.EqualTo(expected.NoOfAttempts));
Assert.That(actual.ErrorMessage, Is.EqualTo(expected.ErrorMessage));
}
}
}