commit f09a4a579eea563049d5408567b692b175deae2c Author: wufan Date: Mon Oct 21 08:49:02 2024 +0800 :sparkles: init diff --git a/.idea/.idea.Hangfire.Job/.idea/.gitignore b/.idea/.idea.Hangfire.Job/.idea/.gitignore new file mode 100644 index 0000000..61b4f1f --- /dev/null +++ b/.idea/.idea.Hangfire.Job/.idea/.gitignore @@ -0,0 +1,13 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# Rider 忽略的文件 +/.idea.Hangfire.Job.iml +/modules.xml +/projectSettingsUpdater.xml +/contentModel.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Hangfire.Job.sln b/Hangfire.Job.sln new file mode 100644 index 0000000..30f150d --- /dev/null +++ b/Hangfire.Job.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hangfire.Job", "Hangfire.Job\Hangfire.Job.csproj", "{C0A6E59A-E820-4008-A95B-483391FEDAA7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C0A6E59A-E820-4008-A95B-483391FEDAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0A6E59A-E820-4008-A95B-483391FEDAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0A6E59A-E820-4008-A95B-483391FEDAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0A6E59A-E820-4008-A95B-483391FEDAA7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Hangfire.Job/Controllers/HangfireController.cs b/Hangfire.Job/Controllers/HangfireController.cs new file mode 100644 index 0000000..ddcdc32 --- /dev/null +++ b/Hangfire.Job/Controllers/HangfireController.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Hangfire.Job.Controllers; + +[ApiController] +[Route("[controller]")] +public class HangfireController : ControllerBase +{ + +} \ No newline at end of file diff --git a/Hangfire.Job/Hangfire.Job.csproj b/Hangfire.Job/Hangfire.Job.csproj new file mode 100644 index 0000000..3e73d56 --- /dev/null +++ b/Hangfire.Job/Hangfire.Job.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Hangfire.Job/Program.cs b/Hangfire.Job/Program.cs new file mode 100644 index 0000000..aa39236 --- /dev/null +++ b/Hangfire.Job/Program.cs @@ -0,0 +1,30 @@ +using Hangfire; +using Hangfire.Console; +using Hangfire.HttpJob; +using Hangfire.Tags.SqlServer; + +var builder = WebApplication.CreateBuilder(args); + + +var connectionString = builder.Configuration["ConnectionStrings:Default"]; + +builder.Services.AddHangfire(config => config + .UseSqlServerStorage(connectionString) + // .UseConsole(new ConsoleOptions() + // { + // BackgroundColor = "#000079" + // }) + // .UseTagsWithSql() + .UseHangfireHttpJob() +); + +builder.Services.AddHangfireServer(); + + +var app = builder.Build(); + +app.UseHangfireDashboard(); +// app.UseHangfireServer(); + +app.MapGet("/", () => "Hangfire service is running!"); +app.Run(); \ No newline at end of file diff --git a/Hangfire.Job/Properties/launchSettings.json b/Hangfire.Job/Properties/launchSettings.json new file mode 100644 index 0000000..053a69a --- /dev/null +++ b/Hangfire.Job/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:1930", + "sslPort": 44394 + } + }, + "profiles": { + "Hangfire.Job": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "hangfire", + "applicationUrl": "http://localhost:8093", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Hangfire.Job/appsettings.Development.json b/Hangfire.Job/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Hangfire.Job/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Hangfire.Job/appsettings.json b/Hangfire.Job/appsettings.json new file mode 100644 index 0000000..6e60f90 --- /dev/null +++ b/Hangfire.Job/appsettings.json @@ -0,0 +1,20 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Hangfire": "Information" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "Default": "server=192.168.1.248;database=HangfireDB;uid=sa;pwd=123;TrustServerCertificate=True;" + }, + "Kestrel": { + "Endpoints": { + "Http": { + "Url": "http://0.0.0.0:8093" + } + } + } +}