Changeset ad058b3 for src


Ignore:
Timestamp:
09/07/21 20:18:53 (3 years ago)
Author:
Стојков Марко <mst@…>
Branches:
dev
Children:
6e1aa47
Parents:
f64836d
Message:

Hangfire is supported

Location:
src/FinkiChattery
Files:
13 added
9 edited
2 moved

Legend:

Unmodified
Added
Removed
  • src/FinkiChattery/FinkiChattery.Api/FinkiChattery.Api.csproj

    rf64836d rad058b3  
    88    <PackageReference Include="FluentValidation" Version="9.5.4" />
    99    <PackageReference Include="FluentValidation.AspNetCore" Version="9.5.4" />
     10    <PackageReference Include="Hangfire.AspNetCore" Version="1.7.25" />
     11    <PackageReference Include="Hangfire.SqlServer" Version="1.7.25" />
    1012    <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
    1113    <PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
     
    2325  </ItemGroup>
    2426
     27  <ItemGroup>
     28    <Folder Include="Controllers\" />
     29  </ItemGroup>
     30
    2531
    2632</Project>
  • src/FinkiChattery/FinkiChattery.Api/Services/RegisterServices.cs

    rf64836d rad058b3  
    66using FinkiChattery.Persistence.Context;
    77using FinkiChattery.Persistence.Models;
     8using Hangfire;
     9using Hangfire.SqlServer;
    810using MediatR;
    911using Microsoft.AspNetCore.Authentication.JwtBearer;
     
    1214using Microsoft.Extensions.Configuration;
    1315using Microsoft.Extensions.DependencyInjection;
     16using System;
    1417
    1518namespace FinkiChattery.Api.Server
     
    2528            // TODO: REGISTER MEDIATOR HANDLERS WHEN WE CREATE FIRST COMMAND SMENI SO DOMAIN KLASA
    2629            services.AddMediatR(typeof(RegisterServices));
     30        }
     31
     32        public static void AddHangfireService(this IServiceCollection services, IConfiguration configuration)
     33        {
     34            services.AddHangfire(x =>
     35            {
     36                x.UseSqlServerStorage(configuration.GetConnectionString("HangfireConnection"), new SqlServerStorageOptions
     37                {
     38                    CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
     39                    SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
     40                    QueuePollInterval = TimeSpan.Zero,
     41                    UseRecommendedIsolationLevel = true,
     42                    DisableGlobalLocks = true
     43                });
     44                x.UseMediatR();
     45            });
     46            services.AddHangfireServer();
    2747        }
    2848
  • src/FinkiChattery/FinkiChattery.Api/Startup.cs

    rf64836d rad058b3  
    33using FinkiChattery.Api.Services;
    44using FinkiChattery.Persistence.Context;
     5using Hangfire;
    56using Microsoft.AspNetCore.Builder;
    67using Microsoft.AspNetCore.Hosting;
     
    3435            services.AddRepos();
    3536            services.AddAwsClient(Configuration);
     37            services.AddHangfireService(Configuration);
    3638
    3739            services.AddDbContext<ApplicationDbContext>(options =>
     
    7274            {
    7375                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
     76                endpoints.MapHangfireDashboard();
    7477            });
    7578        }
  • src/FinkiChattery/FinkiChattery.Api/appsettings.Development.json

    rf64836d rad058b3  
    3131  },
    3232  "ConnectionStrings": {
    33     "DefaultConnection": "data source=.;initial catalog=FinkiChattery;integrated security=True;application name=FinkiChattery Base App;Pooling=true;Min Pool Size=5;Max Pool Size=30;"
     33    "DefaultConnection": "data source=.;initial catalog=FinkiChattery;integrated security=True;application name=FinkiChattery Base App;Pooling=true;Min Pool Size=5;Max Pool Size=30;",
     34    "HangfireConnection": "data source=.;initial catalog=FinkiChatteryHangfire;integrated security=True;application name=FinkiChattery Hangfire App;Pooling=true;Min Pool Size=5;Max Pool Size=30;"
    3435  }
    3536}
  • src/FinkiChattery/FinkiChattery.Common/FinkiChattery.Common.csproj

    rf64836d rad058b3  
    77  <ItemGroup>
    88    <PackageReference Include="FluentValidation" Version="9.5.4" />
     9    <PackageReference Include="Hangfire.Core" Version="1.7.25" />
    910    <PackageReference Include="MediatR" Version="9.0.0" />
    1011    <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
  • src/FinkiChattery/FinkiChattery.Common/Mediator/EventService.cs

    rf64836d rad058b3  
    1 using FinkiChattery.Common.Mediator.Interfaces;
     1using FinkiChattery.Common.Mediator.Contracs;
     2using FinkiChattery.Common.Mediator.Interfaces;
     3using Hangfire;
    24
    35namespace FinkiChattery.Common.Mediator
     
    57    public class EventService : IEventService
    68    {
     9        public EventService(IBackgroundJobClient backgroundJob)
     10        {
     11            BackgroundJob = backgroundJob;
     12        }
     13
     14        public IBackgroundJobClient BackgroundJob { get; }
     15
     16        public void Enqueue(string jobName, IEvent request)
     17        {
     18            BackgroundJob.Enqueue<IMediatorService>(bridge => bridge.PublishAsync(jobName, request));
     19        }
     20
     21        public void Enqueue(IEvent request)
     22        {
     23            BackgroundJob.Enqueue<IMediatorService>(bridge => bridge.PublishAsync(request));
     24        }
    725    }
    826}
  • src/FinkiChattery/FinkiChattery.Common/Mediator/Interfaces/IEventService.cs

    rf64836d rad058b3  
    1 namespace FinkiChattery.Common.Mediator.Interfaces
     1using FinkiChattery.Common.Mediator.Contracs;
     2
     3namespace FinkiChattery.Common.Mediator.Interfaces
    24{
    35    public interface IEventService
    46    {
     7        void Enqueue(string jobName, IEvent request);
     8
     9        void Enqueue(IEvent request);
    510    }
    611}
  • src/FinkiChattery/FinkiChattery.Common/Mediator/Interfaces/IMediatorService.cs

    rf64836d rad058b3  
    1010
    1111        Task<TResponse> SendAsync<TResponse>(ICommand<TResponse> request);
     12
     13        Task PublishAsync<TNotification>(TNotification notification) where TNotification : IEvent;
     14
     15        Task PublishAsync<TNotification>(string jobName, TNotification notification) where TNotification : IEvent;
    1216    }
    1317}
  • src/FinkiChattery/FinkiChattery.Common/Mediator/MediatorService.cs

    rf64836d rad058b3  
    1 using MediatR;
    2 using FinkiChattery.Common.Mediator.Contracs;
     1using FinkiChattery.Common.Mediator.Contracs;
    32using FinkiChattery.Common.Mediator.Interfaces;
     3using MediatR;
     4using System.ComponentModel;
    45using System.Threading;
    56using System.Threading.Tasks;
     
    2526            return await mediator.Send(request);
    2627        }
     28
     29        public async Task PublishAsync<TNotification>(TNotification notification) where TNotification : IEvent
     30        {
     31            await mediator.Publish(notification, default);
     32        }
     33
     34        [DisplayName("{0}")]
     35        public async Task PublishAsync<TNotification>(string jobName, TNotification notification) where TNotification : IEvent
     36        {
     37            await mediator.Publish(notification, default);
     38        }
    2739    }
    2840}
  • src/FinkiChattery/FinkiChattery.HangfireDatabase/FinkiChattery.HangfireDatabase.sqlproj

    rf64836d rad058b3  
    1414    <RootNamespace>FinkiChattery.HangfireDatabase</RootNamespace>
    1515    <AssemblyName>FinkiChattery.HangfireDatabase</AssemblyName>
    16     <ModelCollation>1033, CI</ModelCollation>
     16    <ModelCollation>1033,CI</ModelCollation>
    1717    <DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
    1818    <DeployToDatabase>True</DeployToDatabase>
     
    2323    <IncludeCompositeObjects>True</IncludeCompositeObjects>
    2424    <TargetDatabaseSet>True</TargetDatabaseSet>
     25    <DefaultCollation>SQL_Latin1_General_CP1_CI_AS</DefaultCollation>
     26    <DefaultFilegroup>PRIMARY</DefaultFilegroup>
    2527  </PropertyGroup>
    2628  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    5759  <ItemGroup>
    5860    <Folder Include="Properties" />
     61    <Folder Include="HangFire\" />
     62    <Folder Include="HangFire\Tables\" />
     63    <Folder Include="Security\" />
     64  </ItemGroup>
     65  <ItemGroup>
     66    <Build Include="HangFire\Tables\Schema.sql" />
     67    <Build Include="HangFire\Tables\Job.sql" />
     68    <Build Include="HangFire\Tables\State.sql" />
     69    <Build Include="HangFire\Tables\JobParameter.sql" />
     70    <Build Include="HangFire\Tables\JobQueue.sql" />
     71    <Build Include="HangFire\Tables\Server.sql" />
     72    <Build Include="HangFire\Tables\List.sql" />
     73    <Build Include="HangFire\Tables\Set.sql" />
     74    <Build Include="HangFire\Tables\Counter.sql" />
     75    <Build Include="HangFire\Tables\Hash.sql" />
     76    <Build Include="HangFire\Tables\AggregatedCounter.sql" />
     77    <Build Include="Security\HangFire.sql" />
    5978  </ItemGroup>
    6079</Project>
Note: See TracChangeset for help on using the changeset viewer.