94 lines
3.5 KiB
C#
94 lines
3.5 KiB
C#
using Amazon.DynamoDBv2;
|
|
using Amazon.DynamoDBv2.DocumentModel;
|
|
using Amazon.DynamoDBv2.Model;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
|
|
|
|
namespace GameServer;
|
|
|
|
public class CaliumEventTicker : EntityTicker
|
|
{
|
|
private DynamoDbClient? m_dynamoDb_client { get; set; } = null;
|
|
|
|
public CaliumEventTicker(double onTickIntervalMilliseconds, CancellationTokenSource? cts)
|
|
: base(EntityType.CaliumEventTicker, onTickIntervalMilliseconds, cts)
|
|
{
|
|
var server_logic = GameServerApp.getServerLogic();
|
|
m_dynamoDb_client = server_logic.getDynamoDbClient();
|
|
}
|
|
|
|
public override async Task onTaskTick()
|
|
{
|
|
NullReferenceCheckHelper.throwIfNull(m_dynamoDb_client, () => $"dynamodb client is null !!! ");
|
|
|
|
var calium_storage_entity = GameServerApp.getServerLogic().findGlobalEntity<CaliumStorageEntity>();
|
|
NullReferenceCheckHelper.throwIfNull(calium_storage_entity, () => "calium storage entity is null !!!");
|
|
|
|
var calium_event_action = calium_storage_entity.getEntityAction<CaliumEventAction>();
|
|
NullReferenceCheckHelper.throwIfNull(calium_event_action, () => $"calium_event_action is null !!! - {calium_storage_entity.toBasicString()}");
|
|
|
|
// 1. doc 가져오기
|
|
var search = await searchDocuments();
|
|
|
|
foreach (var doc in search.list)
|
|
{
|
|
var (result, change_doc) = await calium_event_action.updateCaliumEventStatus(doc, CaliumEventStatus.Regist, CaliumEventStatus.Sending);
|
|
if (result.isFail() || null == change_doc) continue;
|
|
|
|
// 2. 재전송 처리
|
|
_ = await sendCaliumEventAsync(change_doc);
|
|
}
|
|
}
|
|
|
|
public override string toBasicString()
|
|
{
|
|
return $"{this.getTypeName()}";
|
|
}
|
|
|
|
public override string toSummaryString()
|
|
{
|
|
return $"{this.getTypeName()}";
|
|
}
|
|
|
|
private async Task<Result> sendCaliumEventAsync(CaliumEventDoc sendDoc)
|
|
{
|
|
var server_logic = GameServerApp.getServerLogic();
|
|
var calium_event_entity = server_logic.findGlobalEntity<CaliumStorageEntity>();
|
|
NullReferenceCheckHelper.throwIfNull(calium_event_entity, () => "calium_event_entity is null !!!");
|
|
|
|
var calium_event_action = calium_event_entity.getEntityAction<CaliumEventAction>();
|
|
NullReferenceCheckHelper.throwIfNull(calium_event_action, () => $"calium_event_action is null !!! - {calium_event_entity.toBasicString()}");
|
|
|
|
var result = await calium_event_action.sendCaliumEventFromDB(sendDoc);
|
|
return result;
|
|
}
|
|
|
|
private async Task<(Result result, List<CaliumEventDoc> list)> searchDocuments()
|
|
{
|
|
NullReferenceCheckHelper.throwIfNull(m_dynamoDb_client, () => $"dynamodb client is null !!! ");
|
|
|
|
var query_config = new QueryOperationConfig();
|
|
query_config.Filter.AddCondition(PrimaryKey.PK_Define, QueryOperator.Equal, CaliumEventDoc.pk);
|
|
query_config.Limit = 10;
|
|
query_config.FilterExpression = new Expression
|
|
{
|
|
ExpressionStatement = "CaliumEventAttrib.#status = :statusValue",
|
|
ExpressionAttributeNames = new Dictionary<string, string>
|
|
{
|
|
{ "#status", "status" }
|
|
},
|
|
ExpressionAttributeValues = new Dictionary<string, DynamoDBEntry>
|
|
{
|
|
{ ":statusValue", CaliumEventStatus.Regist.ToString() }
|
|
}
|
|
};
|
|
|
|
var list = await m_dynamoDb_client.simpleQueryDocTypesWithQueryOperationConfig<CaliumEventDoc>(query_config);
|
|
|
|
return list;
|
|
}
|
|
} |