From c97e7c4afade4384b8b51e1000dfcfc26585d2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96ZT=C3=9CRK?= <76204082+iamsedatozturk@users.noreply.github.com> Date: Thu, 7 May 2026 09:57:46 +0300 Subject: [PATCH] =?UTF-8?q?BackgroundWorker=20a=C3=A7=C4=B1l=C4=B1=C5=9Fta?= =?UTF-8?q?=20run=20edilmesi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BackgroundWorkerAppService.cs | 56 ++------------- .../BackgroundWorkerInitializer.cs | 70 +++++++++++++++++++ .../Seeds/LanguagesData.json | 4 +- .../EntityFrameworkCore/PlatformDbContext.cs | 1 + .../PlatformHttpApiHostModule.cs | 10 ++- ui/src/proxy/intranet/models.ts | 1 + .../intranet/widgets/RecentDocuments.tsx | 8 ++- 7 files changed, 93 insertions(+), 57 deletions(-) create mode 100644 api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerInitializer.cs diff --git a/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerAppService.cs b/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerAppService.cs index a025419..14f290b 100644 --- a/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerAppService.cs +++ b/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerAppService.cs @@ -1,19 +1,9 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text.Json; using System.Threading.Tasks; -using Hangfire; -using Hangfire.Storage; -using Sozsoft.MailQueue.Domain.Shared; -using Sozsoft.Platform.BackgroundWorkers; -using Sozsoft.Platform.Entities; -using Sozsoft.Platform.Enums; using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Volo.Abp; -using Volo.Abp.Domain.Repositories; using Volo.Abp.TextTemplating; namespace Sozsoft.Platform; @@ -21,18 +11,15 @@ namespace Sozsoft.Platform; [Authorize] public class BackgroundWorkerAppService : PlatformAppService { - private readonly IRepository repo; - private readonly PlatformTemplateManager templateManager; + private readonly BackgroundWorkerInitializer initializer; private readonly ITemplateDefinitionManager platformTemplateDefinitionManager; public BackgroundWorkerAppService( - IRepository repo, - PlatformTemplateManager templateManager, + BackgroundWorkerInitializer initializer, ITemplateDefinitionManager platformTemplateDefinitionManager ) { - this.repo = repo; - this.templateManager = templateManager; + this.initializer = initializer; this.platformTemplateDefinitionManager = platformTemplateDefinitionManager; } @@ -46,42 +33,7 @@ public class BackgroundWorkerAppService : PlatformAppService { try { - var jobs = JobStorage.Current.GetConnection().GetRecurringJobs(); - var workers = await repo.GetListAsync(a => a.IsActive); - - foreach (var job in jobs) - { - if (job.Queue == "platform" && !workers.Any(a => $"{a.WorkerType}:{a.Name}" == job.Id)) - { - RecurringJob.RemoveIfExists(job.Id); - } - } - - foreach (var worker in workers) - { - var workerId = worker.Id; - - RecurringJob.AddOrUpdate( - $"{worker.WorkerType}:{worker.Name}", - "platform", - (w) => w.StartAsync(workerId, default), - worker.Cron, - new RecurringJobOptions - { - TimeZone = TimeZoneInfo.Local, - }); - - if (worker.WorkerType == WorkerTypeEnum.MailQueueWorker && !worker.Options.IsNullOrWhiteSpace()) - { - var Options = JsonSerializer.Deserialize(worker.Options); - - // Add template - if (!Options.MailTemplate.IsNullOrEmpty()) - { - await templateManager.AddOrUpdateTemplateAsync(worker.Name, Options.MailTemplate); - } - } - } + await initializer.RunAsync(); } catch (Exception ex) { diff --git a/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerInitializer.cs b/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerInitializer.cs new file mode 100644 index 0000000..a12da0a --- /dev/null +++ b/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerInitializer.cs @@ -0,0 +1,70 @@ +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Hangfire; +using Hangfire.Storage; +using Sozsoft.MailQueue.Domain.Shared; +using Sozsoft.Platform.BackgroundWorkers; +using Sozsoft.Platform.Entities; +using Sozsoft.Platform.Enums; +using Microsoft.Extensions.Logging; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories; + +namespace Sozsoft.Platform; + +public class BackgroundWorkerInitializer : ITransientDependency +{ + private readonly IRepository _repo; + private readonly PlatformTemplateManager _templateManager; + private readonly ILogger _logger; + + public BackgroundWorkerInitializer( + IRepository repo, + PlatformTemplateManager templateManager, + ILogger logger) + { + _repo = repo; + _templateManager = templateManager; + _logger = logger; + } + + public async Task RunAsync() + { + var jobs = JobStorage.Current.GetConnection().GetRecurringJobs(); + var workers = await _repo.GetListAsync(a => a.IsActive); + + foreach (var job in jobs) + { + if (job.Queue == "platform" && !workers.Exists(a => $"{a.WorkerType}:{a.Name}" == job.Id)) + { + RecurringJob.RemoveIfExists(job.Id); + } + } + + foreach (var worker in workers) + { + var workerId = worker.Id; + + RecurringJob.AddOrUpdate( + $"{worker.WorkerType}:{worker.Name}", + "platform", + (w) => w.StartAsync(workerId, default), + worker.Cron, + new RecurringJobOptions + { + TimeZone = TimeZoneInfo.Local, + }); + + if (worker.WorkerType == WorkerTypeEnum.MailQueueWorker && !worker.Options.IsNullOrWhiteSpace()) + { + var options = JsonSerializer.Deserialize(worker.Options); + + if (options != null && !options.MailTemplate.IsNullOrEmpty()) + { + await _templateManager.AddOrUpdateTemplateAsync(worker.Name, options.MailTemplate); + } + } + } + } +} diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json index 16caa31..766ab99 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json @@ -2745,8 +2745,8 @@ { "resourceName": "Platform", "key": "Abp.Identity.User.UserInformation", - "en": "User Information", - "tr": "Kullanıcı Bilgileri" + "en": "General", + "tr": "Genel" }, { "resourceName": "Platform", diff --git a/api/src/Sozsoft.Platform.EntityFrameworkCore/EntityFrameworkCore/PlatformDbContext.cs b/api/src/Sozsoft.Platform.EntityFrameworkCore/EntityFrameworkCore/PlatformDbContext.cs index f6ec41f..6268274 100644 --- a/api/src/Sozsoft.Platform.EntityFrameworkCore/EntityFrameworkCore/PlatformDbContext.cs +++ b/api/src/Sozsoft.Platform.EntityFrameworkCore/EntityFrameworkCore/PlatformDbContext.cs @@ -1060,6 +1060,7 @@ public class PlatformDbContext : b.Property(x => x.PublishDate).IsRequired(); b.Property(x => x.Attachments).HasMaxLength(2048); b.Property(x => x.ViewCount).HasDefaultValue(0); + b.Property(x => x.ImageUrl).HasColumnType("text"); }); builder.Entity(b => diff --git a/api/src/Sozsoft.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs b/api/src/Sozsoft.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs index 2955ff0..a410152 100644 --- a/api/src/Sozsoft.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs +++ b/api/src/Sozsoft.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading.Tasks; using Hangfire; using Hangfire.PostgreSql; using Sozsoft.Languages; @@ -522,6 +523,11 @@ public class PlatformHttpApiHostModule : AbpModule app.UseConfiguredEndpoints(); } + + public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context) + { + using var scope = context.ServiceProvider.CreateScope(); + var initializer = scope.ServiceProvider.GetRequiredService(); + await initializer.RunAsync(); + } } - - diff --git a/ui/src/proxy/intranet/models.ts b/ui/src/proxy/intranet/models.ts index 776fefc..2ac9d1e 100644 --- a/ui/src/proxy/intranet/models.ts +++ b/ui/src/proxy/intranet/models.ts @@ -49,6 +49,7 @@ export interface DocumentDto { parentId: string isReadOnly: boolean childCount: number + tenantId?: string } // Duyuru diff --git a/ui/src/views/intranet/widgets/RecentDocuments.tsx b/ui/src/views/intranet/widgets/RecentDocuments.tsx index a5088e9..88f8c3b 100644 --- a/ui/src/views/intranet/widgets/RecentDocuments.tsx +++ b/ui/src/views/intranet/widgets/RecentDocuments.tsx @@ -4,6 +4,7 @@ import dayjs from 'dayjs' import { DocumentDto } from '@/proxy/intranet/models' import { useLocalization } from '@/utils/hooks/useLocalization' import { getFileIcon, getFileType } from '@/proxy/intranet/utils' +import { FILE_URL } from '@/constants/app.constant' const formatFileSize = (bytes: number): string => { if (bytes === 0) return '0 B' @@ -58,10 +59,15 @@ const RecentDocuments: React.FC<{ documents: DocumentDto[] }> = ({ documents })