-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueueApi.cs
78 lines (63 loc) · 2.38 KB
/
QueueApi.cs
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
76
77
78
using System;
using System.Collections.Generic;
using System.Linq;
using Composite;
using Hangfire.CompositeC1.Entities;
using Hangfire.CompositeC1.Types;
namespace Hangfire.CompositeC1
{
public class QueueApi
{
private readonly CompositeC1Storage _storage;
public QueueApi(CompositeC1Storage storage)
{
Verify.ArgumentNotNull(storage, "storage");
_storage = storage;
}
public IEnumerable<string> GetQueues()
{
return _storage.UseConnection(connection =>
{
return connection.Get<IJobQueue>().Select(j => j.Queue).Distinct();
});
}
public IEnumerable<Guid> GetEnqueuedJobIds(string queue, int from, int perPage)
{
return _storage.UseConnection(connection =>
{
var queues = connection.Get<IJobQueue>();
var jobIds = (from q in queues
where q.Queue == queue
select q.JobId).Skip(from).Take(perPage).ToList();
return jobIds;
});
}
public IEnumerable<Guid> GetFetchedJobIds(string queue, int from, int perPage)
{
return _storage.UseConnection(connection =>
{
var jobs = connection.Get<IJob>();
var queues = connection.Get<IJobQueue>();
var ids = (from q in queues
join j in jobs on q.JobId equals j.Id
where q.Queue == queue && q.FetchedAt.HasValue
select j.Id).Skip(from).Take(perPage).ToList();
return ids;
});
}
public EnqueuedAndFetchedCountDto GetEnqueuedAndFetchedCount(string queue)
{
return _storage.UseConnection(connection =>
{
var jobs = connection.Get<IJobQueue>().Where(q => q.Queue == queue);
var fetchedCount = jobs.Count(q => q.FetchedAt.HasValue);
var enqueuedCount = jobs.Count(q => !q.FetchedAt.HasValue);
return new EnqueuedAndFetchedCountDto
{
EnqueuedCount = enqueuedCount,
FetchedCount = fetchedCount
};
});
}
}
}