Browse Source

Merge pull request #14613 from abpframework/auto-merge/rel-6-0/1442

Merge branch dev with rel-6.0
pull/14615/head
Engincan VESKE 4 years ago
committed by GitHub
parent
commit
9ff82dbddf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      docs/en/UI/Angular/DateTime-Format-Pipe.md
  2. 94
      framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs
  3. 80
      framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzBackgroundWorkerManager.cs

3
docs/en/UI/Angular/DateTime-Format-Pipe.md

@ -17,15 +17,18 @@ ShortDate, ShortTime and ShortDateTime format data like angular's data pipe but
<span>{{today | shortDatePipe }}</span> <span>{{today | shortDatePipe }}</span>
``` ```
# ShortTime Pipe # ShortTime Pipe
```html ```html
<span>{{today | shortTimePipe }}</span> <span>{{today | shortTimePipe }}</span>
``` ```
# ShortDateTime Pipe # ShortDateTime Pipe
```html ```html
<span>{{today | shortDateTimePipe }}</span> <span>{{today | shortDateTimePipe }}</span>
``` ```
}%} }%}

94
framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs

@ -12,78 +12,69 @@ using Volo.Abp.Threading;
namespace Volo.Abp.BackgroundWorkers.Hangfire; namespace Volo.Abp.BackgroundWorkers.Hangfire;
[Dependency(ReplaceServices = true)] [Dependency(ReplaceServices = true)]
public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingletonDependency public class HangfireBackgroundWorkerManager : BackgroundWorkerManager, ISingletonDependency
{ {
private AbpHangfireBackgroundJobServer _backgroundJobServer; protected AbpHangfireBackgroundJobServer BackgroundJobServer { get; set; }
private readonly IServiceProvider _serviceProvider; protected IServiceProvider ServiceProvider { get; }
public HangfireBackgroundWorkerManager(IServiceProvider serviceProvider) public HangfireBackgroundWorkerManager(IServiceProvider serviceProvider)
{ {
_serviceProvider = serviceProvider; ServiceProvider = serviceProvider;
} }
public Task StartAsync(CancellationToken cancellationToken = default) public async override Task StartAsync(CancellationToken cancellationToken = default)
{ {
_backgroundJobServer = _serviceProvider.GetRequiredService<AbpHangfireBackgroundJobServer>(); BackgroundJobServer = ServiceProvider.GetRequiredService<AbpHangfireBackgroundJobServer>();
return Task.CompletedTask; await base.StartAsync(cancellationToken);
} }
public Task StopAsync(CancellationToken cancellationToken = default) public async override Task AddAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default)
{ {
return Task.CompletedTask; switch (worker)
}
public Task AddAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default)
{
if (worker is IHangfireBackgroundWorker hangfireBackgroundWorker)
{ {
var unProxyWorker = ProxyHelper.UnProxy(hangfireBackgroundWorker); case IHangfireBackgroundWorker hangfireBackgroundWorker:
if (hangfireBackgroundWorker.RecurringJobId.IsNullOrWhiteSpace())
{ {
RecurringJob.AddOrUpdate(() => ((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(cancellationToken), var unProxyWorker = ProxyHelper.UnProxy(hangfireBackgroundWorker);
hangfireBackgroundWorker.CronExpression, hangfireBackgroundWorker.TimeZone, hangfireBackgroundWorker.Queue); if (hangfireBackgroundWorker.RecurringJobId.IsNullOrWhiteSpace())
}
else
{
RecurringJob.AddOrUpdate(hangfireBackgroundWorker.RecurringJobId, () => ((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(cancellationToken),
hangfireBackgroundWorker.CronExpression, hangfireBackgroundWorker.TimeZone, hangfireBackgroundWorker.Queue);
}
}
else
{
int? period;
if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase)
{
var timer = worker.GetType()
.GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);
if (worker is AsyncPeriodicBackgroundWorkerBase)
{ {
period = ((AbpAsyncTimer)timer)?.Period; RecurringJob.AddOrUpdate(
() => ((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(cancellationToken),
hangfireBackgroundWorker.CronExpression, hangfireBackgroundWorker.TimeZone,
hangfireBackgroundWorker.Queue);
} }
else else
{ {
period = ((AbpTimer)timer)?.Period; RecurringJob.AddOrUpdate(hangfireBackgroundWorker.RecurringJobId,
() => ((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(cancellationToken),
hangfireBackgroundWorker.CronExpression, hangfireBackgroundWorker.TimeZone,
hangfireBackgroundWorker.Queue);
} }
break;
} }
else case AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase:
{ {
return Task.CompletedTask; var timer = worker.GetType()
} .GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);
if (period == null) var period = worker is AsyncPeriodicBackgroundWorkerBase ? ((AbpAsyncTimer)timer)?.Period : ((AbpTimer)timer)?.Period;
{
return Task.CompletedTask;
}
var adapterType = typeof(HangfirePeriodicBackgroundWorkerAdapter<>).MakeGenericType(ProxyHelper.GetUnProxiedType(worker)); if (period == null)
var workerAdapter = Activator.CreateInstance(adapterType) as IHangfireBackgroundWorker; {
return;
}
RecurringJob.AddOrUpdate(() => workerAdapter.DoWorkAsync(cancellationToken), GetCron(period.Value), workerAdapter.TimeZone, workerAdapter.Queue); var adapterType = typeof(HangfirePeriodicBackgroundWorkerAdapter<>).MakeGenericType(ProxyHelper.GetUnProxiedType(worker));
} var workerAdapter = Activator.CreateInstance(adapterType) as IHangfireBackgroundWorker;
return Task.CompletedTask; RecurringJob.AddOrUpdate(() => workerAdapter.DoWorkAsync(cancellationToken), GetCron(period.Value), workerAdapter.TimeZone, workerAdapter.Queue);
break;
}
default:
await base.AddAsync(worker, cancellationToken);
break;
}
} }
protected virtual string GetCron(int period) protected virtual string GetCron(int period)
@ -105,9 +96,10 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle
} }
else else
{ {
throw new AbpException($"Cannot convert period: {period} to cron expression, use HangfireBackgroundWorkerBase to define worker"); throw new AbpException(
$"Cannot convert period: {period} to cron expression, use HangfireBackgroundWorkerBase to define worker");
} }
return cron; return cron;
} }
} }

