You've already forked imgproxy
mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-11-27 22:48:53 +02:00
Create and destroy a tiny image during health check to check that vips is operational
This commit is contained in:
31
vips/vips.go
31
vips/vips.go
@@ -7,12 +7,14 @@ package vips
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -147,6 +149,35 @@ func GetAllocs() float64 {
|
||||
return float64(C.vips_tracked_get_allocs())
|
||||
}
|
||||
|
||||
func Health() error {
|
||||
timer := time.NewTimer(5 * time.Second)
|
||||
defer timer.Stop()
|
||||
|
||||
done := make(chan struct{})
|
||||
|
||||
var err error
|
||||
|
||||
go func(done chan struct{}) {
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
defer Cleanup()
|
||||
|
||||
if C.vips_health() != 0 {
|
||||
err = Error()
|
||||
}
|
||||
|
||||
close(done)
|
||||
}(done)
|
||||
|
||||
select {
|
||||
case <-done:
|
||||
return err
|
||||
case <-timer.C:
|
||||
return context.DeadlineExceeded
|
||||
}
|
||||
}
|
||||
|
||||
func Cleanup() {
|
||||
C.vips_cleanup()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user