feat: add dead letter queue
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
32
internal/deadletter/repositories/db.go
Normal file
32
internal/deadletter/repositories/db.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.23.0
|
||||
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
35
internal/deadletter/repositories/models.go
Normal file
35
internal/deadletter/repositories/models.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.23.0
|
||||
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type DeadLetter struct {
|
||||
ScheduleID uuid.UUID `json:"schedule_id"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ModelSchedule struct {
|
||||
ModelName string `json:"model_name"`
|
||||
LastRun pgtype.Timestamptz `json:"last_run"`
|
||||
}
|
||||
|
||||
type WorkSchedule struct {
|
||||
ScheduleID uuid.UUID `json:"schedule_id"`
|
||||
WorkerID uuid.UUID `json:"worker_id"`
|
||||
StartRun pgtype.Timestamptz `json:"start_run"`
|
||||
EndRun pgtype.Timestamptz `json:"end_run"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
type WorkerRegister struct {
|
||||
WorkerID uuid.UUID `json:"worker_id"`
|
||||
Capacity int32 `json:"capacity"`
|
||||
HeartBeat pgtype.Timestamptz `json:"heart_beat"`
|
||||
}
|
18
internal/deadletter/repositories/querier.go
Normal file
18
internal/deadletter/repositories/querier.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.23.0
|
||||
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
InsertDeadLetter(ctx context.Context, scheduleID uuid.UUID) error
|
||||
Ping(ctx context.Context) (int32, error)
|
||||
}
|
||||
|
||||
var _ Querier = (*Queries)(nil)
|
39
internal/deadletter/repositories/queries.sql.go
Normal file
39
internal/deadletter/repositories/queries.sql.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.23.0
|
||||
// source: queries.sql
|
||||
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const insertDeadLetter = `-- name: InsertDeadLetter :exec
|
||||
INSERT INTO dead_letter
|
||||
(
|
||||
schedule_id
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
$1
|
||||
)
|
||||
`
|
||||
|
||||
func (q *Queries) InsertDeadLetter(ctx context.Context, scheduleID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, insertDeadLetter, scheduleID)
|
||||
return err
|
||||
}
|
||||
|
||||
const ping = `-- name: Ping :one
|
||||
SELECT 1
|
||||
`
|
||||
|
||||
func (q *Queries) Ping(ctx context.Context) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, ping)
|
||||
var column_1 int32
|
||||
err := row.Scan(&column_1)
|
||||
return column_1, err
|
||||
}
|
Reference in New Issue
Block a user