forked from mtusi2026/mtusi2026lab6
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
|
|
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/config"
|
|
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/database"
|
|
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/postgres"
|
|
)
|
|
|
|
func RunAttachmentReplay(arguments []string, output io.Writer) error {
|
|
if len(arguments) != 3 {
|
|
return errors.New("usage: messenger replay-attachment <attachment-id> <actor> <reason>")
|
|
}
|
|
settings, err := config.LoadJobAdmin()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pool, err := database.Open(context.Background(), database.Config{
|
|
URL: settings.DatabaseURL, MinConnections: settings.DBMinConns, MaxConnections: settings.DBMaxConns,
|
|
MaxConnectionAge: settings.DBMaxConnectionAge, MaxConnectionIdle: settings.DBMaxConnectionIdle,
|
|
HealthCheckPeriod: settings.DBHealthCheckPeriod, ConnectTimeout: settings.DependencyTimeout,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer pool.Close()
|
|
job, err := postgres.New(pool).ReplayFailedAttachment(
|
|
context.Background(), arguments[0], arguments[1], arguments[2],
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = fmt.Fprintf(output, "replayed attachment=%s job=%s attempt=%d\n", job.AttachmentID, job.ID, job.Attempt)
|
|
return err
|
|
}
|