From d602238f829d23f3ba5ea775e691c57dd2779a09 Mon Sep 17 00:00:00 2001
From: hang <872297557@qq.com>
Date: Tue, 30 Jul 2024 16:03:35 +0800
Subject: [PATCH] =?UTF-8?q?hangfire=20=E4=BB=BB=E5=8A=A1=E8=B0=83=E5=BA=A6?=
=?UTF-8?q?=E9=9A=90=E6=82=A3=E6=8E=92=E9=99=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
IRaCIS.Core.API/IRaCIS.Core.API.csproj | 1 +
.../_ServiceExtensions/hangfireSetup.cs | 35 ++++++++++++-------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/IRaCIS.Core.API/IRaCIS.Core.API.csproj b/IRaCIS.Core.API/IRaCIS.Core.API.csproj
index 8bdddbe5f..5a7be3fe9 100644
--- a/IRaCIS.Core.API/IRaCIS.Core.API.csproj
+++ b/IRaCIS.Core.API/IRaCIS.Core.API.csproj
@@ -71,6 +71,7 @@
+
diff --git a/IRaCIS.Core.API/_ServiceExtensions/hangfireSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/hangfireSetup.cs
index 00b718e2c..e2dc37494 100644
--- a/IRaCIS.Core.API/_ServiceExtensions/hangfireSetup.cs
+++ b/IRaCIS.Core.API/_ServiceExtensions/hangfireSetup.cs
@@ -3,6 +3,7 @@ using Hangfire.SqlServer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
+using System.Runtime.InteropServices;
namespace IRaCIS.Core.API
{
@@ -14,19 +15,29 @@ namespace IRaCIS.Core.API
services.AddHangfire(hangFireConfig =>
{
-
- //hangFireConfig.UseInMemoryStorage();
-
- //指定存储介质
- hangFireConfig.UseSqlServerStorage(hangFireConnStr, new SqlServerStorageOptions()
+ //本地window 调试 使用内存,服务器部署使用数据库,防止服务器任务调度到本地
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- SchemaName = "dbo",
- CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
- SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
- QueuePollInterval = TimeSpan.Zero,
- UseRecommendedIsolationLevel = true,
- DisableGlobalLocks = true
- });
+ hangFireConfig.UseInMemoryStorage();
+
+ }
+ else
+ {
+ //指定存储介质
+ hangFireConfig.UseSqlServerStorage(hangFireConnStr, new SqlServerStorageOptions()
+ {
+ SchemaName = "dbo",
+ CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
+ SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
+ QueuePollInterval = TimeSpan.Zero,
+ UseRecommendedIsolationLevel = true,
+ DisableGlobalLocks = true
+ });
+ }
+
+
+
+
//hangFireConfig.UseTagsWithSql(); //nuget引入Hangfire.Tags.SqlServer
//.UseHangfireHttpJob();