mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat: heartbeat (#108)
* feat: heartbeat * feat: independent heartbeat model
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: heartbeat_logs.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const completeHeartbeatLog = `-- name: CompleteHeartbeatLog :one
|
||||
UPDATE bot_heartbeat_logs
|
||||
SET status = $2,
|
||||
result_text = $3,
|
||||
error_message = $4,
|
||||
usage = $5,
|
||||
completed_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, bot_id, status, result_text, error_message, usage, started_at, completed_at
|
||||
`
|
||||
|
||||
type CompleteHeartbeatLogParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Status string `json:"status"`
|
||||
ResultText string `json:"result_text"`
|
||||
ErrorMessage string `json:"error_message"`
|
||||
Usage []byte `json:"usage"`
|
||||
}
|
||||
|
||||
func (q *Queries) CompleteHeartbeatLog(ctx context.Context, arg CompleteHeartbeatLogParams) (BotHeartbeatLog, error) {
|
||||
row := q.db.QueryRow(ctx, completeHeartbeatLog,
|
||||
arg.ID,
|
||||
arg.Status,
|
||||
arg.ResultText,
|
||||
arg.ErrorMessage,
|
||||
arg.Usage,
|
||||
)
|
||||
var i BotHeartbeatLog
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Status,
|
||||
&i.ResultText,
|
||||
&i.ErrorMessage,
|
||||
&i.Usage,
|
||||
&i.StartedAt,
|
||||
&i.CompletedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createHeartbeatLog = `-- name: CreateHeartbeatLog :one
|
||||
INSERT INTO bot_heartbeat_logs (bot_id, started_at)
|
||||
VALUES ($1, now())
|
||||
RETURNING id, bot_id, status, result_text, error_message, usage, started_at, completed_at
|
||||
`
|
||||
|
||||
func (q *Queries) CreateHeartbeatLog(ctx context.Context, botID pgtype.UUID) (BotHeartbeatLog, error) {
|
||||
row := q.db.QueryRow(ctx, createHeartbeatLog, botID)
|
||||
var i BotHeartbeatLog
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Status,
|
||||
&i.ResultText,
|
||||
&i.ErrorMessage,
|
||||
&i.Usage,
|
||||
&i.StartedAt,
|
||||
&i.CompletedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteHeartbeatLogsByBot = `-- name: DeleteHeartbeatLogsByBot :exec
|
||||
DELETE FROM bot_heartbeat_logs WHERE bot_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteHeartbeatLogsByBot(ctx context.Context, botID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteHeartbeatLogsByBot, botID)
|
||||
return err
|
||||
}
|
||||
|
||||
const listHeartbeatLogsByBot = `-- name: ListHeartbeatLogsByBot :many
|
||||
SELECT id, bot_id, status, result_text, error_message, usage, started_at, completed_at
|
||||
FROM bot_heartbeat_logs
|
||||
WHERE bot_id = $1
|
||||
AND ($2::timestamptz IS NULL OR started_at < $2::timestamptz)
|
||||
ORDER BY started_at DESC
|
||||
LIMIT $3
|
||||
`
|
||||
|
||||
type ListHeartbeatLogsByBotParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Column2 pgtype.Timestamptz `json:"column_2"`
|
||||
Limit int32 `json:"limit"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListHeartbeatLogsByBot(ctx context.Context, arg ListHeartbeatLogsByBotParams) ([]BotHeartbeatLog, error) {
|
||||
rows, err := q.db.Query(ctx, listHeartbeatLogsByBot, arg.BotID, arg.Column2, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []BotHeartbeatLog
|
||||
for rows.Next() {
|
||||
var i BotHeartbeatLog
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Status,
|
||||
&i.ResultText,
|
||||
&i.ErrorMessage,
|
||||
&i.Usage,
|
||||
&i.StartedAt,
|
||||
&i.CompletedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
Reference in New Issue
Block a user