mirror of https://github.com/abpframework/abp.git
7 changed files with 59 additions and 22 deletions
@ -1,13 +1,12 @@ |
|||
using Volo.Abp.Data; |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.MongoDB |
|||
{ |
|||
[ConnectionStringName("BackgroundJobs")] |
|||
[ConnectionStringName("AbpBackgroundJobs")] |
|||
public interface IBackgroundJobsMongoDbContext : IAbpMongoDbContext |
|||
{ |
|||
/* Define mongo collections here. Example: |
|||
* IMongoCollection<Question> Questions { get; } |
|||
*/ |
|||
IMongoCollection<BackgroundJobRecord> BackgroundJobs { get; } |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using MongoDB.Driver.Linq; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.Abp.Timing; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.MongoDB |
|||
{ |
|||
public class MongoBackgroundJobRepository : MongoDbRepository<IBackgroundJobsMongoDbContext, BackgroundJobRecord, Guid>, IBackgroundJobRepository |
|||
{ |
|||
protected IClock Clock { get; } |
|||
|
|||
public MongoBackgroundJobRepository( |
|||
IMongoDbContextProvider<IBackgroundJobsMongoDbContext> dbContextProvider, |
|||
IClock clock) |
|||
: base(dbContextProvider) |
|||
{ |
|||
Clock = clock; |
|||
} |
|||
|
|||
public async Task<List<BackgroundJobRecord>> GetWaitingListAsync(int maxResultCount) |
|||
{ |
|||
var now = Clock.Now; |
|||
return await GetMongoQueryable() |
|||
.Where(t => !t.IsAbandoned && t.NextTryTime <= now) |
|||
.OrderByDescending(t => t.Priority) |
|||
.ThenBy(t => t.TryCount) |
|||
.ThenBy(t => t.NextTryTime) |
|||
.Take(maxResultCount) |
|||
.ToListAsync(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue