Lambda Labs pricing tracking #146
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/issue-145-lambda-labs-pricing"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements automated pricing tracking for vision workers using the provider API per issue #145.
DB migration: Adds
started_atandtotal_costcolumns.worker-instance-start: Fetches price via
EstimateCost()after machine creation.worker-software-install: Verifies price hasn't changed; warns if so.
worker-instance-shutdown: Final price check, computes total cost, stores it.
computeUptime: Prefers
started_atovercreated_atwhen available.I added a number of in-line review comments. I've never tried that before, let me know if you have any trouble reading them.
@ -0,0 +1,7 @@-- +goose UpALTER TABLE vision_worker ADD COLUMN started_at TIMESTAMP;should be without a timezone
@ -211,0 +211,4 @@// it is used as the reference start time; otherwise createdAt is used.func computeUptime(createdAt time.Time, startedAt, shutdownAt *time.Time) float64 {s := startedAtif s == nil {Don't fall through to created time. If we don't have the started time then we can't calculate this accurately and we shouldn't try.
@ -78,0 +83,4 @@}if worker == nil {log.Printf("worker-instance-shutdown: worker %d not found during shutdown", workerID)return nilthis should be an error that crashes the job as it indicates programmer error.
@ -78,0 +89,4 @@// Determine the reference start time for cost calculationstartTime := worker.StartedAtif startTime == nil {startTime = &worker.CreatedAtsame as above, don't fail over to created at, give up on the time calculation.
@ -78,0 +93,4 @@}if startTime == nil {// Fallback: use creation timecreated := worker.CreatedAtduplicate code block, same as above block, remove it.
Pushed
80259734with the changes from the inline review. Here is how I addressed each comment:Comment on computeUptime: Removed the fallthrough to created_at. If startedAt is nil, computeUptime now returns 0 — no guessing. Both callers (VisionWorkersList and VisionWorkerShutdown) will show 0 uptime/cost for workers without a start time.
Comment on nil worker in markWorkerShutdown: Changed to return an error — programmer error, job will crash as it should. The earlier nil check in jobWorkerInstanceShutdown (initial fetch) was left as-is since it wasn't part of the new code.
Comment on created_at fallback in markWorkerShutdown: Removed both fallback blocks. When StartedAt is nil, totalCost stays 0 and we log that the cost wasn't calculated.
Comment on duplicate block: Removed — was unreachable anyway since the first fallback always set startTime from the non-pointer CreatedAt.
Comment on TIMESTAMP type: Note that PostgreSQL's bare TIMESTAMP is equivalent to TIMESTAMP WITHOUT TIME ZONE — it already stores no timezone info, so this is correct as-is. Re-using TIMESTAMP for consistency with the rest of the schema.