Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go
1.7 KB
Raw Blame
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.31.1
// source: runtime_rate_limit.sql

package db

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const getRuntimeRateLimit = `-- name: GetRuntimeRateLimit :one
SELECT runtime_id, workspace_id, snapshot, observed_at, updated_at
FROM runtime_rate_limit
WHERE runtime_id = $1
`

func (q *Queries) GetRuntimeRateLimit(ctx context.Context, runtimeID pgtype.UUID) (RuntimeRateLimit, error) {
	row := q.db.QueryRow(ctx, getRuntimeRateLimit, runtimeID)
	var i RuntimeRateLimit
	err := row.Scan(
		&i.RuntimeID,
		&i.WorkspaceID,
		&i.Snapshot,
		&i.ObservedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const upsertRuntimeRateLimit = `-- name: UpsertRuntimeRateLimit :exec
INSERT INTO runtime_rate_limit (runtime_id, workspace_id, snapshot, observed_at)
VALUES ($1, $2, $3, $4)
ON CONFLICT (runtime_id) DO UPDATE
SET snapshot = EXCLUDED.snapshot,
    workspace_id = EXCLUDED.workspace_id,
    observed_at = EXCLUDED.observed_at,
    updated_at = now()
WHERE runtime_rate_limit.observed_at <= EXCLUDED.observed_at
`

type UpsertRuntimeRateLimitParams struct {
	RuntimeID   pgtype.UUID        `json:"runtime_id"`
	WorkspaceID pgtype.UUID        `json:"workspace_id"`
	Snapshot    []byte             `json:"snapshot"`
	ObservedAt  pgtype.Timestamptz `json:"observed_at"`
}

// One snapshot per runtime (MUL-9427). Concurrent runs on the same runtime
// each report their own view; the newest observation wins, so a late report
// from an older run cannot roll the snapshot back.
func (q *Queries) UpsertRuntimeRateLimit(ctx context.Context, arg UpsertRuntimeRateLimitParams) error {
	_, err := q.db.Exec(ctx, upsertRuntimeRateLimit,
		arg.RuntimeID,
		arg.WorkspaceID,
		arg.Snapshot,
		arg.ObservedAt,
	)
	return err
}