Skip to content

Commit

Permalink
feat: add cron jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Mar 31, 2024
1 parent 28956eb commit 63e34dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 5 additions & 1 deletion backend/pkd/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,18 @@ func Start() {
}
*/

//gasstation.CalcCountyTimeSlots()

scheduler := gocron.NewScheduler(time.UTC)
scheduler.Every(1).Day().At("01:07").Do(func() {
gsclient.UpdateGasStations(nil)
})

scheduler.Every(60).Seconds().Tag("messaging").Do(messaging.ConnectionCheck)

scheduler.Every(1).Day().At("00:02").Tag("averages").Do(gasstation.ReCalcCountyStatePrices)
scheduler.Every(1).Day().At("01:32").Tag("timeslices").Do(gasstation.CalcCountyTimeSlots)

scheduler.Every(1).Day().At("03:05").Tag("averages").Do(gasstation.ReCalcCountyStatePrices)

msgFileStr := os.Getenv("MSG_MESSAGES")
if len(strings.TrimSpace(msgFileStr)) > 3 {
Expand Down
5 changes: 2 additions & 3 deletions backend/pkd/gasstation/gsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ func ReCalcCountyStatePrices() {
})
myDuration := time.Now().Sub(myStart)
log.Printf("recalcCountyStatePrices finished for %v states and %v counties in %v.", len(idStateDataMap), len(idCountyDataMap), myDuration)
go calcCountyTimeSlots()
}

func createCodeTimeSliceBuckets(postCodePostCodeLocationMap map[int]pcmodel.PostCodeLocation, postCodeGasStationsMap map[string][]gsmodel.GasStation) map[string]map[time.Time][]gsmodel.GasPrice {
Expand Down Expand Up @@ -274,7 +273,7 @@ func createTimeSliceBuckets(myCountyData pcmodel.CountyData, postCodePostCodeLoc
myPostCodeLocations = append(myPostCodeLocations, myPostCodeLocation)
}
}
log.Printf("myPostCodeLocations: %v\n", len(myPostCodeLocations))
log.Printf("myPostCodeLocations: %v postcode: %v\n", len(myPostCodeLocations), myCountyData.County)
for _, myPcLocation := range myPostCodeLocations {
//log.Printf("postCodeLocations: %v\n", len(myPcLocation.CountyData.PostCodeLocations))
myPostCode := postcode.FormatPostCode(myPcLocation.PostCode)
Expand Down Expand Up @@ -338,7 +337,7 @@ func divZeroCheck(number int64, divisor int64) float64 {
return float64(number / divisor)
}

func calcCountyTimeSlots() {
func CalcCountyTimeSlots() {
log.Printf("calcCountyTimeSlots started.")
myStart := time.Now()
postCodePostCodeLocationMap, _, idCountyDataMap, postCodeGasStationsMap := createPostCodeGasStationMaps()
Expand Down

0 comments on commit 63e34dd

Please sign in to comment.