Skip to content

Commit

Permalink
Run worker by options
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Aug 30, 2024
1 parent ef1b4b0 commit 9786b81
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
28 changes: 20 additions & 8 deletions ArenaService/ArenaService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var configuration = builder.Configuration;
var redisConnectionString = configuration["Redis:ConnectionString"]!;
var timeOut = int.Parse(configuration["Redis:TimeOut"]!);
var enableWorker = bool.Parse(configuration["Worker"]!);
var configurationOptions = new ConfigurationOptions
{
EndPoints = { redisConnectionString },
Expand All @@ -24,22 +25,33 @@

// Add services to the container.
builder.Services
.AddSingleton<RpcClient>()
.AddHostedService<RpcService>()
.AddSingleton(new PrivateKey())
.AddSingleton<IConnectionMultiplexer>(_ => redis)
.AddSingleton<RpcNodeHealthCheck>()
.AddSingleton<IRedisArenaParticipantsService, RedisArenaParticipantsService>()
.AddHostedService<ArenaParticipantsWorker>()
.AddScoped<ISchema, StandaloneSchema>()
.AddSingleton<RedisHealthCheck>()
.AddSingleton<IRedisArenaParticipantsService, RedisArenaParticipantsService>()
.AddHostedService<RedisHealthCheckService>()
.AddGraphQL(options => options.EnableMetrics = true)
.AddSystemTextJson()
.AddGraphTypes(typeof(AddressType))
.AddGraphTypes(typeof(StandaloneQuery));

builder.Services
if (enableWorker)
{
builder.Services
.AddSingleton<RpcClient>()
.AddHostedService<RpcService>()
.AddSingleton(new PrivateKey())
.AddSingleton<RpcNodeHealthCheck>()
.AddHostedService<ArenaParticipantsWorker>();
}

var healthChecksBuilder = builder.Services
.AddHealthChecks()
.AddCheck<RpcNodeHealthCheck>(nameof(RpcNodeHealthCheck));
.AddCheck<RedisHealthCheck>(nameof(RedisHealthCheck));
if (enableWorker)
{
healthChecksBuilder.AddCheck<RpcNodeHealthCheck>(nameof(RpcNodeHealthCheck));
}


var app = builder.Build();
Expand Down
11 changes: 3 additions & 8 deletions ArenaService/ArenaService/RedisArenaParticipantsService.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
using System.Text.Json;
using Libplanet.Crypto;
using StackExchange.Redis;

namespace ArenaService;

public class RedisArenaParticipantsService : IRedisArenaParticipantsService
public class RedisArenaParticipantsService(IConnectionMultiplexer redis, RedisHealthCheck redisHealthCheck)
: IRedisArenaParticipantsService
{
public const string SeasonKey = "season";

private readonly IDatabase _db;

public RedisArenaParticipantsService(IConnectionMultiplexer redis)
{
_db = redis.GetDatabase();
}
private readonly IDatabase _db = redis.GetDatabase();

public async Task<List<ArenaParticipant>> GetArenaParticipantsAsync(string key)
{
Expand Down
2 changes: 1 addition & 1 deletion ArenaService/ArenaService/StandaloneQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ArenaService;

public class StandaloneQuery : ObjectGraphType
{
public StandaloneQuery(RpcClient rpcClient, IRedisArenaParticipantsService redisArenaParticipantsService)
public StandaloneQuery(IRedisArenaParticipantsService redisArenaParticipantsService)
{
Field<NonNullGraphType<StateQuery>>(name: "stateQuery", resolve: _ => new StateQuery(redisArenaParticipantsService));
}
Expand Down

0 comments on commit 9786b81

Please sign in to comment.