Skip to content

Commit

Permalink
Merge pull request #29 from egfanboy/fix-download
Browse files Browse the repository at this point in the history
Fix download
  • Loading branch information
egfanboy committed Dec 28, 2023
2 parents 4af0e32 + 4e1fb5a commit 9786221
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
echo "Deleting dist directory"
rm -rf $PWD/dist
echo "Building service"
go build -o $PWD/dist/mediapire-media-host cmd/main.go
3 changes: 3 additions & 0 deletions bin/env.example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
MEDIA_HOST_CONFIG_PATH=
MEDIA_HOST_LOG_PATH=
9 changes: 9 additions & 0 deletions bin/read-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
source ./bin/env.sh
if [ -z "$MEDIA_HOST_LOG_PATH" ];
then
echo "MEDIA_HOST_LOG_PATH not defined, please add it to the bin/env.sh file and retry again."
exit 1
fi

tail -f -n 1000 $MEDIA_HOST_LOG_PATH/logs.txt
20 changes: 20 additions & 0 deletions bin/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
source $PWD/bin/env.sh

if [ -z "$MEDIA_HOST_CONFIG_PATH" ];
then
echo "MEDIA_HOST_CONFIG_PATH not defined, please add it to the bin/env.sh file and retry again."
exit 1
fi

if [ -z "$MEDIA_HOST_LOG_PATH" ];
then
echo "MEDIA_HOST_LOG_PATH not defined, please add it to the bin/env.sh file and retry again."
exit 1
fi

$PWD/bin/build.sh
echo "Starting service"
nohup $PWD/dist/mediapire-media-host --config $MEDIA_HOST_CONFIG_PATH &> $MEDIA_HOST_LOG_PATH/logs.txt &
echo "Service started with PID $!"
echo $! > $PWD/bin/.pid
8 changes: 8 additions & 0 deletions bin/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
PID_FILE=$PWD/bin/.pid
PID=$(cat $PID_FILE)

if kill $PID; then
echo "Mediapire media host successfully stopped"
rm $PID_FILE
fi
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.16

require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/bep/debounce v1.2.1
github.com/dhowden/tag v0.0.0-20220618230019-adf36e896086
github.com/egfanboy/mediapire-common v0.0.0-20231219000342-fbb6228cf11c
github.com/fsnotify/fsnotify v1.5.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
Expand Down
9 changes: 8 additions & 1 deletion internal/fs/fs-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package fs
import (
"os"
"path/filepath"
"time"

"github.com/bep/debounce"
"github.com/egfanboy/mediapire-media-host/internal/media"

"github.com/fsnotify/fsnotify"
Expand Down Expand Up @@ -35,14 +37,19 @@ func (s *fsService) WatchDirectory(directory string) error {
}

go func() {
debouncer := debounce.New(time.Millisecond * 500)

for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}

err := s.handleWatcherEvent(event, directory, watcher)
var err error
debouncer(func() {
err = s.handleWatcherEvent(event, directory, watcher)
})
if err != nil {
log.Error().Err(err).Msgf("Failed to handle change for directory: %s", directory)
}
Expand Down

0 comments on commit 9786221

Please sign in to comment.