Browse Source

Merge branch 'dev' into localization-v7

pull/13845/head
Halil İbrahim Kalkan 4 years ago
parent
commit
28014c90f9
  1. 35
      docs/en/Background-Jobs-Hangfire.md
  2. 35
      docs/zh-Hans/Background-Jobs-Hangfire.md
  3. 26
      framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/HangfireBackgroundJobManager.cs
  4. 4
      framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/HangfireJobExecutionAdapter.cs
  5. 23
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/BranchGithubVersionProvider.cs

35
docs/en/Background-Jobs-Hangfire.md

@ -80,6 +80,41 @@ After you have installed these NuGet packages, you need to configure your projec
}
````
### Specifying Queue
You can use the [`QueueAttribute`](https://docs.hangfire.io/en/latest/background-processing/configuring-queues.html) to specify the queue.
````csharp
using System.Threading.Tasks;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Emailing;
namespace MyProject
{
[Queue("alpha")]
public class EmailSendingJob
: AsyncBackgroundJob<EmailSendingArgs>, ITransientDependency
{
private readonly IEmailSender _emailSender;
public EmailSendingJob(IEmailSender emailSender)
{
_emailSender = emailSender;
}
public override async Task ExecuteAsync(EmailSendingArgs args)
{
await _emailSender.SendAsync(
args.EmailAddress,
args.Subject,
args.Body
);
}
}
}
````
### Dashboard Authorization
Hangfire Dashboard provides information about your background jobs, including method names and serialized arguments as well as gives you an opportunity to manage them by performing different actions – retry, delete, trigger, etc. So it is important to restrict access to the Dashboard.

35
docs/zh-Hans/Background-Jobs-Hangfire.md

@ -66,6 +66,41 @@ public class YourModule : AbpModule
}
````
### 指定队列
你可以使用 [`QueueAttribute`](https://docs.hangfire.io/en/latest/background-processing/configuring-queues.html) 来指定队列.
````csharp
using System.Threading.Tasks;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Emailing;
namespace MyProject
{
[Queue("alpha")]
public class EmailSendingJob
: AsyncBackgroundJob<EmailSendingArgs>, ITransientDependency
{
private readonly IEmailSender _emailSender;
public EmailSendingJob(IEmailSender emailSender)
{
_emailSender = emailSender;
}
public override async Task ExecuteAsync(EmailSendingArgs args)
{
await _emailSender.SendAsync(
args.EmailAddress,
args.Subject,
args.Body
);
}
}
}
````
1. 如果你想要使用Hangfire的面板,你可以在 `Module` 类的 `OnApplicationInitialization` 方法添加: `UseHangfireDashboard`
````csharp

26
framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/HangfireBackgroundJobManager.cs

@ -1,6 +1,9 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using Hangfire;
using Hangfire.States;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.BackgroundJobs.Hangfire;
@ -8,16 +11,35 @@ namespace Volo.Abp.BackgroundJobs.Hangfire;
[Dependency(ReplaceServices = true)]
public class HangfireBackgroundJobManager : IBackgroundJobManager, ITransientDependency
{
protected AbpBackgroundJobOptions Options { get; }
public HangfireBackgroundJobManager(IOptions<AbpBackgroundJobOptions> options)
{
Options = options.Value;
}
public virtual Task<string> EnqueueAsync<TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal,
TimeSpan? delay = null)
{
return Task.FromResult(delay.HasValue
? BackgroundJob.Schedule<HangfireJobExecutionAdapter<TArgs>>(
adapter => adapter.ExecuteAsync(args),
adapter => adapter.ExecuteAsync(GetQueueName(typeof(TArgs)),args),
delay.Value
)
: BackgroundJob.Enqueue<HangfireJobExecutionAdapter<TArgs>>(
adapter => adapter.ExecuteAsync(args)
adapter => adapter.ExecuteAsync(GetQueueName(typeof(TArgs)) ,args)
));
}
protected virtual string GetQueueName(Type argsType)
{
var queueName = EnqueuedState.DefaultQueue;
var queueAttribute = Options.GetJob(argsType).JobType.GetCustomAttribute<QueueAttribute>();
if (queueAttribute != null)
{
queueName = queueAttribute.Queue;
}
return queueName;
}
}

4
framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/HangfireJobExecutionAdapter.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Hangfire;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
@ -20,7 +21,8 @@ public class HangfireJobExecutionAdapter<TArgs>
Options = options.Value;
}
public async Task ExecuteAsync(TArgs args)
[Queue("{0}")]
public async Task ExecuteAsync(string queue, TArgs args)
{
if (!Options.IsJobExecutionEnabled)
{

23
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/BranchGithubVersionProvider.cs

@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Octokit;
using Octokit.Internal;
using Volo.Abp;
using Volo.Abp.DependencyInjection;
namespace Volo.Docs.GitHub.Documents.Version
@ -12,10 +14,25 @@ namespace Volo.Docs.GitHub.Documents.Version
{
public async Task<List<GithubVersion>> GetVersions(string name, string repositoryName, string token)
{
var client = GetGitHubClient(name, token);
var branches = await client.Repository.Branch.GetAll(name, repositoryName);
try
{
var client = GetGitHubClient(name, token);
var branches = await client.Repository.Branch.GetAll(name, repositoryName);
return branches.Select(b => new GithubVersion {Name = b.Name}).ToList();
return branches.Select(b => new GithubVersion { Name = b.Name }).ToList();
}
catch (Exception e)
{
var apiException = (Octokit.ApiException)e;
if (apiException.ApiError?.Message == "Bad credentials" ||
apiException.StatusCode == HttpStatusCode.Unauthorized)
{
throw new AbpException("Invalid credentials for the GitHub repository: " + name + "/" + repositoryName + ". " +
"The GitHub access token: " + token + " does not work!" + "\n\rError: " + e);
}
throw new AbpException("Could not get branches from GitHub repository: " + name + "/" + repositoryName + "\n\rError: " + e.Message);
}
}
private static GitHubClient GetGitHubClient(string name, string token)

Loading…
Cancel
Save