80
framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzBackgroundWorkerManager.cs

@ -8,78 +8,92 @@ using Volo.Abp.DynamicProxy;
namespace Volo.Abp.BackgroundWorkers.Quartz; namespace Volo.Abp.BackgroundWorkers.Quartz;
[Dependency(ReplaceServices = true)] [Dependency(ReplaceServices = true)]
public class QuartzBackgroundWorkerManager : IBackgroundWorkerManager, ISingletonDependency public class QuartzBackgroundWorkerManager : BackgroundWorkerManager, ISingletonDependency
{ {
private readonly IScheduler _scheduler; protected IScheduler Scheduler { get; }
public QuartzBackgroundWorkerManager(IScheduler scheduler) public QuartzBackgroundWorkerManager(IScheduler scheduler)
{ {
_scheduler = scheduler; Scheduler = scheduler;
} }
public virtual async Task StartAsync(CancellationToken cancellationToken = default) public async override Task StartAsync(CancellationToken cancellationToken = default)
{ {
if (_scheduler.IsStarted && _scheduler.InStandbyMode) if (Scheduler.IsStarted && Scheduler.InStandbyMode)
{ {
await _scheduler.Start(cancellationToken); await Scheduler.Start(cancellationToken);
} }
await base.StartAsync(cancellationToken);
} }
public virtual async Task StopAsync(CancellationToken cancellationToken = default) public async override Task StopAsync(CancellationToken cancellationToken = default)
{ {
if (_scheduler.IsStarted && !_scheduler.InStandbyMode) if (Scheduler.IsStarted && !Scheduler.InStandbyMode)
{ {
await _scheduler.Standby(cancellationToken); await Scheduler.Standby(cancellationToken);
} }
await base.StopAsync(cancellationToken);
} }
public virtual async Task AddAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default) public async override Task AddAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default)
{ {
await ReScheduleJobAsync(worker, cancellationToken); await ReScheduleJobAsync(worker, cancellationToken);
} }
protected virtual async Task ReScheduleJobAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default) protected virtual async Task ReScheduleJobAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default)
{ {
if (worker is IQuartzBackgroundWorker quartzWork) switch (worker)
{ {
Check.NotNull(quartzWork.Trigger, nameof(quartzWork.Trigger)); case IQuartzBackgroundWorker quartzWork:
Check.NotNull(quartzWork.JobDetail, nameof(quartzWork.JobDetail));
if (quartzWork.ScheduleJob != null)
{ {
await quartzWork.ScheduleJob.Invoke(_scheduler); Check.NotNull(quartzWork.Trigger, nameof(quartzWork.Trigger));
Check.NotNull(quartzWork.JobDetail, nameof(quartzWork.JobDetail));
if (quartzWork.ScheduleJob != null)
{
await quartzWork.ScheduleJob.Invoke(Scheduler);
}
else
{
await DefaultScheduleJobAsync(quartzWork, cancellationToken);
}
break;
} }
else case AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase:
{ {
await DefaultScheduleJobAsync(quartzWork, cancellationToken); var adapterType = typeof(QuartzPeriodicBackgroundWorkerAdapter<>).MakeGenericType(ProxyHelper.GetUnProxiedType(worker));
}
}
else
{
var adapterType = typeof(QuartzPeriodicBackgroundWorkerAdapter<>).MakeGenericType(ProxyHelper.GetUnProxiedType(worker));
var workerAdapter = Activator.CreateInstance(adapterType) as IQuartzBackgroundWorkerAdapter; var workerAdapter = Activator.CreateInstance(adapterType) as IQuartzBackgroundWorkerAdapter;
workerAdapter?.BuildWorker(worker); workerAdapter?.BuildWorker(worker);
if (workerAdapter?.Trigger != null) if (workerAdapter?.Trigger != null)
{ {
await DefaultScheduleJobAsync(workerAdapter, cancellationToken); await DefaultScheduleJobAsync(workerAdapter, cancellationToken);
}
break;
} }
default:
await base.AddAsync(worker, cancellationToken);
break;
} }
} }
protected virtual async Task DefaultScheduleJobAsync(IQuartzBackgroundWorker quartzWork, CancellationToken cancellationToken = default) protected virtual async Task DefaultScheduleJobAsync(IQuartzBackgroundWorker quartzWork, CancellationToken cancellationToken = default)
{ {
if (await _scheduler.CheckExists(quartzWork.JobDetail.Key, cancellationToken)) if (await Scheduler.CheckExists(quartzWork.JobDetail.Key, cancellationToken))
{ {
await _scheduler.AddJob(quartzWork.JobDetail, true, true, cancellationToken); await Scheduler.AddJob(quartzWork.JobDetail, true, true, cancellationToken);
await _scheduler.ResumeJob(quartzWork.JobDetail.Key, cancellationToken); await Scheduler.ResumeJob(quartzWork.JobDetail.Key, cancellationToken);
await _scheduler.RescheduleJob(quartzWork.Trigger.Key, quartzWork.Trigger, cancellationToken); await Scheduler.RescheduleJob(quartzWork.Trigger.Key, quartzWork.Trigger, cancellationToken);
} }
else else
{ {
await _scheduler.ScheduleJob(quartzWork.JobDetail, quartzWork.Trigger, cancellationToken); await Scheduler.ScheduleJob(quartzWork.JobDetail, quartzWork.Trigger, cancellationToken);
} }
} }
} }

Loading…
Cancel
Save