1+ using Hangfire ;
12using HotChocolate . AspNetCore ;
23using Lib9c . GraphQL . Extensions ;
34using Lib9c . GraphQL . InputObjects ;
@@ -46,21 +47,29 @@ [Service] IActionTypeRepository repo
4647 /// </summary>
4748 /// <param name="address">The address of the agent.</param>
4849 /// <returns>The agent state</returns>
49- public async Task < AgentState > GetAgentAsync ( Address address , [ Service ] IAgentRepository repo )
50+ public async Task < AgentState > GetAgentAsync (
51+ Address address ,
52+ [ Service ] IAgentRepository repo ,
53+ [ Service ] IBackgroundJobClient jobClient
54+ )
5055 {
5156 try
5257 {
5358 var document = await repo . GetByAddressAsync ( address ) ;
5459 if ( document . Metadata . StoredBlockIndex != 0 )
5560 {
56- HangfireJobs . EnqueueAgentStateRecovery ( address ) ;
61+ jobClient . Enqueue < IStateRecoveryService > ( service =>
62+ service . TryRecoverAgentStateAsync ( address )
63+ ) ;
5764 }
5865
5966 return document . Object ;
6067 }
6168 catch ( Mimir . MongoDB . Exceptions . DocumentNotFoundInMongoCollectionException )
6269 {
63- HangfireJobs . EnqueueAgentStateRecovery ( address ) ;
70+ jobClient . Enqueue < IStateRecoveryService > ( service =>
71+ service . TryRecoverAgentStateAsync ( address )
72+ ) ;
6473 throw ;
6574 }
6675 }
@@ -70,15 +79,21 @@ public async Task<AgentState> GetAgentAsync(Address address, [Service] IAgentRep
7079 /// </summary>
7180 /// <param name="address">The address of the avatar.</param>
7281 /// <returns>The avatar state</returns>
73- public async Task < AvatarState > GetAvatarAsync ( Address address , [ Service ] IAvatarRepository repo )
82+ public async Task < AvatarState > GetAvatarAsync (
83+ Address address ,
84+ [ Service ] IAvatarRepository repo ,
85+ [ Service ] IBackgroundJobClient jobClient
86+ )
7487 {
7588 try
7689 {
7790 return ( await repo . GetByAddressAsync ( address ) ) . Object ;
7891 }
7992 catch ( Mimir . MongoDB . Exceptions . DocumentNotFoundInMongoCollectionException )
8093 {
81- HangfireJobs . EnqueueAvatarStateRecovery ( address ) ;
94+ jobClient . Enqueue < IStateRecoveryService > ( service =>
95+ service . TryRecoverAvatarStateAsync ( address )
96+ ) ;
8297 throw ;
8398 }
8499 }
@@ -95,7 +110,8 @@ public async Task<string> GetBalanceAsync(
95110 CurrencyInput ? currency ,
96111 string ? currencyTicker ,
97112 Address address ,
98- [ Service ] IBalanceRepository repo
113+ [ Service ] IBalanceRepository repo ,
114+ [ Service ] IBackgroundJobClient jobClient
99115 )
100116 {
101117 try
@@ -118,7 +134,9 @@ [Service] IBalanceRepository repo
118134 {
119135 if ( currencyTicker ? . ToUpper ( ) == "NCG" )
120136 {
121- HangfireJobs . EnqueueNCGBalanceRecovery ( address ) ;
137+ jobClient . Enqueue < IStateRecoveryService > ( service =>
138+ service . TryRecoverNCGBalanceAsync ( address )
139+ ) ;
122140 }
123141 throw ;
124142 }
0 commit comments