Доработайте публикацию и сверку вложений по итогам ревью
This commit is contained in:
+32
-23
@@ -1,4 +1,4 @@
|
||||
// Command server starts the messenger API over PostgreSQL and Valkey.
|
||||
// Command server starts the messenger API over PostgreSQL, Valkey and S3.
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -61,25 +61,9 @@ func run(ctx context.Context, log *slog.Logger, cfg config.Config, alias string)
|
||||
return err
|
||||
}
|
||||
defer sessions.Close()
|
||||
var blobs attachment.Blobs
|
||||
var reconciler *attachment.Reconciler
|
||||
if cfg.S3.Endpoint != "" {
|
||||
blobs, err = s3store.New(cfg.S3.Endpoint, cfg.S3.Region, cfg.S3.Bucket, cfg.S3.AccessKey, cfg.S3.SecretKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reconCfg, e := config.LoadS3(config.ReconcileS3(os.LookupEnv))
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
reconBlobs, e := s3store.New(reconCfg.Endpoint, reconCfg.Region, reconCfg.Bucket, reconCfg.AccessKey, reconCfg.SecretKey)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
reconciler, err = attachment.NewReconciler(pool, reconBlobs, time.Hour)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
blobs, reconciler, err := newAttachmentStorage(pool, cfg.S3, os.LookupEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp", cfg.Addr())
|
||||
@@ -100,8 +84,10 @@ func run(ctx context.Context, log *slog.Logger, cfg config.Config, alias string)
|
||||
InstanceID: alias,
|
||||
IdempotencyTTL: cfg.IdempotencyTTL,
|
||||
Blobs: blobs,
|
||||
MaxUploadBytes: cfg.S3.MaxBytes,
|
||||
MaxImagePixels: cfg.S3.MaxPixels,
|
||||
AttachmentsCfg: attachment.Config{
|
||||
MaxBytes: cfg.S3.MaxBytes,
|
||||
MaxPixels: cfg.S3.MaxPixels,
|
||||
},
|
||||
})
|
||||
var debugLn net.Listener
|
||||
if cfg.DebugAddr != "" {
|
||||
@@ -124,7 +110,7 @@ func run(ctx context.Context, log *slog.Logger, cfg config.Config, alias string)
|
||||
return
|
||||
case <-ticker.C:
|
||||
scan, cancel := context.WithTimeout(ctx, 2*time.Minute)
|
||||
stats, err := reconciler.Run(scan, true, false, nil)
|
||||
stats, err := reconciler.Run(scan, attachment.ReconcileOptions{Apply: true}, nil)
|
||||
cancel()
|
||||
if err != nil {
|
||||
log.Warn("attachment cleanup incomplete", "error", err)
|
||||
@@ -149,6 +135,29 @@ func run(ctx context.Context, log *slog.Logger, cfg config.Config, alias string)
|
||||
return err
|
||||
}
|
||||
|
||||
func newAttachmentStorage(pool *pgxpool.Pool, cfg config.S3, lookup config.Lookup) (attachment.Blobs, *attachment.Reconciler, error) {
|
||||
if cfg.Endpoint == "" {
|
||||
return nil, nil, nil
|
||||
}
|
||||
blobs, err := s3store.New(cfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
reconCfg, err := config.LoadS3(config.ReconcileS3(lookup))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
reconBlobs, err := s3store.New(reconCfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
reconciler, err := attachment.NewReconciler(pool, reconBlobs, time.Hour)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return blobs, reconciler, nil
|
||||
}
|
||||
|
||||
// publishDebugVars adds to expvar what the load tests read from a replica.
|
||||
func publishDebugVars(alias string, pool *pgxpool.Pool) {
|
||||
expvar.NewString("instance").Set(alias)
|
||||
|
||||
Reference in New Issue
Block a user