Ez4.CronJob
6.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Ez4.CronJob --version 6.0.3
NuGet\Install-Package Ez4.CronJob -Version 6.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ez4.CronJob" Version="6.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ez4.CronJob --version 6.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ez4.CronJob, 6.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Ez4.CronJob as a Cake Addin #addin nuget:?package=Ez4.CronJob&version=6.0.3 // Install Ez4.CronJob as a Cake Tool #tool nuget:?package=Ez4.CronJob&version=6.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Getting Started
Cron expression
Allowed values Allowed special characters Comment
┌───────────── second (optional) 0-59 * , - /
│ ┌───────────── minute 0-59 * , - /
│ │ ┌───────────── hour 0-23 * , - /
│ │ │ ┌───────────── day of month 1-31 * , - / L W ?
│ │ │ │ ┌───────────── month 1-12 or JAN-DEC * , - /
│ │ │ │ │ ┌───────────── day of week 0-6 or SUN-SAT * , - / # L ? Both 0 and 7 means SUN
│ │ │ │ │ │
* * * * * *
Usage
With Base
MyJob.cs
public class BasicCronJob : Ez4CronJobBase
{
private readonly ILogger<BasicCronJob> logger;
public BasicCronJob(ILogger<BasicCronJob> logger, ICronConfiguration<BasicCronJob> cronConfiguration)
: base(logger, cronConfiguration)
{
this.logger = logger;
logger.LogInformation("BasicCronJob created");
}
public override Task ExecuteAsync(CancellationToken cancellationToken)
{
logger.LogWarning("Working BasicCronJob" + " Start Time : " + DateTime.UtcNow);
return Task.CompletedTask;
}
}
Program.cs Local test with each 5 second
builder.Services.ApplyEz4CronJob<BasicCronJob>(op =>
{
op.CronExpression = "*/5 * * * * *";
op.CronFormat = CronFormat.IncludeSeconds;
op.TimeZoneInfo = TimeZoneInfo.Local;
});
With CronExpressionAttribute
[CronExpression(cronExpression: "*/2 * * * * *", cronFormat: CronFormat.IncludeSeconds)]
public class BasicCronJobAuto : Ez4CronJobBase, ICronJobAutoConfig
{
private readonly ILogger<BasicCronJobAuto> logger;
public BasicCronJobAuto(ILogger<BasicCronJobAuto> logger, ICronConfiguration<BasicCronJobAuto> cronConfiguration)
: base(logger, cronConfiguration)
{
this.logger = logger;
logger.LogInformation("BasicCronJobAuto created {0} {1} {2}", cronConfiguration.CronExpression, cronConfiguration.TimeZoneInfo, cronConfiguration.CronFormat);
}
public override Task ExecuteAsync(CancellationToken cancellationToken)
{
logger.LogWarning("Working BasicCronJobAuto" + " Start Time : " + DateTime.UtcNow);
return Task.CompletedTask;
}
}
Program.cs
builder.Services.AutoApplyEz4CronJob();
With k8s Cluster
[CronExpression(cronExpression: "*/5 * * * * *", cronFormat: CronFormat.IncludeSeconds)]
public class ConsoleBasicCronJob : Ez4CronJobLeader, ICronJobAutoConfig
{
private ILogger<ConsoleBasicCronJob> _logger;
public ConsoleBasicCronJob(ILogger<ConsoleBasicCronJob> logger, IEz4LeaderConfiguration Ez4CronJobLeaderOption, ICronConfiguration<ConsoleBasicCronJob> cronConfig) : base(logger, Ez4CronJobLeaderOption, cronConfig)
{
_logger = logger;
}
public override Task ExecuteAsync(CancellationToken cancellationToken)
{
_logger.LogWarning("ok at {0}", DateTime.Now);
return Task.CompletedTask;
}
}
Program.cs
builder.Services.AddEz4LeaderConfig(op =>
{
op.Namespace = "default";
op.Lock = "my-lock";
});
builder.Services.AutoApplyEz4CronJob();
Example with local k8s & minikube
Prerequisites
Run k8s on Docker Desktop.
Start minikube and run demo test
minikube start
helm_deploy.sh
kubectl -n ns-demo2024 get pod
kubectl -n ns-demo2024 get lease
kubectl -n ns-demo2024 logs replace_your_lease_pod
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Ez4.CronJob.Abstractions (>= 6.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.