Skip to content

Cron Services

Furkan Güngör edited this page Jun 12, 2021 · 1 revision

Usage

Install EasyCronJob.Core from Nuget Package

Add your own cron services.

For Example;

    public class ConsoleCronJob : CronJobService
    {
        private readonly ILogger<ConsoleCronJob> logger;

        public ConsoleCronJob(ICronConfiguration<ConsoleCronJob> cronConfiguration, ILogger<ConsoleCronJob> logger) 
            : base(cronConfiguration.CronExpression,cronConfiguration.TimeZoneInfo)
        {
            this.logger = logger;
        }

        public override Task StartAsync(CancellationToken cancellationToken)
        {
            logger.LogInformation("Start");
            return base.StartAsync(cancellationToken);
        }


        protected override Task ScheduleJob(CancellationToken cancellationToken)
        {
            logger.LogInformation("Scheduled");
            return base.ScheduleJob(cancellationToken);
        }

        public override Task DoWork(CancellationToken cancellationToken)
        {
            logger.LogInformation("Do Work");
            return base.DoWork(cancellationToken);
        }
    }
Clone this wiki locally