/
retryrecords.go
54 lines (42 loc) · 1.57 KB
/
retryrecords.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package darwin
import (
"context"
"time"
"github.com/rs/zerolog/log"
"github.com/travigo/travigo/pkg/ctdf"
"github.com/travigo/travigo/pkg/database"
"github.com/travigo/travigo/pkg/realtime/nationalrail/railutils"
"go.mongodb.org/mongo-driver/bson"
)
func RetryRecords(queue *railutils.BatchProcessingQueue) {
retryRecordsCollection := database.GetCollection("retry_records")
realtimeJourneysCollection := database.GetCollection("realtime_journeys")
for true {
matchingFormations := []ScheduleFormations{}
var retryRecords []struct {
Type string
Record ScheduleFormations
}
cursor, _ := retryRecordsCollection.Find(context.Background(), bson.M{"type": "realtimedarwin_formation"})
cursor.All(context.Background(), &retryRecords)
for _, retryRecord := range retryRecords {
searchQuery := bson.M{"otheridentifiers.nationalrailrid": retryRecord.Record.RID}
var realtimeJourney *ctdf.RealtimeJourney
realtimeJourneysCollection.FindOne(context.Background(), searchQuery).Decode(&realtimeJourney)
if realtimeJourney != nil {
log.Info().
Str("nationalrailrid", retryRecord.Record.RID).
Str("realtimejourney", realtimeJourney.PrimaryIdentifier).
Msg("Found matching record for retry schedule formation")
matchingFormations = append(matchingFormations, retryRecord.Record)
retryRecordsCollection.DeleteOne(context.Background(), searchQuery)
}
}
pushPort := PushPortData{
ScheduleFormations: matchingFormations,
}
pushPort.UpdateRealtimeJourneys(queue)
// Run this loop every 90 seconds
time.Sleep(90 * time.Second)
}
}