BackgroundWorker açılışta run edilmesi
This commit is contained in:
parent
d81ca4cd2f
commit
c97e7c4afa
7 changed files with 93 additions and 57 deletions
|
|
@ -1,19 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading.Tasks;
|
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.AspNetCore.Authorization;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Domain.Repositories;
|
|
||||||
using Volo.Abp.TextTemplating;
|
using Volo.Abp.TextTemplating;
|
||||||
|
|
||||||
namespace Sozsoft.Platform;
|
namespace Sozsoft.Platform;
|
||||||
|
|
@ -21,18 +11,15 @@ namespace Sozsoft.Platform;
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class BackgroundWorkerAppService : PlatformAppService
|
public class BackgroundWorkerAppService : PlatformAppService
|
||||||
{
|
{
|
||||||
private readonly IRepository<BackgroundWorker, Guid> repo;
|
private readonly BackgroundWorkerInitializer initializer;
|
||||||
private readonly PlatformTemplateManager templateManager;
|
|
||||||
private readonly ITemplateDefinitionManager platformTemplateDefinitionManager;
|
private readonly ITemplateDefinitionManager platformTemplateDefinitionManager;
|
||||||
|
|
||||||
public BackgroundWorkerAppService(
|
public BackgroundWorkerAppService(
|
||||||
IRepository<BackgroundWorker, Guid> repo,
|
BackgroundWorkerInitializer initializer,
|
||||||
PlatformTemplateManager templateManager,
|
|
||||||
ITemplateDefinitionManager platformTemplateDefinitionManager
|
ITemplateDefinitionManager platformTemplateDefinitionManager
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.repo = repo;
|
this.initializer = initializer;
|
||||||
this.templateManager = templateManager;
|
|
||||||
this.platformTemplateDefinitionManager = platformTemplateDefinitionManager;
|
this.platformTemplateDefinitionManager = platformTemplateDefinitionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,42 +33,7 @@ public class BackgroundWorkerAppService : PlatformAppService
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var jobs = JobStorage.Current.GetConnection().GetRecurringJobs();
|
await initializer.RunAsync();
|
||||||
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<IPlatformBackgroundWorker>(
|
|
||||||
$"{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<MailQueueWorkerOptions>(worker.Options);
|
|
||||||
|
|
||||||
// Add template
|
|
||||||
if (!Options.MailTemplate.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
await templateManager.AddOrUpdateTemplateAsync(worker.Name, Options.MailTemplate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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<BackgroundWorker, Guid> _repo;
|
||||||
|
private readonly PlatformTemplateManager _templateManager;
|
||||||
|
private readonly ILogger<BackgroundWorkerInitializer> _logger;
|
||||||
|
|
||||||
|
public BackgroundWorkerInitializer(
|
||||||
|
IRepository<BackgroundWorker, Guid> repo,
|
||||||
|
PlatformTemplateManager templateManager,
|
||||||
|
ILogger<BackgroundWorkerInitializer> 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<IPlatformBackgroundWorker>(
|
||||||
|
$"{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<MailQueueWorkerOptions>(worker.Options);
|
||||||
|
|
||||||
|
if (options != null && !options.MailTemplate.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
await _templateManager.AddOrUpdateTemplateAsync(worker.Name, options.MailTemplate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2745,8 +2745,8 @@
|
||||||
{
|
{
|
||||||
"resourceName": "Platform",
|
"resourceName": "Platform",
|
||||||
"key": "Abp.Identity.User.UserInformation",
|
"key": "Abp.Identity.User.UserInformation",
|
||||||
"en": "User Information",
|
"en": "General",
|
||||||
"tr": "Kullanıcı Bilgileri"
|
"tr": "Genel"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"resourceName": "Platform",
|
"resourceName": "Platform",
|
||||||
|
|
|
||||||
|
|
@ -1060,6 +1060,7 @@ public class PlatformDbContext :
|
||||||
b.Property(x => x.PublishDate).IsRequired();
|
b.Property(x => x.PublishDate).IsRequired();
|
||||||
b.Property(x => x.Attachments).HasMaxLength(2048);
|
b.Property(x => x.Attachments).HasMaxLength(2048);
|
||||||
b.Property(x => x.ViewCount).HasDefaultValue(0);
|
b.Property(x => x.ViewCount).HasDefaultValue(0);
|
||||||
|
b.Property(x => x.ImageUrl).HasColumnType("text");
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Entity<Survey>(b =>
|
builder.Entity<Survey>(b =>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Hangfire;
|
using Hangfire;
|
||||||
using Hangfire.PostgreSql;
|
using Hangfire.PostgreSql;
|
||||||
using Sozsoft.Languages;
|
using Sozsoft.Languages;
|
||||||
|
|
@ -522,6 +523,11 @@ public class PlatformHttpApiHostModule : AbpModule
|
||||||
|
|
||||||
app.UseConfiguredEndpoints();
|
app.UseConfiguredEndpoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||||
|
{
|
||||||
|
using var scope = context.ServiceProvider.CreateScope();
|
||||||
|
var initializer = scope.ServiceProvider.GetRequiredService<BackgroundWorkerInitializer>();
|
||||||
|
await initializer.RunAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ export interface DocumentDto {
|
||||||
parentId: string
|
parentId: string
|
||||||
isReadOnly: boolean
|
isReadOnly: boolean
|
||||||
childCount: number
|
childCount: number
|
||||||
|
tenantId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Duyuru
|
// Duyuru
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import dayjs from 'dayjs'
|
||||||
import { DocumentDto } from '@/proxy/intranet/models'
|
import { DocumentDto } from '@/proxy/intranet/models'
|
||||||
import { useLocalization } from '@/utils/hooks/useLocalization'
|
import { useLocalization } from '@/utils/hooks/useLocalization'
|
||||||
import { getFileIcon, getFileType } from '@/proxy/intranet/utils'
|
import { getFileIcon, getFileType } from '@/proxy/intranet/utils'
|
||||||
|
import { FILE_URL } from '@/constants/app.constant'
|
||||||
|
|
||||||
const formatFileSize = (bytes: number): string => {
|
const formatFileSize = (bytes: number): string => {
|
||||||
if (bytes === 0) return '0 B'
|
if (bytes === 0) return '0 B'
|
||||||
|
|
@ -58,10 +59,15 @@ const RecentDocuments: React.FC<{ documents: DocumentDto[] }> = ({ documents })
|
||||||
<button
|
<button
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
const url = FILE_URL(doc.path, doc.tenantId)
|
||||||
const link = document.createElement('a')
|
const link = document.createElement('a')
|
||||||
link.href = `/cdn/${doc.path}`
|
link.href = url
|
||||||
link.download = doc.name
|
link.download = doc.name
|
||||||
|
link.target = '_blank'
|
||||||
|
link.rel = 'noopener noreferrer'
|
||||||
|
document.body.appendChild(link)
|
||||||
link.click()
|
link.click()
|
||||||
|
document.body.removeChild(link)
|
||||||
}}
|
}}
|
||||||
className="p-2 hover:bg-blue-100 dark:hover:bg-blue-900/30 rounded-lg transition-colors group"
|
className="p-2 hover:bg-blue-100 dark:hover:bg-blue-900/30 rounded-lg transition-colors group"
|
||||||
title={translate('::App.Platform.Intranet.Widgets.RecentDocuments.Download')}
|
title={translate('::App.Platform.Intranet.Widgets.RecentDocuments.Download')}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue