MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / _periodic_refresh_loop

Function _periodic_refresh_loop

browser_utils/cookie_refresh.py:146–176  ·  view source on GitHub ↗

Background task that periodically saves cookies.

()

Source from the content-addressed store, hash-verified

144
145
146async def _periodic_refresh_loop():
147 """
148 Background task that periodically saves cookies.
149 """
150 global _last_refresh_time
151
152 logger.info(
153 f"🔄 Periodic cookie refresh started "
154 f"(interval: {COOKIE_REFRESH_INTERVAL_SECONDS}s)"
155 )
156
157 # Initial delay before first save
158 await asyncio.sleep(COOKIE_REFRESH_INTERVAL_SECONDS)
159
160 while True:
161 try:
162 elapsed = time.time() - _last_refresh_time
163 if elapsed >= COOKIE_REFRESH_INTERVAL_SECONDS:
164 logger.debug("Periodic cookie refresh triggered")
165 await save_current_cookies_to_profile()
166
167 # Sleep until next check
168 await asyncio.sleep(min(60, COOKIE_REFRESH_INTERVAL_SECONDS // 2))
169
170 except asyncio.CancelledError:
171 logger.info("🔄 Periodic cookie refresh task cancelled")
172 raise
173 except Exception as e:
174 logger.error(f"Error in periodic cookie refresh: {e}")
175 # Continue running despite errors
176 await asyncio.sleep(60)
177
178
179def start_periodic_refresh() -> Optional[asyncio.Task]:

Callers 1

start_periodic_refreshFunction · 0.85

Calls 4

infoMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected