1
0
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:
DarthSim
2023-08-21 20:48:47 +03:00
parent f0b9c05e98
commit 925dac28bb
5 changed files with 68 additions and 3 deletions

View File

@@ -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()
}