feat(pkg/db): postgres database
This commit is contained in:
		| @@ -8,6 +8,7 @@ import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/go-flucky/flucky/pkg/config" | ||||
| 	"github.com/go-flucky/flucky/pkg/db" | ||||
| 	"github.com/go-flucky/flucky/pkg/logfile" | ||||
| 	"github.com/go-flucky/flucky/pkg/logger" | ||||
| 	"github.com/go-flucky/flucky/pkg/rgbled" | ||||
| @@ -15,6 +16,14 @@ import ( | ||||
| 	"github.com/go-flucky/flucky/pkg/types" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	postgresHost     = "markus-pc.trier.cryptic.systems" | ||||
| 	postgresPort     = "5432" | ||||
| 	postgresDatabase = "postgres" | ||||
| 	postgresUser     = "postgres" | ||||
| 	postgresPassword = "postgres" | ||||
| ) | ||||
|  | ||||
| // Start the daemon | ||||
| func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compression bool, round float64, logger logger.Logger) { | ||||
|  | ||||
| @@ -67,7 +76,9 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress | ||||
| 				logger.Error("Can not turn on blue info light: %v", err) | ||||
| 			} | ||||
|  | ||||
| 			err = logfile.Append(measuredValuesLogfile, compression, round, measuredValuesCache) | ||||
| 			// err = logfile.Append(measuredValuesLogfile, compression, round, measuredValuesCache) | ||||
|  | ||||
| 			postgres, err := db.New(db.DBOTypePostgres, postgresHost, postgresPort, postgresDatabase, postgresUser, postgresPassword) | ||||
| 			if err != nil { | ||||
|  | ||||
| 				err = rgbled.Error(rgbLEDs) | ||||
| @@ -76,8 +87,22 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress | ||||
| 				} | ||||
|  | ||||
| 				cancel() | ||||
| 				logger.Fatal("Can not save temperatures: %v", err) | ||||
| 				logger.Error("Can not open database connection: %v", err) | ||||
| 			} | ||||
|  | ||||
| 			postgresCtx := context.Background() | ||||
| 			err = postgres.InsertMeasuredValues(postgresCtx, measuredValuesCache) | ||||
| 			if err != nil { | ||||
|  | ||||
| 				err = rgbled.Error(rgbLEDs) | ||||
| 				if err != nil { | ||||
| 					logger.Error("Can not turn on red info light: %v", err) | ||||
| 				} | ||||
|  | ||||
| 				cancel() | ||||
| 				logger.Error("Can not save caches measured values in database: %v", err) | ||||
| 			} | ||||
|  | ||||
| 			measuredValuesCache = make([]*types.MeasuredValue, 0) | ||||
|  | ||||
| 		case measuredValues, _ := <-measuredValuesChannel: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user