Skip to content

Conversation

PhiRho
Copy link
Collaborator

@PhiRho PhiRho commented Jun 13, 2025

Make it possible for a system admin to configure a specific pricing table to offer free-stuff to people.

PhiRho added 6 commits June 13, 2025 15:33
- Enhanced the pricing table creation and retrieval logic to support both standard and always-free pricing tables.
- Updated the `create_pricing_table` endpoint to differentiate between standard and always-free tables based on the `table_type` parameter.
- Modified the `get_pricing_table` endpoint to return the appropriate pricing table based on the team's status (always-free or standard).
- Added a new `is_always_free` field to the `DBTeam` model to track team status.
- Implemented tests for creating and retrieving pricing tables, including scenarios for always-free teams and validation of access permissions.
- Ensured proper error handling for cases where the expected pricing table does not exist.
…tus functionality

- Changed email template data keys from "team_name" to "name" and "pricing_url" to "dashboard_url" in the SES email sending logic.
- Added a section in TeamsPage to display always-free status with a button to resend the request email for always-free teams.
- Updated tests to reflect changes in email template name and data structure.
- Implemented a file-based locking mechanism to prevent concurrent execution of the monitor_teams job.
- Created a temporary lock file to manage access, ensuring that only one instance of the job runs at a time.
- Added error handling for job execution and lock acquisition, with appropriate logging for success and failure cases.
- Cleaned up the lock file after job completion to maintain a tidy environment.
- Updated the logic in the monitor_team_keys function to ensure that current spend and budget values default to 0.0 if LiteLLM returns None.
- This change improves robustness by preventing potential errors when accessing spend and budget information.
Copy link

@czue czue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had a couple small things but looks good. didn't review tests or front end code

if not pricing_table:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Always-free pricing table not found"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only reason all of this has to be duplicated is to change this text, yeah? is that important? if not, you could just assign the pricing table in an if/else block and remove the duplicated raise and returns

app/main.py Outdated
from datetime import UTC

# Set timezone environment variable to prevent tzlocal warning
os.environ['TZ'] = 'UTC'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: guessing it's fine but this feels a bit weird (I'm not familiar with this error so don't have an alternate proposal).


async def monitor_teams_job():
# Create a lock file in the temp directory
lock_file = os.path.join(tempfile.gettempdir(), 'monitor_teams.lock')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of the lock here? do we ever have to worry about this job running on multiple machines (if so, a file-based approach might not work). separately, i wonder if there's a library that might support this more reusably/reliably

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scheduled task sends an email in certain cases. At the moment, because of the way uvicorn is started it sends four of them. I will look at if there is a library which can do the locking with a DB table rather, but will do that when I add certain other resilience aspects (like what happens if the run is interrupted). This is sufficient for now.

PhiRho added 2 commits June 18, 2025 11:29
- Simplified the logic in the `get_pricing_table` function to remove redundant checks for always-free pricing tables.
- Adjusted the corresponding test to reflect the updated error message.
@PhiRho PhiRho merged commit 2673b11 into dev Jun 18, 2025
1 check passed
@PhiRho PhiRho deleted the free-stuff branch June 18, 2025 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants