1- using CurseForge . APIClient ;
1+ using CFLookup . Models ;
2+ using CurseForge . APIClient ;
23using CurseForge . APIClient . Models . Mods ;
34using Hangfire ;
45using Hangfire . Server ;
@@ -29,6 +30,8 @@ public async static Task RunAsync(PerformContext context, IJobCancellationToken
2930 token . ThrowIfCancellationRequested ( ) ;
3031
3132 var cfClient = scope . ServiceProvider . GetRequiredService < ApiClient > ( ) ;
33+
34+ var influxWriter = scope . ServiceProvider . GetRequiredService < InfluxDBWriter > ( ) ;
3235
3336 var conn = scope . ServiceProvider . GetRequiredService < NpgsqlConnection > ( ) ;
3437 await conn . OpenAsync ( ) ;
@@ -77,6 +80,10 @@ public async static Task RunAsync(PerformContext context, IJobCancellationToken
7780
7881 token . ThrowIfCancellationRequested ( ) ;
7982
83+ var projectMetrics = new List < InfluxProjectMetric > ( ) ;
84+
85+ var currentTs = DateTime . UtcNow ;
86+
8087 foreach ( var mod in modList . Data )
8188 {
8289 token . ThrowIfCancellationRequested ( ) ;
@@ -237,13 +244,27 @@ ON CONFLICT (projectid, gameid) DO UPDATE
237244 } ) ;
238245
239246 batch . BatchCommands . Add ( cmd ) ;
247+
248+ projectMetrics . Add ( new InfluxProjectMetric
249+ {
250+ ProjectId = mod . Id ,
251+ GameId = mod . GameId ,
252+ DownloadCount = mod . DownloadCount ,
253+ ThumbsUpCount = mod . ThumbsUpCount ,
254+ GamePopularityRank = mod . GamePopularityRank ,
255+ Timestamp = currentTs
256+ } ) ;
240257
241258 if ( batch . BatchCommands . Count >= 1000 )
242259 {
243260 if ( ! await ExecuteBatchWithRetries ( batch ) )
244261 {
245262 // No-op for now, maybe Discord logs later
246263 }
264+
265+ await influxWriter . WriteBatchAsync ( "CFLookup" , "cf_project_data" , projectMetrics ) ;
266+ projectMetrics . Clear ( ) ;
267+ currentTs = DateTime . UtcNow ;
247268 token . ThrowIfCancellationRequested ( ) ;
248269 }
249270 }
@@ -254,6 +275,10 @@ ON CONFLICT (projectid, gameid) DO UPDATE
254275 {
255276 // No-op for now, maybe Discord logs later
256277 }
278+
279+ await influxWriter . WriteBatchAsync ( "CFLookup" , "cf_project_data" , projectMetrics ) ;
280+ projectMetrics . Clear ( ) ;
281+
257282 token . ThrowIfCancellationRequested ( ) ;
258283 }
259284
0 commit comments