You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in all of my job i need to call a method. the method call an api in order to get a private key and check whether the expiration time is expired. this method should be called in all of my jobs.
i think there should be a base class that common logic is put and when job inherited from that base class they call this method so there is no duplication code in my jobs. on top of that, i need to log in all of my jobs is it better that quartz provide some thing for cross-cutting concerns.
here is my code:
[DisallowConcurrentExecution]
public class AddAccountDataBackgroundJob : IJob
{
#region Field
private readonly ISender _mediator;
private readonly ILoggerProvider<AddAccountDataBackgroundJob> _logger;
#endregion
public AddAccountDataBackgroundJob(ISender mediator, ILoggerProvider<AddAccountDataBackgroundJob> logger)
{
_mediator = mediator;
_logger = logger;
}
public async Task Execute(IJobExecutionContext context)
{
_logger.Information(context.JobDetail.Key, nameof(Execute), string.Empty);
await _mediator.Send(new AddAccountDataCommand(), CancellationToken.None).ConfigureAwait(false);
}
}
using Holoo.Framework.Component.Loggers;
using Holoo.Local.Transfer.Service.Application.Account.Command.ApiGateway.UpdateAccount;
using Holoo.Local.Transfer.Service.Application.PrivateKey.Query.GetPrivateKey;
using MediatR;
using Quartz;
namespace Holoo.Local.Transfer.Service.Application.Component.BackgroundJobs.AccountBackgroundJobs;
[DisallowConcurrentExecution]
public class UpdateAccountDataBackgroundJob : IJob
{
#region Field
private readonly ISender _mediator;
private readonly ILoggerProvider<UpdateAccountDataBackgroundJob> _logger;
#endregion
public UpdateAccountDataBackgroundJob(ISender mediator, ILoggerProvider<UpdateAccountDataBackgroundJob> logger)
{
_mediator = mediator;
_logger = logger;
}
public async Task Execute(IJobExecutionContext context)
{
_logger.Information(context.JobDetail.Key, nameof(Execute), string.Empty);
await _mediator.Send(new GetPrivateKeyQuery()).ConfigureAwait(false);
await _mediator.Send(new UpdateAccountDataCommand(), CancellationToken.None);
}
}
This discussion was converted from issue #2369 on May 11, 2024 14:40.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
in all of my job i need to call a method. the method call an api in order to get a private key and check whether the expiration time is expired. this method should be called in all of my jobs.
i think there should be a base class that common logic is put and when job inherited from that base class they call this method so there is no duplication code in my jobs. on top of that, i need to log in all of my jobs is it better that quartz provide some thing for cross-cutting concerns.
here is my code:
Beta Was this translation helpful? Give feedback.
All reactions