Compare commits
4 Commits
7e4bc66a7b
...
08112df5df
Author | SHA1 | Date |
---|---|---|
Nathan Chung | 08112df5df | |
Nathan Chung | bbb87eaac9 | |
Nathan Chung | 24541cc075 | |
Nathan Chung | e6ce691738 |
17
README.md
17
README.md
|
@ -2,8 +2,23 @@
|
|||
|
||||
To be written in the future....
|
||||
|
||||
|
||||
## How to test
|
||||
|
||||
|
||||
|
||||
## How to build
|
||||
|
||||
Download dependencies:
|
||||
```
|
||||
go get -u
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
go run . check debian ubuntu < data/example.in # from the project root directory, read the config and run all checks for the specified projects
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
|
@ -14,7 +29,7 @@ After building...
|
|||
|
||||
...
|
||||
|
||||
> From the original mirror checker: Future notes: Because many of the mirror checkers are built very specific to each mirror. A slight change in the way the project manages their mirror-related websites, public repos etc. can drastically influence whether the mirror checker works correctly or not. These problems are also unfortunately very hard to detect, so it's important that CSC actively maintain the mirror checker so that it works as intended in the long term.
|
||||
> **From the original mirror checker**: Future notes: Because many of the mirror checkers are built very specific to each mirror. A slight change in the way the project manages their mirror-related websites, public repos etc. can drastically influence whether the mirror checker works correctly or not. These problems are also unfortunately very hard to detect, so it's important that CSC actively maintain the mirror checker so that it works as intended in the long term.
|
||||
>
|
||||
> Extra notes: A test client for individual mirror checker classes is provided as test.py. To use it, simply change all occurrences of the imported project class
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ type ProjectProperties struct {
|
|||
OOSSince time.Time //`json:"out_of_sync_since"`
|
||||
OOSInterval int64 `json:"out_of_sync_interval"` // in seconds
|
||||
CSC string `json:"csc"`
|
||||
Mirrors []string `json:"mirrors"`
|
||||
Upstream string `json:"upstream"`
|
||||
File string `json:"file"`
|
||||
}
|
||||
|
@ -122,8 +123,6 @@ func (p Project) RunChecks(callback CheckerResultCallback) (*JobGroup, error) {
|
|||
Wg: &sync.WaitGroup{},
|
||||
}
|
||||
|
||||
log.Info().Msgf("Running %d checks for project %s", n, p.Name)
|
||||
|
||||
for i, jd := range jobs {
|
||||
log.Info().Str("project", p.Name).
|
||||
Str("check_name", jd.Checker.Name).
|
||||
|
@ -135,14 +134,27 @@ func (p Project) RunChecks(callback CheckerResultCallback) (*JobGroup, error) {
|
|||
// Wait for all checks to complete
|
||||
log.Debug().
|
||||
Str("project", p.Name).
|
||||
Str("job_group", jg.Name).
|
||||
Msgf("Waiting for %d checks to complete.", n)
|
||||
for i := 0; i < n; i++ {
|
||||
res := <-results
|
||||
log.Debug().Str("project", p.Name).
|
||||
Str("job_group", jg.Name).
|
||||
Str("worker_id", strconv.Itoa(jg.WorkerID)).
|
||||
Str("checker_name", res.CheckerName).
|
||||
Msg("Received checker result.")
|
||||
if res.Status == CHECKER_ERROR {
|
||||
// TODO: log checker UUID
|
||||
log.Error().Err(res.Error).Msg("Checker returned error.")
|
||||
statusResult <- CHECKER_ERROR
|
||||
// TODO: stop exisiting jobs
|
||||
return
|
||||
}
|
||||
if res.Status == CHECKER_FAIL {
|
||||
// TODO: log checker UUID
|
||||
log.Debug().Msg("Checker failed.")
|
||||
statusResult <- CHECKER_FAIL
|
||||
return
|
||||
}
|
||||
}
|
||||
close(results)
|
||||
|
@ -232,7 +244,7 @@ func LoadProject(name string) (*Project, error) {
|
|||
if !exists {
|
||||
return res, errors.New("Requested project not found.")
|
||||
}
|
||||
if res.Properties == DefaultProjectProperties {
|
||||
if res.Properties.CSC == "unknown" {
|
||||
log.Debug().Str("csc", res.Properties.CSC).
|
||||
Msgf("Requested project %s has default properties.", name)
|
||||
return res, errors.New("Requested project has invalid properties. Please check the project config.")
|
||||
|
|
16
go.mod
16
go.mod
|
@ -2,26 +2,30 @@ module github.com/Nathan13888/mirror-checker2/v2
|
|||
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/gofiber/fiber/v2 v2.47.0
|
||||
github.com/rs/zerolog v1.29.1
|
||||
github.com/urfave/cli/v2 v2.25.7
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/gofiber/fiber/v2 v2.46.0 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/klauspost/compress v1.16.5 // indirect
|
||||
github.com/klauspost/compress v1.16.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/philhofer/fwd v1.1.2 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
github.com/rs/zerolog v1.29.1 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
||||
github.com/tinylib/msgp v1.1.8 // indirect
|
||||
github.com/urfave/cli/v2 v2.25.5 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.47.0 // indirect
|
||||
github.com/valyala/fasthttp v1.48.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
golang.org/x/sys v0.9.0 // indirect
|
||||
)
|
||||
|
|
11
go.sum
11
go.sum
|
@ -6,10 +6,14 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
|
|||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gofiber/fiber/v2 v2.46.0 h1:wkkWotblsGVlLjXj2dpgKQAYHtXumsK/HyFugQM68Ns=
|
||||
github.com/gofiber/fiber/v2 v2.46.0/go.mod h1:DNl0/c37WLe0g92U6lx1VMQuxGUQY5V7EIaVoEsUffc=
|
||||
github.com/gofiber/fiber/v2 v2.47.0 h1:EN5lHVCc+Pyqh5OEsk8fzRiifgwpbrP0rulQ4iNf3fs=
|
||||
github.com/gofiber/fiber/v2 v2.47.0/go.mod h1:mbFMVN1lQuzziTkkakgtKKdjfsXSw9BKR5lmcNksUoU=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
|
||||
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk=
|
||||
github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
|
@ -22,6 +26,7 @@ github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
|
|||
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
||||
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
|
||||
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||
|
@ -41,10 +46,14 @@ github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0=
|
|||
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
|
||||
github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc=
|
||||
github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
||||
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
|
||||
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.47.0 h1:y7moDoxYzMooFpT5aHgNgVOQDrS3qlkfiP9mDtGGK9c=
|
||||
github.com/valyala/fasthttp v1.47.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||
github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc=
|
||||
github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
|
@ -82,6 +91,8 @@ golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
||||
|
|
31
main.go
31
main.go
|
@ -70,9 +70,6 @@ func main() {
|
|||
checkers.LoadDefaultProjects()
|
||||
loadConfig()
|
||||
|
||||
// verify all projects are enabled
|
||||
// TODO: ???
|
||||
|
||||
// attempt to look up and check all projects
|
||||
projects := cCtx.Args().Slice()
|
||||
if len(projects) == 0 {
|
||||
|
@ -94,16 +91,16 @@ func main() {
|
|||
}
|
||||
|
||||
res, err := proj.RunChecks(func(res checkers.CheckerResult) {
|
||||
if res.Error != nil {
|
||||
log.Error().Err(res.Error).
|
||||
Time("time", res.Time).
|
||||
Msgf("Failed check %s for project %s", res.CheckerName, res.ProjectName)
|
||||
} else {
|
||||
log.Info().
|
||||
Time("time", res.Time).
|
||||
Str("status", string(res.Status)).
|
||||
Msgf("Completed check %s for project %s", res.CheckerName, res.ProjectName)
|
||||
}
|
||||
// if res.Error != nil {
|
||||
// log.Error().Err(res.Error).
|
||||
// Time("time", res.Time).
|
||||
// Msgf("Failed check %s for project %s", res.CheckerName, res.ProjectName)
|
||||
// } else {
|
||||
// log.Info().
|
||||
// Time("time", res.Time).
|
||||
// Str("status", string(res.Status)).
|
||||
// Msgf("Completed check %s for project %s", res.CheckerName, res.ProjectName)
|
||||
// }
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -115,6 +112,14 @@ func main() {
|
|||
log.Fatal().Err(err).Msg("Failed to check project.")
|
||||
}
|
||||
|
||||
if status == checkers.CHECKER_FAIL {
|
||||
// exit with non-zero status
|
||||
log.Error().Str("final_status", string(status)).
|
||||
Str("project", arg).
|
||||
Msg("Error found when checking project.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
log.Info().Str("final_status", string(status)).
|
||||
Msgf("Completed all checks for project `%s`", arg)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue