Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converter: Update workers #125

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions converter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/sunshineplan/imgconv v0.0.0-00010101000000-000000000000
github.com/sunshineplan/tiff v0.0.0-20220128141034-29b9d69bd906
github.com/sunshineplan/utils v0.1.71
github.com/sunshineplan/workers v1.0.1
)

require (
Expand All @@ -17,6 +18,7 @@ require (
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sunshineplan/pdf v1.0.7 // indirect
golang.org/x/image v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Expand Down
4 changes: 4 additions & 0 deletions converter/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ github.com/sunshineplan/tiff v0.0.0-20220128141034-29b9d69bd906 h1:+yYRCj+PGQNnn
github.com/sunshineplan/tiff v0.0.0-20220128141034-29b9d69bd906/go.mod h1:O+Ar7ouRbdfxLgoZLFz447/dvdM1NVKk1VpOQaijvAU=
github.com/sunshineplan/utils v0.1.71 h1:FTe6qAdevePih+hLil1KvKhMAU2Bp+qHTtlO0wxoAYI=
github.com/sunshineplan/utils v0.1.71/go.mod h1:QMe2vCEFq9VliPac8WfXndi5jP0ZrPHus8wvJlgBy5M=
github.com/sunshineplan/workers v1.0.1 h1:vhDo4ZaerVu0QM1udRmWpvHY2U61/vTLRVwmKcYOxNw=
github.com/sunshineplan/workers v1.0.1/go.mod h1:EjLgk5vd/2ig6vdWDAZy/fpkzdSm8IVDsARPQVSyQy0=
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
13 changes: 7 additions & 6 deletions converter/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"errors"
"flag"
"fmt"
Expand All @@ -16,7 +17,7 @@ import (
"github.com/sunshineplan/utils/flags"
"github.com/sunshineplan/utils/log"
"github.com/sunshineplan/utils/progressbar"
"github.com/sunshineplan/utils/workers"
"github.com/sunshineplan/workers"
)

var (
Expand All @@ -37,7 +38,7 @@ var (
width = flag.Int("width", 0, "")
height = flag.Int("height", 0, "")
percent = flag.Float64("percent", 0, "")
worker = flag.Int("worker", 5, "")
worker = flag.Int64("worker", 5, "")
debug = flag.Bool("debug", false, "")

format imgconv.Format
Expand Down Expand Up @@ -133,12 +134,12 @@ func main() {
log.Println("Total images:", total)
pb := progressbar.New(total)
pb.Start()
workers.RunSlice(*worker, images, func(_ int, image string) {
workers.NewWorkers(*worker).Run(context.Background(), workers.SliceJob(images, func(_ int, image string) {
defer pb.Add(1)
if _, err := open(image); err != nil {
log.Error("Bad image", "image", image, "error", err)
}
})
}))
pb.Done()
case srcInfo.Mode().IsRegular():
if _, err := open(*src); err != nil {
Expand Down Expand Up @@ -210,7 +211,7 @@ func main() {
log.Println("Total images:", total)
pb := progressbar.New(total)
pb.Start()
workers.RunSlice(*worker, images, func(_ int, image string) {
workers.NewWorkers(*worker).Run(context.Background(), workers.SliceJob(images, func(_ int, image string) {
defer pb.Add(1)
rel, err := filepath.Rel(*src, image)
if err != nil {
Expand All @@ -225,7 +226,7 @@ func main() {
return
}
log.Debug("Converted " + image)
})
}))
pb.Done()
case srcInfo.Mode().IsRegular():
output := *dst
Expand Down