Skip to content
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

No way to use base class for a job #4

Open
alex-training opened this issue Sep 14, 2017 · 1 comment
Open

No way to use base class for a job #4

alex-training opened this issue Sep 14, 2017 · 1 comment

Comments

@alex-training
Copy link

alex-training commented Sep 14, 2017

Hi @icsharp !

As long as there is no ExecuteAsync method support (hope yet) I tried to create a base class for my jobs.

    public abstract class BaseRecurringJob : IRecurringJob
    {
        public void Execute(PerformContext context)
        {
            ExecuteAsync(context).GetAwaiter().GetResult();
        }

        protected virtual Task ExecuteAsync(PerformContext context) => Task.CompletedTask;
    }

After that all my jobs can be used like so:
public class HealthCheckRecurringJob: BaseRecurringJob

There is a problem that a Hangfire JobActivator tries to create my base abstract class instead of using child class.

As I can see there is something wrong with this line:
option.JobType.GetMethod(nameof(IRecurringJob.Execute));

var addOrUpdate = Expression.Call(
				typeof(RecurringJob),
				nameof(RecurringJob.AddOrUpdate),
				new Type[] { method.DeclaringType },
				new Expression[]
				{
					Expression.Constant(recurringJobId),
					Expression.Lambda(methodCall, x),
					Expression.Constant(cron),
					Expression.Constant(timeZone),
					Expression.Constant(queue)
				});

Could you please try to fix this issue?

Br, Alex

@alex-training
Copy link
Author

In two words I would like to do something like that:
https://www.codeproject.com/Tips/399786/Quartz-Net-Custom-Base-Job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants