Last active
August 4, 2023 08:25
-
-
Save yowko/db60edaeb8f13150d7d2a454d7fef829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Coravel; | |
using CoravelDemo; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.Services.AddSingleton<UpdateCacheService>(); | |
builder.Services.AddScheduler(); | |
var app = builder.Build(); | |
var provider = app.Services; | |
provider.UseScheduler(scheduler => | |
{ | |
scheduler.Schedule( | |
async () => | |
{ | |
var updateCacheService = provider.GetService<UpdateCacheService>(); | |
if (updateCacheService!=null) | |
{ | |
await updateCacheService.GetAsync(new CancellationToken()); | |
} | |
await Task.CompletedTask; | |
} | |
) | |
.Cron("00 00 * * *") | |
.Zoned( TimeZoneInfo.FindSystemTimeZoneById("Asia/Shanghai")) | |
.RunOnceAtStart(); | |
}).OnError((exception) => Console.WriteLine(exception.Message)); | |
app.MapGet("/", () => "Hello World!"); | |
app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment