Skip to content

Commit

Permalink
Run cleanup asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-asplin-met-no committed Sep 20, 2024
1 parent 4b5fbce commit 1d73adf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 3 additions & 4 deletions datastore/datastore/storagebackend/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"datastore/common"
"datastore/datastore"
"fmt"
"log"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -545,7 +546,7 @@ func cleanup(db *sql.DB) error {
}

// considerCleanup considers if cleanup() should be called.
func considerCleanup(db *sql.DB) error {
func considerCleanup(db *sql.DB) {

// call cleanup() if at least cleanupInterval has passed since the last time it was called

Expand All @@ -555,9 +556,7 @@ func considerCleanup(db *sql.DB) error {

if time.Since(lastCleanupTime) > cleanupInterval {
if err := cleanup(db); err != nil {
return fmt.Errorf("cleanup() failed: %v", err)
log.Printf("cleanup() failed: %v", err)
}
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"datastore/common"
"datastore/datastore"
"fmt"
"log"
"reflect"
"strings"

Expand Down Expand Up @@ -457,9 +456,8 @@ func (sbe *PostgreSQL) PutObservations(request *datastore.PutObsRequest) (codes.
}
}

if err := considerCleanup(sbe.Db); err != nil {
log.Printf("WARNING: considerCleanup() failed: %v", err)
}
// run cleanup asynchronously to allow this function to return immediately
go considerCleanup(sbe.Db)

return codes.OK, ""
}

1 comment on commit 1d73adf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Unit Test Coverage Report
FileStmtsMissCoverMissing
\_\_init\_\_.py00100% 
datastore_pb2.py655220%34–85
datastore_pb2_grpc.py542750%15–16, 19, 65–80, 121–123, 128–130, 135–137, 142–144, 148–173, 219, 246, 273, 300
grpc_getter.py201145%15–19, 23–26, 30–32, 36–38
locustfile.py15150%1–31
main.py41783%42, 47, 57, 67–68, 78–79
metadata_endpoints.py653152%45–54, 58, 85, 100–219, 223
response_classes.py50100% 
utilities.py1745171%20, 38, 45, 67–70, 78–89, 94–101, 121, 125, 127, 155, 161, 179, 193–194, 198, 214–218, 222–228, 232–234, 245–249, 264, 268, 290, 295
custom_geo_json
   edr_feature_collection.py60100% 
formatters
   \_\_init\_\_.py110100% 
   covjson.py59198%91
   geojson.py20290%26, 51
openapi
   custom_dimension_examples.py40100% 
   edr_query_parameter_descriptions.py110100% 
   openapi_examples.py130100% 
routers
   \_\_init\_\_.py00100% 
   edr.py101496%348–349, 438–439
   feature.py471960%99–132, 148–153, 159–181
TOTAL71122069% 

API Unit Test Coverage Summary

Tests Skipped Failures Errors Time
30 0 💤 0 ❌ 0 🔥 2.034s ⏱️

Please sign in to comment.