2025-03-06 19:26:01 +00:00
|
|
|
// **Listens For**: S3 Event notifications - limited to PUT notifications.
|
|
|
|
|
//
|
|
|
|
|
// **Action**.
|
|
|
|
|
//
|
|
|
|
|
// Checks if the uploaded document is a duplicate.
|
|
|
|
|
//
|
2025-03-10 11:03:00 +00:00
|
|
|
// Currently whether the document content is a duplicate or not is determines using the document ETag, and check if it already exists for the client.
|
2025-03-06 19:26:01 +00:00
|
|
|
//
|
|
|
|
|
// Find reference entity.
|
|
|
|
|
//
|
|
|
|
|
// If NOT a duplicate - Create a document reference entity.
|
|
|
|
|
//
|
|
|
|
|
// Create a document entry to log the successful upload of a document.
|
|
|
|
|
//
|
|
|
|
|
// Add an event to the DOC SYNC queue.
|
2025-02-03 17:30:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"log/slog"
|
|
|
|
|
"os"
|
2025-03-05 12:05:46 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
docinitrunner "queryorchestration/api/docInitRunner"
|
|
|
|
|
documentinit "queryorchestration/internal/document/init"
|
|
|
|
|
"queryorchestration/internal/server/runner"
|
2025-02-12 19:00:25 +00:00
|
|
|
documentsyncc "queryorchestration/internal/serviceconfig/queue/documentsync"
|
2025-02-03 17:30:50 +00:00
|
|
|
|
|
|
|
|
_ "github.com/lib/pq"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DocInitConfig struct {
|
2025-04-02 18:50:03 +00:00
|
|
|
runner.BaseConfig[docinitrunner.Body]
|
2025-02-12 19:00:25 +00:00
|
|
|
documentsyncc.DocSyncConfig
|
2025-02-03 17:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
cfg := &DocInitConfig{}
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
cfg.ControllerFunc = func() runner.Controller[docinitrunner.Body] {
|
2025-02-12 19:00:25 +00:00
|
|
|
docinit := documentinit.New(cfg)
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-04-22 14:40:16 +00:00
|
|
|
return docinitrunner.New(&docinitrunner.Services{
|
2025-02-07 12:12:51 +00:00
|
|
|
Document: docinit,
|
2025-02-03 17:30:50 +00:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server, err := runner.New(ctx, cfg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error(err.Error())
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-05 16:59:01 +00:00
|
|
|
// optional add shutdown metrics
|
|
|
|
|
defer func() {
|
|
|
|
|
err = cfg.GetMetrics().RecordLifecycleEvent(1.0, "shutdown", "main")
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("Failed to record shutdown metric ", "error", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// start and block until server is done
|
2025-02-03 17:30:50 +00:00
|
|
|
server.Listen(ctx)
|
2025-03-05 16:59:01 +00:00
|
|
|
|
|
|
|
|
// optional shutdown
|
|
|
|
|
metrics := cfg.GetMetrics()
|
|
|
|
|
if err := metrics.Shutdown(ctx); err != nil {
|
|
|
|
|
slog.Error("Error shutting down metrics server", "error", err)
|
|
|
|
|
}
|
2025-02-03 17:30:50 +00:00
|
|
|
}
|