Skip to content

Commit

Permalink
Merge pull request #44 from grisu48/version
Browse files Browse the repository at this point in the history
Add version command and omit 'skipped' jobs
  • Loading branch information
grisu48 authored May 12, 2021
2 parents 9969579 + 55753d2 commit 1f6468a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
36 changes: 30 additions & 6 deletions cmd/openqa-mon/openqa-mon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/grisu48/gopenqa"
)

const VERSION = "0.5"

// Remote instance
type Remote struct {
URI string
Expand All @@ -29,6 +31,7 @@ func printHelp() {
fmt.Println("OPTIONS")
fmt.Println("")
fmt.Println(" -h, --help Print this help message")
fmt.Println(" --version Display program version")
fmt.Println(" -j, --jobs JOBS Display information only for the given JOBS")
fmt.Println(" JOBS can be a single job id, a comma separated list (e.g. 42,43,1337)")
fmt.Println(" or a job range (1335..1339 or 1335+4)")
Expand Down Expand Up @@ -250,6 +253,9 @@ func main() {
case "--help":
printHelp()
return
case "--version":
fmt.Println("openqa-mon version " + VERSION)
return
case "--jobs":
i++
if i >= len(args) {
Expand Down Expand Up @@ -612,12 +618,25 @@ func FetchJobs(remotes []Remote, callback func(int, gopenqa.Job)) ([]Remote, err
}

// Fires a job notification, if notifications are enabled
func NotifyJobChanged(j gopenqa.Job) {
func NotifyJobsChanged(jobs []gopenqa.Job) {
if config.Bell {
bell()
}
if config.Notify {
notifySend(fmt.Sprintf("[%s] - Job %d %s", j.JobState(), j.ID, j.Name))
notification := ""
if len(jobs) == 1 {
j := jobs[0]
notification = fmt.Sprintf("[%s] - Job %d %s", j.JobState(), j.ID, j.Name)
} else {
for _, j := range jobs {
notification += fmt.Sprintf("[%s] %s\n", j.JobState(), j.Name)
}
}
notification = strings.TrimSpace(notification)

if notification != "" {
notifySend(notification)
}
}
}

Expand Down Expand Up @@ -680,7 +699,8 @@ func continuousMonitoring(remotes []Remote) {

tui.SetStatus("Initial job fetching ... ")
for {
exists := make(map[int]bool, 0) // Keep track of existing jobs
exists := make(map[int]bool, 0) // Keep track of existing jobs
notifyJobs := make([]gopenqa.Job, 0) // jobs which fire a notification
// Fetch new jobs. Update remotes (job id's) when necessary
remotes, err = FetchJobs(remotes, func(id int, job gopenqa.Job) {
exists[job.ID] = true
Expand All @@ -692,13 +712,13 @@ func continuousMonitoring(remotes []Remote) {
if j.JobState() == job.JobState() {
return
}
// Ignore trivial changes (uploading, assigned)
// Ignore trivial changes (uploading, assigned) and skipped jobs
state := job.JobState()
if state == "uploading" || state == "assigned" {
if state == "uploading" || state == "assigned" || state == "skipped" || state == "cancelled" {
return
}
// Notify about job update
NotifyJobChanged(job)
notifyJobs = append(notifyJobs, job)
// Refresh tui after each job update
tui.Model.SetJobs(jobs)
tui.Update()
Expand All @@ -711,6 +731,10 @@ func continuousMonitoring(remotes []Remote) {
tui.Model.SetJobs(jobs)
tui.Update()
})
if len(notifyJobs) > 0 {
NotifyJobsChanged(notifyJobs)
}

// Remove items which are not present anymore - (e.g. old children)
jobs = uniqueJobs(filterJobs(jobs, func(job gopenqa.Job) bool {
_, ok := exists[job.ID]
Expand Down
5 changes: 5 additions & 0 deletions cmd/openqa-mq/openqa-mq.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/streadway/amqp"
)

const VERSION = "1.0"

func printUsage() {
fmt.Printf("Usage: %s [REMOTE] [KEY]\n", os.Args[0])
fmt.Println(" REMOTE - RabbitMQ address (e.g. amqps://opensuse:[email protected])")
Expand Down Expand Up @@ -38,6 +40,9 @@ func main() {
if remote == "-h" || remote == "--help" {
printUsage()
os.Exit(0)
} else if remote == "--version" {
fmt.Println("openqa-mq version " + VERSION)
os.Exit(0)
}

// Provide some nice shortcuts
Expand Down
3 changes: 3 additions & 0 deletions cmd/openqa-revtui/openqa-revtui.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ func parseProgramArgs() error {
if arg == "-h" || arg == "--help" {
printUsage()
os.Exit(0)
} else if arg == "--version" {
fmt.Println("openqa-revtui version " + VERSION)
os.Exit(0)
} else if arg == "-c" || arg == "--config" {
if i++; i >= n {
return fmt.Errorf("Missing argument: %s", "config file")
Expand Down
1 change: 1 addition & 0 deletions cmd/openqa-revtui/pc-review.toml

0 comments on commit 1f6468a

Please sign in to comment.