Skip to content

Hangfire added #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Tinkoff.ISA.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using Microsoft.AspNetCore;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace Tinkoff.ISA.API
{
public class Program
{
public static void Main(string[] args)
public static Task Main(string[] args)
{
CreateWebHostBuilder(args).UseUrls("http://*:5000").Build().Run();
return CreateWebHostBuilder(args).UseUrls("http://*:5000").Build().RunAsync();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason to change it to RunAsync? Is there any other processes?
Is there any difference in runtime level?

}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
Expand Down
44 changes: 43 additions & 1 deletion src/Tinkoff.ISA.API/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
using System.IO;
using AutoMapper;
using Hangfire;
using Hangfire.Common;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused directive

using Hangfire.Mongo;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need it here?

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Tinkoff.ISA.AppLayer;
using Tinkoff.ISA.AppLayer.Jobs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jobs in API?

using Tinkoff.ISA.Infrastructure.Settings;
using Tinkoff.ISA.DAL;
using Tinkoff.ISA.DAL.Common;
using Tinkoff.ISA.Infrastructure.Configuration;
using Tinkoff.ISA.Infrastructure.Extensions;
using Tinkoff.ISA.Infrastructure.MongoDb;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see any reason to add reference with MongoDb here.

using IHostingEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;

namespace Tinkoff.ISA.API
Expand Down Expand Up @@ -40,10 +45,31 @@ public void ConfigureServices(IServiceCollection services)
services.AddAppDependencies();
services.AddMvc();
services.AddAutoMapper();
services.AddHangfire((serviceProvider, config) =>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems better to move it to Tinkoff.Isa.Infrastructure project, do you agree? to avoid duplications in API, Scheduler, SchedulerUI

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to have Hangfire in API?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can remove it?

{
var mongoContext = serviceProvider
.GetService<IMongoContext>();

config.UseMongoStorage(
mongoContext.MongoClient.Settings,
"Jobs",
new MongoStorageOptions
{
MigrationOptions = new MongoMigrationOptions
{
Strategy = MongoMigrationStrategy.Drop,
BackupStrategy = MongoBackupStrategy.Collections
}
});
});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove also here :)

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory,
IRecurringJobManager recurringJobManager)
{
var logSettings = _configuration.GetSection("Logging").Get<LoggingSettings>();

Expand All @@ -60,6 +86,22 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
}

app.UseMvc();

recurringJobManager.AddOrUpdate<JiraJob>(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add this reference to have an ability to configure new providers in main ISA project.
Further this code should be in Tinkoff.ISA.Jira, Tinkoff.ISA.Confluence and so on...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, are you sure about further code placement in ISA.Jira, ISA.Confluence, etc? I supposed that we will have a core job that will ask IKnowledgeProvider for data (is it possible to create a job per each registered provider?). Is it necessary to force providers to depend on Hangfire? Correct me, if I'm wrong.

nameof(JiraJob),
job => job.StartJob(),
Cron.Minutely
);
recurringJobManager.AddOrUpdate<ConfluenceJob>(
nameof(ConfluenceJob),
job => job.StartJob(),
Cron.Minutely
);
recurringJobManager.AddOrUpdate<MongoIndexingForElasticJob>(
nameof(MongoIndexingForElasticJob),
job => job.StartJob(),
Cron.Minutely
);
}
}
}
2 changes: 2 additions & 0 deletions src/Tinkoff.ISA.API/Tinkoff.ISA.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="8.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.6" />
<PackageReference Include="Hangfire.Mongo" Version="0.6.3" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
Expand Down
2 changes: 1 addition & 1 deletion src/Tinkoff.ISA.AppLayer/Jobs/ConfluenceJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Tinkoff.ISA.AppLayer.Jobs
{
internal class ConfluenceJob : IJob
public class ConfluenceJob : IJob
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to move this to another project

{
private readonly IConfluenceHttpClient _confluenceHttpClient;
private readonly IElasticsearchClient _elasticsearchClient;
Expand Down
1 change: 1 addition & 0 deletions src/Tinkoff.ISA.Infrastructure/MongoDb/IMongoContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Tinkoff.ISA.Infrastructure.MongoDb
{
public interface IMongoContext
{
IMongoClient MongoClient { get; }
IMongoCollection<TEntity> For<TEntity>();
}
}
2 changes: 2 additions & 0 deletions src/Tinkoff.ISA.Infrastructure/MongoDb/MongoContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class MongoContext : IMongoContext
private readonly Lazy<MongoClient> _isaMongoClient;
private readonly string _isaDbName;

public IMongoClient MongoClient => _isaMongoClient.Value;

static MongoContext()
{
BsonDefaults.GuidRepresentation = GuidRepresentation.Standard;
Expand Down

This file was deleted.

47 changes: 0 additions & 47 deletions src/Tinkoff.ISA.Scheduler.UnitTests/Scheduler/SchedulerTests.cs

This file was deleted.

7 changes: 0 additions & 7 deletions src/Tinkoff.ISA.Scheduler/Activators/IJobsActivator.cs

This file was deleted.

Loading