|
22 | 22 | from oasst_backend.prompt_repository import PromptRepository, UserRepository
|
23 | 23 | from oasst_backend.task_repository import TaskRepository, delete_expired_tasks
|
24 | 24 | from oasst_backend.tree_manager import TreeManager, halt_prompts_of_disabled_users
|
25 |
| -from oasst_backend.user_repository import User |
26 | 25 | from oasst_backend.user_stats_repository import UserStatsRepository, UserStatsTimeFrame
|
27 |
| -from oasst_backend.utils.database_utils import CommitMode, default_session_factory, managed_tx_function |
| 26 | +from oasst_backend.utils.database_utils import CommitMode, managed_tx_function |
28 | 27 | from oasst_shared.exceptions import OasstError, OasstErrorCode
|
29 | 28 | from oasst_shared.schemas import protocol as protocol_schema
|
30 | 29 | from oasst_shared.utils import utcnow
|
31 | 30 | from prometheus_fastapi_instrumentator import Instrumentator
|
32 | 31 | from pydantic import BaseModel
|
33 |
| -from sqlmodel import Session, select |
| 32 | +from sqlmodel import Session |
34 | 33 | from starlette.middleware.cors import CORSMiddleware
|
35 | 34 |
|
36 | 35 | # from worker.scheduled_tasks import create_task
|
@@ -139,8 +138,6 @@ async def http_callback(request: fastapi.Request, response: fastapi.Response, pe
|
139 | 138 | @app.on_event("startup")
|
140 | 139 | @managed_tx_function(auto_commit=CommitMode.COMMIT)
|
141 | 140 | def create_seed_data(session: Session):
|
142 |
| - # logger.debug("create_seed_data...") |
143 |
| - # create_task.delay("create_seed_data",2,3) |
144 | 141 | class DummyMessage(BaseModel):
|
145 | 142 | task_message_id: str
|
146 | 143 | user_message_id: str
|
@@ -289,53 +286,6 @@ def update_leader_board_total(session: Session) -> None:
|
289 | 286 | logger.exception("Error during user states update (total)")
|
290 | 287 |
|
291 | 288 |
|
292 |
| -@app.on_event("startup") |
293 |
| -@repeat_every(seconds=3600, wait_first=False) |
294 |
| -def update_user_streak() -> None: |
295 |
| - logger.debug("update_user_streak...") |
296 |
| - try: |
297 |
| - with default_session_factory() as session: |
298 |
| - current_time = utcnow() |
299 |
| - timedelta = current_time - startup_time |
300 |
| - if timedelta.days > 0: |
301 |
| - # Update only greater than 24 hours . Do nothing |
302 |
| - logger.debug("Process timedelta greater than 24h") |
303 |
| - statement = select(User) |
304 |
| - result = session.exec(statement).all() |
305 |
| - if result is not None: |
306 |
| - for user in result: |
307 |
| - last_activity_date = user.last_activity_date |
308 |
| - streak_last_day_date = user.streak_last_day_date |
309 |
| - # set NULL streak_days to 0 |
310 |
| - if user.streak_days is None: |
311 |
| - user.streak_days = 0 |
312 |
| - # if the user had completed a task |
313 |
| - if last_activity_date is not None: |
314 |
| - lastactitvitydelta = current_time - last_activity_date |
315 |
| - # if the user missed consecutive days of completing a task |
316 |
| - # reset the streak_days to 0 and set streak_last_day_date to the current_time |
317 |
| - if lastactitvitydelta.days > 1 or user.streak_days is None: |
318 |
| - user.streak_days = 0 |
319 |
| - user.streak_last_day_date = current_time |
320 |
| - # streak_last_day_date has a current timestamp in DB. Idealy should not be NULL. |
321 |
| - if streak_last_day_date is not None: |
322 |
| - streak_delta = current_time - streak_last_day_date |
323 |
| - # if user completed tasks on consecutive days then increment the streak days |
324 |
| - # update the streak_last_day_date to current time for the next calculation |
325 |
| - if streak_delta.days > 0: |
326 |
| - user.streak_days += 1 |
327 |
| - user.streak_last_day_date = current_time |
328 |
| - session.add(user) |
329 |
| - session.commit() |
330 |
| - |
331 |
| - else: |
332 |
| - logger.debug("Not yet 24hours since the process started! ...") |
333 |
| - |
334 |
| - except Exception as e: |
335 |
| - logger.error(str(e)) |
336 |
| - return |
337 |
| - |
338 |
| - |
339 | 289 | @app.on_event("startup")
|
340 | 290 | @repeat_every(seconds=60 * 60) # 1 hour
|
341 | 291 | @managed_tx_function(auto_commit=CommitMode.COMMIT)
|
|
0 commit comments