CronJob.Org.Sdk
1.0.0
See the version list below for details.
dotnet add package CronJob.Org.Sdk --version 1.0.0
NuGet\Install-Package CronJob.Org.Sdk -Version 1.0.0
<PackageReference Include="CronJob.Org.Sdk" Version="1.0.0" />
paket add CronJob.Org.Sdk --version 1.0.0
#r "nuget: CronJob.Org.Sdk, 1.0.0"
// Install CronJob.Org.Sdk as a Cake Addin #addin nuget:?package=CronJob.Org.Sdk&version=1.0.0 // Install CronJob.Org.Sdk as a Cake Tool #tool nuget:?package=CronJob.Org.Sdk&version=1.0.0
CronJob.Org SDK for .NET
A .NET SDK for scheduling and managing cron jobs using the cron-job.org API. This SDK provides a simple interface to create, manage, and monitor scheduled tasks.
Features
- Schedule one-time and recurring jobs
- Flexible recurring patterns (minutes, hourly, daily, weekly, monthly, yearly)
- Support for intervals (every X minutes, days, or months)
- Manage existing cron jobs
- Retrieve job details and status
- Delete scheduled jobs
- Supports multiple time zones
- Built-in request validation
- Comprehensive logging
Installation
Install the package via NuGet:
dotnet add package CronJobOrgSdk
Configuration
Add the following to your appsettings.json
:
{
"CronJobApi": {
"BaseUrl": "YOUR_API_BASE_URL",
"BearerToken": "YOUR_API_TOKEN"
}
}
Register the service in your Program.cs
or Startup.cs
:
builder.Services.AddCronJobOrgSdk();
Usage
Schedule a One-time Job
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.OneTime,
ExecutionTime = DateTime.UtcNow.AddHours(1),
TimeZone = "America/New_York"
};
var response = await _cronJobService.ScheduleJobAsync(request);
Schedule Recurring Jobs
Every Minute
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.EveryMinute,
TimeZone = "UTC"
};
Every X Minutes
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.EveryMinute,
MinuteInterval = 15, // Run every 15 minutes
TimeZone = "UTC"
};
Hourly (Every hour at specific minute)
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.Hourly,
Minute = 30, // Run at minute 30 of every hour
TimeZone = "UTC"
};
Daily Job
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.Daily,
Hour = 14, // Run at 2 PM
Minute = 30, // at 30 minutes
TimeZone = "UTC"
};
Every X Days
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.EveryXDays,
DayInterval = 2, // Run every 2 days
Hour = 9, // at 9 AM
Minute = 0,
TimeZone = "UTC"
};
Weekly Job
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.Weekly,
DayOfWeek = DayOfWeek.Monday, // Run every Monday
Hour = 10,
Minute = 0,
TimeZone = "UTC"
};
Monthly Job
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.Monthly,
DayOfMonth = 15, // Run on 15th of every month
Hour = 14,
Minute = 30,
TimeZone = "UTC"
};
Every X Months (e.g., Quarterly)
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.Monthly,
DayOfMonth = 1, // Run on 1st of every 3rd month
MonthInterval = 3, // Every 3 months
Hour = 9,
Minute = 0,
TimeZone = "UTC"
};
Yearly Job
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.Yearly,
Month = 3, // March
DayOfMonth = 15, // 15th
Hour = 15,
Minute = 0,
TimeZone = "UTC"
};
Custom Pattern
var request = new CronJobScheduleRequest
{
WebhookUrl = "https://api.example.com/webhook",
ScheduleType = JobScheduleType.Recurring,
RecurringPattern = RecurringPattern.Custom,
Month = 6, // June
DayOfMonth = 1, // 1st
DayOfWeek = DayOfWeek.Monday, // Only on Mondays
Hour = 12,
Minute = 30,
TimeZone = "UTC"
};
Get Job Details
var jobDetails = await _cronJobService.GetJobDetailsAsync(jobId);
Console.WriteLine($"Job URL: {jobDetails.JobDetails.Url}");
Get All Jobs
var allJobs = await _cronJobService.GetAllJobsAsync();
foreach (var job in allJobs.Jobs)
{
Console.WriteLine($"Job ID: {job.JobId}, Status: {job.Status}");
}
Delete a Job
var deleted = await _cronJobService.DeleteJobAsync(jobId);
if (deleted)
{
Console.WriteLine("Job deleted successfully");
}
Request Models
CronJobScheduleRequest
public class CronJobScheduleRequest
{
public string WebhookUrl { get; set; }
public JobScheduleType ScheduleType { get; set; }
public string TimeZone { get; set; } = "UTC";
// For one-time jobs
public DateTime? ExecutionTime { get; set; }
// For recurring jobs
public RecurringPattern RecurringPattern { get; set; }
public int? Hour { get; set; }
public int? Minute { get; set; }
public int? DayOfMonth { get; set; }
public DayOfWeek? DayOfWeek { get; set; }
public int? Month { get; set; }
public int? MinuteInterval { get; set; }
public int? MonthInterval { get; set; }
public int? DayInterval { get; set; }
}
public enum RecurringPattern
{
EveryMinute,
Hourly,
Daily,
EveryXDays,
Weekly,
Monthly,
Yearly,
Custom
}
public enum JobScheduleType
{
OneTime,
Recurring
}
Response Models
ScheduleJobResponse
public class ScheduleJobResponse
{
public bool Success { get; set; }
public string Message { get; set; }
public HttpStatusCode? StatusCode { get; set; }
public long? JobId { get; set; }
}
GetJobsResponse
public class GetJobsResponse
{
[JsonPropertyName("jobs")]
public List<JobDetails> Jobs { get; set; }
[JsonPropertyName("someFailed")]
public bool SomeFailed { get; set; }
}
JobDetailsResponse
public class JobDetailsResponse
{
[JsonPropertyName("jobDetails")]
public JobDetailsInfo JobDetails { get; set; }
}
public class JobDetailsInfo : JobDetails
{
[JsonPropertyName("auth")]
public AuthInfo Auth { get; set; }
[JsonPropertyName("notification")]
public NotificationInfo Notification { get; set; }
[JsonPropertyName("extendedData")]
public ExtendedDataInfo ExtendedData { get; set; }
}
JobDetails
public class JobDetails
{
[JsonPropertyName("jobId")]
public long JobId { get; set; }
[JsonPropertyName("enabled")]
public bool Enabled { get; set; }
[JsonPropertyName("title")]
public string Title { get; set; }
[JsonPropertyName("saveResponses")]
public bool SaveResponses { get; set; }
[JsonPropertyName("url")]
public string Url { get; set; }
[JsonPropertyName("lastStatus")]
public int LastStatus { get; set; }
[JsonPropertyName("lastDuration")]
public int LastDuration { get; set; }
[JsonPropertyName("lastExecution")]
public long LastExecution { get; set; }
[JsonPropertyName("nextExecution")]
public long? NextExecution { get; set; }
[JsonPropertyName("type")]
public int Type { get; set; }
[JsonPropertyName("requestTimeout")]
public int RequestTimeout { get; set; }
[JsonPropertyName("redirectSuccess")]
public bool RedirectSuccess { get; set; }
[JsonPropertyName("folderId")]
public int FolderId { get; set; }
[JsonPropertyName("schedule")]
public Schedule Schedule { get; set; }
[JsonPropertyName("requestMethod")]
public int RequestMethod { get; set; }
}
Schedule Configuration
public class Schedule
{
[JsonPropertyName("timezone")]
public string Timezone { get; set; }
[JsonPropertyName("expiresAt")]
public long ExpiresAt { get; set; }
[JsonPropertyName("hours")]
public List<int> Hours { get; set; }
[JsonPropertyName("minutes")]
public List<int> Minutes { get; set; }
[JsonPropertyName("mdays")]
public List<int> Mdays { get; set; }
[JsonPropertyName("months")]
public List<int> Months { get; set; }
[JsonPropertyName("wdays")]
public List<int> Wdays { get; set; }
[JsonPropertyName("exceptionDates")]
public List<int> ExceptionDates { get; set; }
}
Error Handling
The SDK includes comprehensive error handling and logging. All methods throw appropriate exceptions for invalid requests or API errors. It's recommended to wrap calls in try-catch blocks:
try
{
var response = await _cronJobService.ScheduleJobAsync(request);
// Handle success
}
catch (ArgumentException ex)
{
// Handle validation errors
_logger.LogError(ex, "Invalid request");
}
catch (HttpRequestException ex)
{
// Handle API communication errors
_logger.LogError(ex, "API error");
}
catch (Exception ex)
{
// Handle unexpected errors
_logger.LogError(ex, "Unexpected error");
}
Logging
The SDK uses Microsoft.Extensions.Logging for comprehensive logging of operations. Configure logging in your application to capture:
- API requests and responses
- Validation errors
- Configuration issues
- Runtime errors
Supported .NET Versions
- .NET 6.0
- .NET 7.0
- .NET 8.0
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 is compatible. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
-
net7.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version 1.0.0:
- Initial release
- Added core functionality for CronJob.Org integration
- Basic SDK features implemented