AnderssonPeter / Hangfire.Console.Extensions

Makes it easier to use Hangfire.Console with .net core dependency injection
MIT License
81 stars 17 forks source link

Some minor Questions/Confirmations #7

Closed sommmen closed 3 years ago

sommmen commented 3 years ago

Hiya,

I personally use the following interface to build jobs on:

    /// <summary>
    /// A rather empty base for options passed to a <see cref="IJob{TOptions}"/>
    /// NOTE When dealing with options note that the options class you use will be a DTO.
    ///      Json is used to serialize the class to a string and then it will be stored in the db.
    /// NOTE Interfaces or abstract classes are not supported! This means you can only use plain c# classes - keep this in mind. This includes valuetuples.
    /// </summary>
    [Serializable]
    public class JobOptionsBase
    {
    }

    public interface IJob<in TOptions> 
        where TOptions : JobOptionsBase, new()
    {
        public Task Run(PerformContext context, CancellationToken token, TOptions jobOptions = default);
    }

If i were to use this library, from what i can gather, i would need to change that interface and take out the Performcontext context and inject it in the constructor instead. Perhaps the same for the cancellationtoken.

Or could i leave this as - is?

Also in this sample i don't see a call to c.UseConsole(); in the startup, which adds the hangfire.console services. I also don't see this added in theAddHangfireConsoleExtensions` method - do i not need to call hangfire.console anymore?

This also uses GlobalJobFilters.Filters.Add(new HangfireSubscriber()); `

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHangfire((serviceProvider, configuration) => configuration
                .UseConsole()
                .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                .UseSimpleAssemblyNameTypeSerializer()
                .UseRecommendedSerializerSettings()
                //.UseSqlServerStorage(@"Server=(localdb)\MSSQLLocalDB;Integrated Security=true;"));
                .UseMemoryStorage());
            services.AddHangfireConsoleExtensions();
            services.AddHangfireServer();

            services.AddTransient<SampleJob>();
            services.AddTransient<ContinuationJob>();
        }

https://github.com/AnderssonPeter/Hangfire.Console.Extensions/blob/master/SampleWithSerilog/Startup.cs

AnderssonPeter commented 3 years ago

Hi, both would be a valid option, and you should do what seems most logical to you, its not like one is better or worse than the other.. its more what is logical in your case.

There is a call to .UseConsole() https://github.com/AnderssonPeter/Hangfire.Console.Extensions/blob/dc6f7d5261f7117b790ec504a8df424e3f128cca/SampleWithSerilog/Startup.cs#L24