-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.go
57 lines (44 loc) · 1.63 KB
/
admin.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
55
56
57
package handler
import (
"context"
"time"
"github.com/a-h/templ"
"github.com/dxta-dev/app/internal/data"
"github.com/dxta-dev/app/internal/middleware"
admin_template "github.com/dxta-dev/app/internal/template/admin"
"fmt"
"github.com/labstack/echo/v4"
)
func (a *App) GetCrawlInstancesInfo(c echo.Context) error {
r := c.Request()
tenantDatabaseUrl := r.Context().Value(middleware.TenantDatabaseURLContext).(string)
store := &data.Store{
DbUrl: tenantDatabaseUrl,
}
currentTime := time.Now()
threeMonthsAgo := currentTime.Add(-3 * time.Hour * 24 * 30)
crawlInstances, err := store.GetCrawlInstances(threeMonthsAgo.Unix(), currentTime.Unix())
if err != nil {
return err
}
instanceByRepo := make(map[int64]data.TimeFrameSlice)
for _, instance := range crawlInstances {
instanceByRepo[instance.RepositoryId] = append(instanceByRepo[instance.RepositoryId], instance.TimeFrame)
}
var findGaps data.TimeFrameSlice
var components templ.Component
for repositoryId, timeFrames := range instanceByRepo {
fmt.Printf("RepositoryId %d\n", repositoryId)
findGaps = data.FindGaps(threeMonthsAgo, currentTime, timeFrames)
if len(findGaps) > 0 {
fmt.Printf("Gaps detected for repositoryId %d:\n", repositoryId)
for _, gap := range findGaps {
fmt.Printf("There is a gap between %s and %s\n", gap.Since.Format("2006-01-02 15:04:05"), gap.Until.Format("2006-01-02 15:04:05"))
}
} else {
fmt.Printf("No gaps found for repositoryId %d.\n", repositoryId)
}
components = admin_template.DashboardAdminPage(findGaps, repositoryId, crawlInstances)
}
return components.Render(context.Background(), c.Response().Writer)
}