Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
monder committed Jun 28, 2016
1 parent 134d05b commit efe5bc8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
6 changes: 4 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ import:
- service/s3
- package: github.com/gorilla/mux
- package: gopkg.in/yaml.v2
- package: github.com/tj/go-debug
18 changes: 13 additions & 5 deletions wain/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package wain

import (
"fmt"
. "github.com/tj/go-debug"
"regexp"
"strings"
)

var debug = Debug("handler")

type ResizeOptions struct {
Width int
Height int
Expand All @@ -30,21 +33,26 @@ func HandleProcessing(url ConfigUrl, s3 map[string]*S3Connection, r ResizeOption
return imageData, nil
}

fmt.Printf("No cached version found %s\n", cacheKey)
fmt.Printf("Downloading %s\n", originalKey)
debug("No cached version found %s\n", cacheKey)
debug("Downloading %s\n", originalKey)

imageData, err = s3[url.Original.Bucket].GetObject(originalKey)
if err != nil {
return nil, err
}

fmt.Printf("Resizing...\n")
debug("Resizing...\n")

imageData, err = VipsResize(imageData, r)

if err == nil {
fmt.Printf("Save cached version\n")
go s3[url.Cache.Bucket].PutObject(cacheKey, imageData, "image/jpeg")
debug("Save cached version\n")
go func() {
e := s3[url.Cache.Bucket].PutObject(cacheKey, imageData, "image/jpeg")
if e != nil {
fmt.Println(e)
}
}()
}

return imageData, err
Expand Down
1 change: 1 addition & 0 deletions wain/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (s *Server) handleProcessing(url ConfigUrl) func(http.ResponseWriter, *http
if err != nil {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(400)
fmt.Printf("Unable to process image %s\n", r.URL)
fmt.Println(err)
} else {
//TODO w.Header().Set("Content-Type", "")
Expand Down
3 changes: 1 addition & 2 deletions wain/vips.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
int vips_wain_init() {
if (vips_init("wain-vips")) vips_error_exit("unable to start VIPS");
vips_concurrency_set(1);
vips_cache_set_max_mem(100 * 1048576); // 100Mb
vips_cache_set_max(500);

return 0;
}
Expand Down Expand Up @@ -38,6 +36,7 @@ static double calculate_shrink(VipsImage *im, gboolean crop, int width, int heig
int vips_wain_resize(void *src, size_t src_len, void **dst, size_t *dst_len, int width, int height) {

VipsImage *image = vips_image_new_from_buffer(src, src_len, NULL, NULL);
if (!image) return 1;
VipsImage *tmp = NULL;

if (height == 0) {
Expand Down

0 comments on commit efe5bc8

Please sign in to comment.