feat: add some new features
This commit is contained in:
@@ -72,7 +72,7 @@ func (e *PostCreated) Handler(msg *message.Message) ([]*message.Message, error)
|
||||
}
|
||||
|
||||
// cut video
|
||||
_, err = job.Insert(context.Background(), jobs.VideoCut{
|
||||
_, err = job.Insert(context.Background(), jobs.PostVideoCutJob{
|
||||
PostID: post.ID,
|
||||
Hash: video.Hash,
|
||||
TenantID: post.TenantID,
|
||||
@@ -83,7 +83,7 @@ func (e *PostCreated) Handler(msg *message.Message) ([]*message.Message, error)
|
||||
}
|
||||
|
||||
// extract audio
|
||||
_, err = job.Insert(context.Background(), jobs.VideoExtractAudio{
|
||||
_, err = job.Insert(context.Background(), jobs.PostVideoExtractAudioJob{
|
||||
PostID: post.ID,
|
||||
Hash: video.Hash,
|
||||
TenantID: post.TenantID,
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package jobs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
_ "git.ipao.vip/rogeecn/atom"
|
||||
_ "git.ipao.vip/rogeecn/atom/contracts"
|
||||
. "github.com/riverqueue/river"
|
||||
)
|
||||
|
||||
var (
|
||||
_ JobArgs = VideoCut{}
|
||||
_ JobArgsWithInsertOpts = VideoCut{}
|
||||
)
|
||||
|
||||
type VideoCut struct {
|
||||
PostID int64 `json:"post_id"`
|
||||
Hash string `json:"hash"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
// InsertOpts implements JobArgsWithInsertOpts.
|
||||
func (s VideoCut) InsertOpts() InsertOpts {
|
||||
return InsertOpts{
|
||||
Queue: QueueDefault,
|
||||
Priority: PriorityDefault,
|
||||
UniqueOpts: UniqueOpts{
|
||||
ByArgs: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (VideoCut) Kind() string {
|
||||
return "VideoCut"
|
||||
}
|
||||
|
||||
var _ Worker[VideoCut] = (*VideoCutWorker)(nil)
|
||||
|
||||
// @provider(job)
|
||||
type VideoCutWorker struct {
|
||||
WorkerDefaults[VideoCut]
|
||||
}
|
||||
|
||||
func (w *VideoCutWorker) NextRetry(job *Job[VideoCut]) time.Time {
|
||||
return time.Now().Add(5 * time.Second)
|
||||
}
|
||||
|
||||
func (w *VideoCutWorker) Work(ctx context.Context, job *Job[VideoCut]) error {
|
||||
return nil
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package jobs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
_ "git.ipao.vip/rogeecn/atom"
|
||||
_ "git.ipao.vip/rogeecn/atom/contracts"
|
||||
. "github.com/riverqueue/river"
|
||||
)
|
||||
|
||||
var (
|
||||
_ JobArgs = VideoExtractAudio{}
|
||||
_ JobArgsWithInsertOpts = VideoExtractAudio{}
|
||||
)
|
||||
|
||||
type VideoExtractAudio struct {
|
||||
PostID int64 `json:"post_id"`
|
||||
Hash string `json:"hash"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
// InsertOpts implements JobArgsWithInsertOpts.
|
||||
func (s VideoExtractAudio) InsertOpts() InsertOpts {
|
||||
return InsertOpts{
|
||||
Queue: QueueDefault,
|
||||
Priority: PriorityDefault,
|
||||
UniqueOpts: UniqueOpts{
|
||||
ByArgs: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (VideoExtractAudio) Kind() string {
|
||||
return "VideoExtractAudio"
|
||||
}
|
||||
|
||||
var _ Worker[VideoExtractAudio] = (*VideoExtractAudioWorker)(nil)
|
||||
|
||||
// @provider(job)
|
||||
type VideoExtractAudioWorker struct {
|
||||
WorkerDefaults[VideoExtractAudio]
|
||||
}
|
||||
|
||||
func (w *VideoExtractAudioWorker) NextRetry(job *Job[VideoExtractAudio]) time.Time {
|
||||
return time.Now().Add(5 * time.Minute)
|
||||
}
|
||||
|
||||
func (w *VideoExtractAudioWorker) Work(ctx context.Context, job *Job[VideoExtractAudio]) error {
|
||||
return nil
|
||||
}
|
||||
54
backend/app/jobs/post_video_cut.go
Normal file
54
backend/app/jobs/post_video_cut.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package jobs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
_ "git.ipao.vip/rogeecn/atom"
|
||||
_ "git.ipao.vip/rogeecn/atom/contracts"
|
||||
. "github.com/riverqueue/river"
|
||||
)
|
||||
|
||||
var (
|
||||
_ JobArgs = (*PostVideoCutJob)(nil)
|
||||
_ JobArgsWithInsertOpts = (*PostVideoCutJob)(nil)
|
||||
)
|
||||
|
||||
type PostVideoCutJob struct {
|
||||
PostID int64
|
||||
TenantID int64
|
||||
UserID int64
|
||||
Hash string
|
||||
}
|
||||
|
||||
// InsertOpts implements JobArgsWithInsertOpts.
|
||||
func (s PostVideoCutJob) InsertOpts() InsertOpts {
|
||||
return InsertOpts{
|
||||
Queue: QueueDefault,
|
||||
Priority: PriorityDefault,
|
||||
// UniqueOpts: UniqueOpts{
|
||||
// ByArgs: true,
|
||||
// },
|
||||
}
|
||||
}
|
||||
|
||||
func (PostVideoCutJob) Kind() string {
|
||||
return "PostVideoCutJob"
|
||||
}
|
||||
|
||||
// worker
|
||||
|
||||
var _ Worker[PostVideoCutJob] = (*PostVideoCutJobWorker)(nil)
|
||||
|
||||
// @provider(job)
|
||||
type PostVideoCutJobWorker struct {
|
||||
WorkerDefaults[PostVideoCutJob]
|
||||
}
|
||||
|
||||
func (w *PostVideoCutJobWorker) NextRetry(job *Job[PostVideoCutJob]) time.Time {
|
||||
return time.Now().Add(5 * time.Second)
|
||||
}
|
||||
|
||||
func (w *PostVideoCutJobWorker) Work(ctx context.Context, job *Job[PostVideoCutJob]) error {
|
||||
return nil
|
||||
}
|
||||
52
backend/app/jobs/post_video_extract_audio.go
Normal file
52
backend/app/jobs/post_video_extract_audio.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package jobs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
_ "git.ipao.vip/rogeecn/atom"
|
||||
_ "git.ipao.vip/rogeecn/atom/contracts"
|
||||
. "github.com/riverqueue/river"
|
||||
)
|
||||
|
||||
var (
|
||||
_ JobArgs = (*PostVideoExtractAudioJob)(nil)
|
||||
_ JobArgsWithInsertOpts = (*PostVideoExtractAudioJob)(nil)
|
||||
)
|
||||
|
||||
type PostVideoExtractAudioJob struct {
|
||||
PostID int64
|
||||
TenantID int64
|
||||
UserID int64
|
||||
Hash string
|
||||
}
|
||||
|
||||
// InsertOpts implements JobArgsWithInsertOpts.
|
||||
func (s PostVideoExtractAudioJob) InsertOpts() InsertOpts {
|
||||
return InsertOpts{
|
||||
Queue: QueueDefault,
|
||||
Priority: PriorityDefault,
|
||||
// UniqueOpts: UniqueOpts{
|
||||
// ByArgs: true,
|
||||
// },
|
||||
}
|
||||
}
|
||||
|
||||
func (PostVideoExtractAudioJob) Kind() string {
|
||||
return "PostVideoExtractAudioJob"
|
||||
}
|
||||
|
||||
var _ Worker[PostVideoExtractAudioJob] = (*PostVideoExtractAudioJobWorker)(nil)
|
||||
|
||||
// @provider(job)
|
||||
type PostVideoExtractAudioJobWorker struct {
|
||||
WorkerDefaults[PostVideoExtractAudioJob]
|
||||
}
|
||||
|
||||
func (w *PostVideoExtractAudioJobWorker) NextRetry(job *Job[PostVideoExtractAudioJob]) time.Time {
|
||||
return time.Now().Add(5 * time.Second)
|
||||
}
|
||||
|
||||
func (w *PostVideoExtractAudioJobWorker) Work(ctx context.Context, job *Job[PostVideoExtractAudioJob]) error {
|
||||
return nil
|
||||
}
|
||||
@@ -11,30 +11,6 @@ import (
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
if err := container.Container.Provide(func(
|
||||
__job *job.Job,
|
||||
) (contracts.Initial, error) {
|
||||
obj := &VideoCutWorker{}
|
||||
if err := river.AddWorkerSafely(__job.Workers, obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
__job *job.Job,
|
||||
) (contracts.Initial, error) {
|
||||
obj := &VideoExtractAudioWorker{}
|
||||
if err := river.AddWorkerSafely(__job.Workers, obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func() (contracts.CronJob, error) {
|
||||
obj := &CronJob{}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
@@ -57,5 +33,29 @@ func Provide(opts ...opt.Option) error {
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
__job *job.Job,
|
||||
) (contracts.Initial, error) {
|
||||
obj := &PostVideoCutJobWorker{}
|
||||
if err := river.AddWorkerSafely(__job.Workers, obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
__job *job.Job,
|
||||
) (contracts.Initial, error) {
|
||||
obj := &PostVideoExtractAudioJobWorker{}
|
||||
if err := river.AddWorkerSafely(__job.Workers, obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user