视频转码接入队列(asynq)
This commit is contained in:
@@ -14,6 +14,8 @@ type Store interface {
|
||||
IsUniqueViolation(err error) bool
|
||||
IsForeignKeyViolation(err error) bool
|
||||
IsNoRows(err error) bool
|
||||
|
||||
CreateVideoTx(ctx context.Context, arg CreateVideoTxParam) (CreateVideoTxResult, error)
|
||||
}
|
||||
|
||||
type SQLStore struct {
|
||||
|
||||
29
internal/db/tx_create_video.go
Normal file
29
internal/db/tx_create_video.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package db
|
||||
|
||||
import "context"
|
||||
|
||||
type CreateVideoTxParam struct {
|
||||
CreateVideoParams
|
||||
AfterCreate func(video Video) error
|
||||
}
|
||||
|
||||
type CreateVideoTxResult struct {
|
||||
Video Video
|
||||
}
|
||||
|
||||
func (store *SQLStore) CreateVideoTx(ctx context.Context, arg CreateVideoTxParam) (CreateVideoTxResult, error) {
|
||||
var result CreateVideoTxResult
|
||||
|
||||
err := store.ExecTx(ctx, func(q *Queries) error {
|
||||
var err error
|
||||
|
||||
result.Video, err = q.CreateVideo(ctx, arg.CreateVideoParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return arg.AfterCreate(result.Video)
|
||||
})
|
||||
|
||||
return result, err
|
||||
}
|
||||
Reference in New Issue
Block a user