• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / reporting / 732508278

pending completion
732508278

Pull #87

gitlab-ci

Fabio Tranchitella
refac: rename internal search end-point to `/tenants/{tenant_id}/devices/search`
Pull Request #87: MEN-5930: index device deployment objects

331 of 402 new or added lines in 12 files covered. (82.34%)

135 existing lines in 5 files now uncovered.

2196 of 2600 relevant lines covered (84.46%)

17.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.46
/app/indexer/run.go
1
// Copyright 2022 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package indexer
16

17
import (
18
        "context"
19
        "os"
20
        "os/signal"
21
        "time"
22

23
        "golang.org/x/sys/unix"
24

25
        "github.com/mendersoftware/go-lib-micro/config"
26

27
        "github.com/mendersoftware/reporting/client/deployments"
28
        "github.com/mendersoftware/reporting/client/deviceauth"
29
        "github.com/mendersoftware/reporting/client/inventory"
30
        "github.com/mendersoftware/reporting/client/nats"
31
        rconfig "github.com/mendersoftware/reporting/config"
32
        "github.com/mendersoftware/reporting/model"
33
        "github.com/mendersoftware/reporting/store"
34
)
35

36
const jobsChanSize = 1000
37

38
// InitAndRun initializes the indexer and runs it
39
func InitAndRun(conf config.Reader, store store.Store, ds store.DataStore, nats nats.Client) error {
1✔
40
        ctx, cancel := context.WithCancel(context.Background())
1✔
41
        defer cancel()
1✔
42

1✔
43
        invClient := inventory.NewClient(
1✔
44
                conf.GetString(rconfig.SettingInventoryAddr),
1✔
45
        )
1✔
46

1✔
47
        devClient := deviceauth.NewClient(
1✔
48
                conf.GetString(rconfig.SettingDeviceAuthAddr),
1✔
49
        )
1✔
50

1✔
51
        deplClient := deployments.NewClient(
1✔
52
                conf.GetString(rconfig.SettingDeploymentsAddr),
1✔
53
        )
1✔
54

1✔
55
        indexer := NewIndexer(store, ds, nats, devClient, invClient, deplClient)
1✔
56
        jobs := make(chan *model.Job, jobsChanSize)
1✔
57

1✔
58
        err := indexer.GetJobs(ctx, jobs)
1✔
59
        if err != nil {
1✔
UNCOV
60
                return err
×
UNCOV
61
        }
×
62

63
        quit := make(chan os.Signal, 1)
1✔
64
        signal.Notify(quit, unix.SIGINT, unix.SIGTERM)
1✔
65

1✔
66
        batchSize := conf.GetInt(rconfig.SettingReindexBatchSize)
1✔
67
        jobsList := make([]*model.Job, batchSize)
1✔
68
        jobsListSize := 0
1✔
69

1✔
70
        maxTimeMs := conf.GetInt(rconfig.SettingReindexMaxTimeMsec)
1✔
71
        tickerTimeout := time.Duration(maxTimeMs) * time.Millisecond
1✔
72
        ticker := time.NewTimer(tickerTimeout)
1✔
73

1✔
74
        for {
35✔
75
                select {
34✔
76
                case <-ticker.C:
18✔
77
                        if jobsListSize > 0 {
21✔
78
                                indexer.ProcessJobs(ctx, jobsList[0:jobsListSize])
3✔
79
                                jobsListSize = 0
3✔
80
                        }
3✔
81
                        ticker.Reset(tickerTimeout)
18✔
82

83
                case job := <-jobs:
15✔
84
                        jobsList[jobsListSize] = job
15✔
85
                        jobsListSize++
15✔
86
                        if jobsListSize == batchSize {
15✔
UNCOV
87
                                indexer.ProcessJobs(ctx, jobsList[0:jobsListSize])
×
UNCOV
88
                                ticker.Reset(tickerTimeout)
×
UNCOV
89
                                jobsListSize = 0
×
UNCOV
90
                        }
×
91

92
                case <-quit:
1✔
93
                        return nil
1✔
94
                }
95
        }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc