2
0

Experimental Async Refreshes API (#34918)

This commit is contained in:
David Roetzel
2025-06-12 16:54:00 +02:00
committed by GitHub
parent 825312d4b0
commit 319fbbbfac
11 changed files with 437 additions and 13 deletions

View File

@@ -6,15 +6,39 @@ class HomeFeed < Feed
super(:home, account.id)
end
def async_refresh
@async_refresh ||= AsyncRefresh.new(redis_regeneration_key)
end
def regenerating?
redis.exists?("account:#{@account.id}:regeneration")
async_refresh.running?
rescue Redis::CommandError
retry if upgrade_redis_key!
end
def regeneration_in_progress!
redis.set("account:#{@account.id}:regeneration", true, nx: true, ex: 1.day.seconds)
@async_refresh = AsyncRefresh.create(redis_regeneration_key)
rescue Redis::CommandError
upgrade_redis_key!
end
def regeneration_finished!
redis.del("account:#{@account.id}:regeneration")
async_refresh.finish!
rescue Redis::CommandError
retry if upgrade_redis_key!
end
private
def redis_regeneration_key
@redis_regeneration_key = "account:#{@account.id}:regeneration"
end
def upgrade_redis_key!
if redis.type(redis_regeneration_key) == 'string'
redis.del(redis_regeneration_key)
regeneration_in_progress!
true
end
end
end