Repository navigation
Add assembly-wide defaults for job tags and execution settings #225
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
400c76b
Support assembly-wide job defaults with explicit per-job overrides
viceroypenguin 2b9f231
Support assembly defaults on the older Roslyn targets
viceroypenguin fd64783
Reuse tag parsing and analyze job defaults on attributes
viceroypenguin d0275e1
Better organization
viceroypenguin 939c7d7
Document explicit job overrides and assembly default precedence
viceroypenguin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using System.Collections.Immutable; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.Diagnostics; | ||
| using Microsoft.CodeAnalysis.Operations; | ||
|
|
||
| namespace Immediate.Jobs.Analyzers; | ||
|
|
||
| [DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
| public sealed class JobDefaultsAnalyzer : DiagnosticAnalyzer | ||
| { | ||
| public static readonly DiagnosticDescriptor InvalidJobDefaults = | ||
| new( | ||
| id: DiagnosticIds.IJOB0017JobDefaultsInvalid, | ||
| title: "Job Defaults Invalid", | ||
| messageFormat: "Invalid job defaults: {0}", | ||
| category: "ImmediateJobs", | ||
| defaultSeverity: DiagnosticSeverity.Error, | ||
| isEnabledByDefault: true, | ||
| customTags: [WellKnownDiagnosticTags.NotConfigurable] | ||
| ); | ||
|
|
||
| public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create([InvalidJobDefaults]); | ||
|
|
||
| public override void Initialize(AnalysisContext context) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(context); | ||
|
|
||
| context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); | ||
| context.EnableConcurrentExecution(); | ||
|
|
||
| context.RegisterOperationAction(AnalyzeDefaults, OperationKind.Attribute); | ||
| } | ||
|
|
||
| private static void AnalyzeDefaults(OperationAnalysisContext context) | ||
| { | ||
| context.CancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
| if (context.Operation is not IAttributeOperation { Operation: IObjectCreationOperation { Type.IsJobDefaultsAttribute: true } }) | ||
| return; | ||
|
|
||
| var syntax = context.Operation.Syntax; | ||
|
|
||
| var attribute = context.Compilation.Assembly.GetAttributes() | ||
| .FirstOrDefault( | ||
| attribute => | ||
| attribute.ApplicationSyntaxReference is { } reference | ||
| && reference.SyntaxTree == syntax.SyntaxTree | ||
| && reference.Span == syntax.Span | ||
| ); | ||
|
|
||
| if (attribute is null) | ||
| return; | ||
|
|
||
| foreach (var error in attribute.GetJobDefaultsErrors()) | ||
| context.ReportDiagnostic(Diagnostic.Create(InvalidJobDefaults, syntax.GetLocation(), error)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| namespace Immediate.Jobs.Shared; | ||
|
|
||
| /// <summary> | ||
| /// Supplies defaults for generated jobs declared in this assembly. Explicit job settings override these values. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Only explicitly supplied settings become assembly defaults. Unspecified settings use the built-in job defaults. | ||
| /// </remarks> | ||
| [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] | ||
| public sealed class JobDefaultsAttribute : Attribute | ||
| { | ||
| /// <summary> | ||
| /// The routing tags inherited by jobs that omit a tag list. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Null or empty lists use the default tag. Explicit job tag lists, including null or empty lists, override these tags. | ||
| /// </remarks> | ||
| [NotNull] | ||
| public string[]? Tags { get; init => field = [.. JobTags.Normalize(value)]; } | ||
|
|
||
| /// <summary> | ||
| /// The default time-zone identifier. A null value uses UTC. | ||
| /// </summary> | ||
| public string? TimeZone { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The default total execution attempts, including the first attempt. | ||
| /// </summary> | ||
| public int MaxAttempts { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The default execution timeout as a TimeSpan string, or null for no timeout. | ||
| /// </summary> | ||
| public string? Timeout { get; init; } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.