Let's build a simple tracker to monitor use over time.
It has 3 components: 1. database table; 2. variable (in memory), 3. background task using fastapi background task. or using async io to do something like repeat every
back-end
Table looks something like this
Table name: usage (? or journal or history or something?)
Columns: timestamp, variable_name, value
Then in the database agent, make function report_result or journal_entry or something, that just is like agent.journal_entry(today(), "users", number_of_files. And then maybe something likefetch_result` that can take a particular variable name
functions
Now we need a few variables to store.
One could be num_bed_files, which just returns the COUNT of number of files, from the database. we just want to record how this changes over time.
For this one, write a background task that will run every 7 days, entering a journal entry.
Then, there can be another one, which is num_requests_served. For this one, we would have an environment variable in the app, maybe called USAGE ={}. Add to the endpoint an incrementer so whenever someone hits the endpoint X, you do USAGE['endponit-x'] += 1. Then, set up a background task to @repeat_every 7 days, and have it take the value and add it to the existing value in the database, with a new entry, under today's timestamp, and then reset the USAGE variable.
Let's build a simple tracker to monitor use over time.
It has 3 components: 1. database table; 2. variable (in memory), 3. background task using fastapi background task. or using async io to do something like repeat every
back-end
Table looks something like this
Table name:
usage
(? orjournal
orhistory
or something?) Columns: timestamp, variable_name, valueThen in the database agent, make function
report_result
orjournal_entry
or something, that just is likeagent.journal_entry(today(), "users", number_of_files. And then maybe something like
fetch_result` that can take a particular variable namefunctions
Now we need a few variables to store. One could be
num_bed_files
, which just returns the COUNT of number of files, from the database. we just want to record how this changes over time.For this one, write a
background task
that will run every 7 days, entering a journal entry.Then, there can be another one, which is num_requests_served. For this one, we would have an environment variable in the app, maybe called
USAGE ={}
. Add to the endpoint an incrementer so whenever someone hits the endpoint X, you doUSAGE['endponit-x'] += 1
. Then, set up a background task to@repeat_every
7 days, and have it take the value and add it to the existing value in the database, with a new entry, under today's timestamp, and then reset theUSAGE
variable.