-
Notifications
You must be signed in to change notification settings - Fork 6
Add DisplayName functionality #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Linq.Expressions; | ||
| using System.Reflection; | ||
| using System.Threading.Tasks; | ||
| using Hangfire.Annotations; | ||
| using Hangfire.Common; | ||
|
|
@@ -138,11 +139,28 @@ private static Job ToDynamicJob([NotNull] Job job, [CanBeNull] IEnumerable<JobFi | |
| if (job == null) throw new ArgumentNullException(nameof(job)); | ||
|
|
||
| var invocationData = InvocationData.SerializeJob(job); | ||
|
|
||
| //get display name form original job | ||
| var jobDisplayNameAttribute = job.Method.GetCustomAttributes<JobDisplayNameAttribute>(inherit: true).FirstOrDefault(); | ||
| //TODO: maybe is better resolve name here and serialize as string? | ||
|
|
||
| //get queue filter from original job | ||
| //// Job.Method.GetMethodFilterAttributes() inaccessibile | ||
| //// ReflectedAttributeCache.GetMethodFilterAttributes(job.Method); inaccessible | ||
| var typeFiltes = job.Type.GetTypeInfo().GetCustomAttributes(typeof(QueueAttribute), inherit: true).Cast<QueueAttribute>(); | ||
| var methodFiltes = job.Method.GetCustomAttributes(typeof(QueueAttribute), inherit: true).Cast<QueueAttribute>(); | ||
|
|
||
| //generate list of filters for dynamicjob | ||
| var dynamicfilters = new List<JobFilterAttribute>(filters?.ToArray() ?? Enumerable.Empty<JobFilterAttribute>()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should concentrate on description only in this pull request. Automatic filter attribute acquisition is great, but it has some gotchas – since arguments (or their types) of a target method can be unavailable at runtime, this solution will have a lot of limitations. Currently |
||
| dynamicfilters.AddRange(typeFiltes); | ||
| dynamicfilters.AddRange(methodFiltes); | ||
|
|
||
| var dynamicJob = new DynamicJob(invocationData.Type, | ||
| invocationData.Method, | ||
| !String.IsNullOrEmpty(invocationData.ParameterTypes) ? invocationData.ParameterTypes : null, | ||
| invocationData.Arguments, | ||
| filters?.ToArray()); | ||
| dynamicfilters?.ToArray(), | ||
| jobDisplayNameAttribute); | ||
|
|
||
| return Job.FromExpression(() => DynamicJob.Execute(dynamicJob, default)); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should expose the
DisplayNameproperty as astringone and calculate its value when creating a dynamic job. Such descriptions are often based on argument values (by using placeholders like{0}passed to theString.Formatmethod), and since argument types can be unavailable at runtime, we shouldn't depend on them.