Skip to content

Commit

Permalink
Merge pull request #85 from gitautoai/kan-183-add-time-to-usage-table
Browse files Browse the repository at this point in the history
Kan 183 Add time to usage table
  • Loading branch information
nikitamalinov authored Apr 27, 2024
2 parents 4bcd682 + 6d45d57 commit 27b2ce8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions services/gitauto_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
from uuid import uuid4


# Local imports
from config import (
PRODUCT_ID,
Expand Down Expand Up @@ -39,6 +40,8 @@

async def handle_gitauto(payload: GitHubLabeledPayload, trigger_type: str) -> None:
"""Core functionality to create comments on issue, create PRs, and update progress."""
current_time = time.time()

# Extract label and validate it
if trigger_type == "label" and payload["label"]["name"] != PRODUCT_ID:
return
Expand Down Expand Up @@ -223,9 +226,11 @@ async def handle_gitauto(payload: GitHubLabeledPayload, trigger_type: str) -> No
body=pull_request_completed(pull_request_url=pull_request_url),
)

end_time = time.time()
supabase_manager.complete_and_update_usage_record(
usage_record_id=usage_record_id,
token_input=token_input,
token_output=token_output,
total_seconds=int(end_time - current_time),
)
return
2 changes: 2 additions & 0 deletions services/supabase/gitauto_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def complete_and_update_usage_record(
usage_record_id: int,
token_input: int,
token_output: int,
total_seconds: int,
) -> None:
"""Add agent information to usage record and set is_completed to True."""
try:
Expand All @@ -25,6 +26,7 @@ def complete_and_update_usage_record(
"is_completed": True,
"token_input": token_input,
"token_output": token_output,
"total_seconds": total_seconds,
}
).eq(column="id", value=usage_record_id).execute()
except Exception as e:
Expand Down
2 changes: 2 additions & 0 deletions tests/services/supabase/test_gitauto_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_create_update_user_request_works() -> None:
usage_record_id=usage_record_id,
token_input=1000,
token_output=100,
total_seconds=100,
)
is None
)
Expand Down Expand Up @@ -118,6 +119,7 @@ def test_complete_and_update_usage_record_only_updates_one_record() -> None:
usage_record_id=usage_record_id,
token_input=1000,
token_output=100,
total_seconds=100,
)
is None
)
Expand Down
1 change: 1 addition & 0 deletions tests/services/supabase/test_users_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def test_create_and_update_user_request_works() -> None:
usage_record_id=usage_record_id,
token_input=1000,
token_output=100,
total_seconds=100,
)
is None
)
Expand Down

0 comments on commit 27b2ce8

Please sign in to comment.