furkandeveloper / easycronjob Goto Github PK
View Code? Open in Web Editor NEWThis repository provides easy cron job to your application on IHostedService.
Home Page: https://furkandeveloper.github.io/EasyCronJob/
License: MIT License
This repository provides easy cron job to your application on IHostedService.
Home Page: https://furkandeveloper.github.io/EasyCronJob/
License: MIT License
Hi! Can you please add the ability to specify seconds in cron expression? Need to run a task every 10 seconds.
Additional context
I saw that for parsing expressions you used Cronos, and in its Parse method there is an overload for include seconds
CronExpression expression = CronExpression.Parse("*/10 * * * * *", CronFormat.IncludeSeconds);
Must be BaseService
for run cronjob.
This service must be abstract class.
Add '.ConfigureAwait(false)' to this call to allow execution to continue in any thread.
Add '.ConfigureAwait(false)' to this call to allow execution to continue in any thread.
Add '.ConfigureAwait(false)' to this call to allow execution to continue in any thread.
Add '.ConfigureAwait(false)' to this call to allow execution to continue in any thread.
Must be configurable cron jobs. So ICronConfiguration
uses object with get cron configuration.
In that must be define;
/// <summary>
/// This interface includes base parameter for Cron Job.
/// </summary>
/// <typeparam name="T">
/// Cron Job
/// </typeparam>
public interface ICronConfiguration<T>
{
/// <summary>
/// Cron Expression. For Example; '****' Cron.Minutely
/// </summary>
public string CronExpression { get; set; }
/// <summary>
/// TimeZone Information
/// </summary>
public TimeZoneInfo TimeZoneInfo { get; set; }
}
Describe the bug
I have a very simple Job like this:
public class Test : CronJobService
{
public TimTest(ICronConfiguration<TrainingsReminderJob> cronConfiguration)
: base(cronConfiguration.CronExpression, cronConfiguration.TimeZoneInfo, cronConfiguration.CronFormat)
{
}
public override Task StartAsync(CancellationToken cancellationToken)
{
Log();
return base.StartAsync(cancellationToken);
}
public override Task ScheduleJob(CancellationToken cancellationToken)
{
Log();
return base.StartAsync(cancellationToken);
}
public async override Task DoWork(CancellationToken cancellationToken)
{
await DoMyWorkAsync();
return base.DoWork(cancellationToken);
}
I set it up like this:
services.ApplyResulation<Test>(options =>
{
options.CronExpression = "* * * * *";
options.TimeZoneInfo = TimeZoneInfo.Local;
options.CronFormat = Cronos.CronFormat.Standard;
});
So it should run every minute. I can see in my logs, that Startasync
and ScheduleJob
are being called, but DoWork
is called never. What am I doing wrong?
public class CronJobUpdateVisitorVisitDay:CronJobService
{
private readonly ApplicationDbContext _ApplicationDbContext;
private readonly UserManager _UserManager;
public CronJobUpdateVisitorVisitDay(ICronConfiguration<CronJobUpdateVisitorVisitDay> cronConfiguration, ApplicationDbContext applicationDbContext,UserManager<ApplicationUser> userManager)
: base(cronConfiguration.CronExpression,cronConfiguration.TimeZoneInfo,cronConfiguration.CronFormat)
{
_ApplicationDbContext = applicationDbContext;
_UserManager = userManager;
}
protected override async Task ScheduleJob(CancellationToken cancellationToken)
{
await CustomExtension.StoreVisitorVisitDay(_ApplicationDbContext, _UserManager);
await base.ScheduleJob(cancellationToken);
}
public override async Task StartAsync(CancellationToken cancellationToken)
{
await CustomExtension.StoreVisitorVisitDay(_ApplicationDbContext, _UserManager);
await base.StartAsync(cancellationToken);
}
}
In this code, StartAsync and ScheduleJob are run consecutively, while according to the settings, they must be run every 25 minutes every hour.
services.ApplyResulation<CronJobUpdateVisitorVisitDay>(options =>
{
options.CronExpression = "25 * * * *";
options.TimeZoneInfo = TimeZoneInfo.Local;
options.CronFormat = Cronos.CronFormat.Standard;
});
Describe the bug
Not sure what's causing this, but it sometimes happens and sometimes doesn't happen.
To Reproduce
Steps to reproduce the behavior:
Here is the code I used.
The line in question I believe is the InactiveRemoverService.
Expected behavior
Job scheduled to run every two hours.
Desktop (please complete the following information):
It will be very usefull to have dynamic time configuration, to allow change timers without app restart.
Currently can't seem to find that, or need example.
Change jobs timers without app restart
Hi, Iโm @obarscan
I noticed that if you use the autoncofigurator the hostservices are in separated scope.
This library could easily target more that .net5. I successfully tested this in in core3.1 without any problem. Having taken a look in this library I see no reason for this not to work in any version of donet. This could be done by a simple edit in the csproj files. I have personally tested 3.1 so anything newer should be ok.
Makes this project usable independently of c# version. The Timers api works since core2.0 and .net standard 2.0.
CodeFactor found an issue: An opening curly bracket must not be followed by a blank line.
It's currently on:
samples\EasyCron.Sample\Startup.cs:30
Must be IServiceCollection
extension for initialize job.
services.ApplyResulation<DbWriterCronJob>(options =>
{
options.CronExpression = "* * * * *"
options.TimeZoneInfo = TimeZoneInfo.Local;
});
Change the visibility of this constructor to 'protected'.
It would be really helpful to load the ICronConfiguration for the appsettings.
Services can be updated without recompiling
Additional context
Maybe consider
{
"CronConfiguration" : [
"ServiceName" {
"CronExpression": "*/10 * * * * *",
"TimeZoneInfo": "Local"
}
]
}
CodeFactor found an issue: The code must not contain multiple blank lines in a row.
It's currently on:
samples\EasyCron.Sample\Jobs\ConsoleCronJob.cs:27
Commit 001f7cf
Add '.ConfigureAwait(false)' to this call to allow execution to continue in any thread.
await Task.CompletedTask;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.