Background job remove sync api

pull/2464/head
Halil İbrahim Kalkan 5 years ago
parent f0ae994848
commit d332818f6a

@ -36,7 +36,7 @@ namespace Volo.Abp.BackgroundJobs
{
var store = scope.ServiceProvider.GetRequiredService<IBackgroundJobStore>();
var waitingJobs = store.GetWaitingJobs(WorkerOptions.MaxJobFetchCount);
var waitingJobs = AsyncHelper.RunSync(() => store.GetWaitingJobsAsync(WorkerOptions.MaxJobFetchCount));
if (!waitingJobs.Any())
{
@ -62,7 +62,7 @@ namespace Volo.Abp.BackgroundJobs
{
jobExecuter.Execute(context);
store.Delete(jobInfo.Id);
AsyncHelper.RunSync(() => store.DeleteAsync(jobInfo.Id));
}
catch (BackgroundJobExecutionException)
{
@ -94,7 +94,7 @@ namespace Volo.Abp.BackgroundJobs
{
try
{
store.Update(jobInfo);
AsyncHelper.RunSync(() => store.UpdateAsync(jobInfo));
}
catch (Exception updateEx)
{

@ -9,13 +9,6 @@ namespace Volo.Abp.BackgroundJobs
/// </summary>
public interface IBackgroundJobStore
{
/// <summary>
/// Gets a BackgroundJobInfo based on the given jobId.
/// </summary>
/// <param name="jobId">The Job Unique Identifier.</param>
/// <returns>The BackgroundJobInfo object.</returns>
BackgroundJobInfo Find(Guid jobId);
/// <summary>
/// Gets a BackgroundJobInfo based on the given jobId.
/// </summary>
@ -23,27 +16,12 @@ namespace Volo.Abp.BackgroundJobs
/// <returns>The BackgroundJobInfo object.</returns>
Task<BackgroundJobInfo> FindAsync(Guid jobId);
/// <summary>
/// Inserts a background job.
/// </summary>
/// <param name="jobInfo">Job information.</param>
void Insert(BackgroundJobInfo jobInfo);
/// <summary>
/// Inserts a background job.
/// </summary>
/// <param name="jobInfo">Job information.</param>
Task InsertAsync(BackgroundJobInfo jobInfo);
/// <summary>
/// Gets waiting jobs. It should get jobs based on these:
/// Conditions: !IsAbandoned And NextTryTime &lt;= Clock.Now.
/// Order by: Priority DESC, TryCount ASC, NextTryTime ASC.
/// Maximum result: <paramref name="maxResultCount"/>.
/// </summary>
/// <param name="maxResultCount">Maximum result count.</param>
List<BackgroundJobInfo> GetWaitingJobs(int maxResultCount);
/// <summary>
/// Gets waiting jobs. It should get jobs based on these:
/// Conditions: !IsAbandoned And NextTryTime &lt;= Clock.Now.
@ -53,24 +31,12 @@ namespace Volo.Abp.BackgroundJobs
/// <param name="maxResultCount">Maximum result count.</param>
Task<List<BackgroundJobInfo>> GetWaitingJobsAsync(int maxResultCount);
/// <summary>
/// Deletes a job.
/// </summary>
/// <param name="jobId">The Job Unique Identifier.</param>
void Delete(Guid jobId);
/// <summary>
/// Deletes a job.
/// </summary>
/// <param name="jobId">The Job Unique Identifier.</param>
Task DeleteAsync(Guid jobId);
/// <summary>
/// Updates a job.
/// </summary>
/// <param name="jobInfo">Job information.</param>
void Update(BackgroundJobInfo jobInfo);
/// <summary>
/// Updates a job.
/// </summary>

@ -20,13 +20,6 @@ namespace Volo.Abp.BackgroundJobs
BackgroundJobRepository = backgroundJobRepository;
}
public BackgroundJobInfo Find(Guid jobId)
{
return ObjectMapper.Map<BackgroundJobRecord, BackgroundJobInfo>(
BackgroundJobRepository.Find(jobId)
);
}
public virtual async Task<BackgroundJobInfo> FindAsync(Guid jobId)
{
return ObjectMapper.Map<BackgroundJobRecord, BackgroundJobInfo>(
@ -34,13 +27,6 @@ namespace Volo.Abp.BackgroundJobs
);
}
public void Insert(BackgroundJobInfo jobInfo)
{
BackgroundJobRepository.Insert(
ObjectMapper.Map<BackgroundJobInfo, BackgroundJobRecord>(jobInfo)
);
}
public virtual async Task InsertAsync(BackgroundJobInfo jobInfo)
{
await BackgroundJobRepository.InsertAsync(
@ -62,28 +48,11 @@ namespace Volo.Abp.BackgroundJobs
);
}
public void Delete(Guid jobId)
{
BackgroundJobRepository.Delete(jobId);
}
public virtual async Task DeleteAsync(Guid jobId)
{
await BackgroundJobRepository.DeleteAsync(jobId);
}
public void Update(BackgroundJobInfo jobInfo)
{
var backgroundJobRecord = BackgroundJobRepository.Find(jobInfo.Id);
if (backgroundJobRecord == null)
{
return;
}
ObjectMapper.Map(jobInfo, backgroundJobRecord);
BackgroundJobRepository.Update(backgroundJobRecord);
}
public virtual async Task UpdateAsync(BackgroundJobInfo jobInfo)
{
var backgroundJobRecord = await BackgroundJobRepository.FindAsync(jobInfo.Id);

@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.BackgroundJobs
{
@ -28,9 +29,9 @@ namespace Volo.Abp.BackgroundJobs
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
AsyncHelper.RunSync(() => scope.ServiceProvider
.GetRequiredService<BackgroundJobsTestDataBuilder>()
.Build();
.BuildAsync());
}
}
}

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Timing;
@ -20,9 +21,9 @@ namespace Volo.Abp.BackgroundJobs
_clock = clock;
}
public void Build()
public async Task BuildAsync()
{
_backgroundJobRepository.Insert(
await _backgroundJobRepository.InsertAsync(
new BackgroundJobRecord(_testData.JobId1)
{
JobName = "TestJobName",
@ -36,7 +37,7 @@ namespace Volo.Abp.BackgroundJobs
}
);
_backgroundJobRepository.Insert(
await _backgroundJobRepository.InsertAsync(
new BackgroundJobRecord(_testData.JobId2)
{
JobName = "TestJobName",
@ -50,7 +51,7 @@ namespace Volo.Abp.BackgroundJobs
}
);
_backgroundJobRepository.Insert(
await _backgroundJobRepository.InsertAsync(
new BackgroundJobRecord(_testData.JobId3)
{
JobName = "TestJobName",

Loading…
Cancel
Save