mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
40 lines
736 B
Go
40 lines
736 B
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/hibiken/asynq"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// SyncJob manages the sync process.
|
|
type SyncJob struct {
|
|
DB *gorm.DB
|
|
AsynqClient *asynq.Client
|
|
}
|
|
|
|
// NewSyncJob initializes a new SyncJob.
|
|
func NewSyncJob(db *gorm.DB, aClient *asynq.Client) *SyncJob {
|
|
return &SyncJob{
|
|
DB: db,
|
|
AsynqClient: aClient,
|
|
}
|
|
}
|
|
|
|
// RunFullSync performs a full sync of all entities and edges.
|
|
func (s *SyncJob) RunFullSync(ctx context.Context) error {
|
|
log.Println("Starting full database sync...")
|
|
|
|
if err := s.SyncAllEntities(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := s.SyncAllEdges(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Println("Database sync completed successfully.")
|
|
return nil
|
|
}
|