Skip to content

Commit

Permalink
Merge pull request #35 from teknologi-umum/feat/insert-aggregate-on-w…
Browse files Browse the repository at this point in the history
…orker

feat(backend): insert aggregate values on aggregate worker
  • Loading branch information
aldy505 authored May 26, 2024
2 parents c1716d3 + 0776221 commit 2fab892
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions backend/aggregate_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ func (w *AggregateWorker) RunHourlyAggregate() {
totalStatus += int64(data.Status)
}

var _ = totalLatency / int64(len(lastHourData)) // averageLatency
var _ = MonitorStatus(totalStatus / int64(len(lastHourData))) // averageStatus

// TODO: Write the hourly aggregate data
// Need https://github.com/teknologi-umum/semyi/pull/32 to be merged first
var averageLatency = totalLatency / int64(len(lastHourData))
var averageStatus = MonitorStatus(totalStatus / int64(len(lastHourData)))

err = w.writer.WriteHourly(context.TODO(), MonitorHistorical{
MonitorID: monitorId,
Status: averageStatus,
Latency: averageLatency,
Timestamp: fromTime,
})
if err != nil {
log.Error().Err(err).Msg("failed to write hourly aggregate data")
continue
}
}

// Calculate the time that we allowed to sleep. We should wake up 10 minutes after the `startTime`
Expand Down Expand Up @@ -95,11 +103,19 @@ func (w *AggregateWorker) RunDailyAggregate() {
totalStatus += int64(data.Status)
}

var _ = totalLatency / int64(len(lastHourData)) // averageLatency
var _ = MonitorStatus(totalStatus / int64(len(lastHourData))) // averageStatus
var averageLatency = totalLatency / int64(len(lastHourData))
var averageStatus = MonitorStatus(totalStatus / int64(len(lastHourData)))

// TODO: Write the daily aggregate data
// Need https://github.com/teknologi-umum/semyi/pull/32 to be merged first
err = w.writer.WriteDaily(context.TODO(), MonitorHistorical{
MonitorID: monitorId,
Status: averageStatus,
Latency: averageLatency,
Timestamp: fromTime,
})
if err != nil {
log.Error().Err(err).Msg("failed to write daily aggregate data")
continue
}
}

// Calculate the time that we allowed to sleep. We should wake up 1 hour after the `startTime`
Expand Down

0 comments on commit 2fab892

Please sign in to comment.