Skip to content

Commit

Permalink
Fixing working directory switching on start (when getting temp dir di…
Browse files Browse the repository at this point in the history
…sk space). Included example output in comment from lambda, so no longer prints all of Statfs output
  • Loading branch information
Peter Nemere committed Dec 9, 2024
1 parent e1a08bc commit b1fbccc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
15 changes: 13 additions & 2 deletions core/utils/diskfree_nonwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package utils

import (
"fmt"
"os"

"golang.org/x/sys/unix"
Expand All @@ -21,6 +20,18 @@ func GetDiskAvailableBytes() (uint64, error) {
return 0, err
}

/* An example of output on Lambda:
Bavail: 393433
Bfree: 397529
Blocks: 397532
Bsize: 4096
Ffree: 434325
Files: 434336
Flags: 4128
Fsid: [-1480289054 1771191333]
Type: 61267
Disk free space: 1611501568
fmt.Printf("Bavail: %v\n", stat.Bavail)
fmt.Printf("Bfree: %v\n", stat.Bfree)
fmt.Printf("Blocks: %v\n", stat.Blocks)
Expand All @@ -37,7 +48,7 @@ func GetDiskAvailableBytes() (uint64, error) {
//fmt.Printf("Mntonname: %v\n", stat.Mntonname)
//fmt.Printf("Owner: %v\n", stat.Owner)
fmt.Printf("Type: %v\n", stat.Type)

*/
// Available blocks * size per block = available space in bytes
return stat.Bavail * uint64(stat.Bsize), nil
}
28 changes: 20 additions & 8 deletions internal/lambdas/data-import/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,28 @@ func HandleRequest(ctx context.Context, event awsutil.Event) (string, error) {
// and it'll be useful for initial debugging
fmt.Printf("ImportForTrigger: \"%v\"\n", record.SNS.Message)

err = os.Chdir(os.TempDir())
wd, err := os.Getwd()
if err != nil {
fmt.Printf("Failed to change to temp dir: %v\n", err)
}

freeBytes, err := utils.GetDiskAvailableBytes()
if err != nil {
fmt.Printf("Failed to read disk free space: %v\n", err)
fmt.Printf("Failed to get working dir: %v\n", err)
} else {
fmt.Printf("Disk free space: %v\n", freeBytes)
fmt.Printf("Working dir: %v\n", wd)

err = os.Chdir(os.TempDir())
if err != nil {
fmt.Printf("Failed to change to temp dir: %v\n", err)
}

freeBytes, err := utils.GetDiskAvailableBytes()
if err != nil {
fmt.Printf("Failed to read disk free space: %v\n", err)
} else {
fmt.Printf("Disk free space: %v\n", freeBytes)
}

err = os.Chdir(wd)
if err != nil {
fmt.Printf("Failed to change to working dir: %v\n", err)
}
}

mongoClient, _, err := mongoDBConnection.Connect(sess, mongoSecret, iLog)
Expand Down

0 comments on commit b1fbccc

Please sign in to comment.