Skip to content

Commit

Permalink
Check if there is any connected scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Jan 25, 2025
1 parent 68fcba2 commit 4a67803
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions handlers/scraper/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net"
"sync/atomic"
"syscall"
"time"

Expand All @@ -16,9 +17,11 @@ type remoteResult struct {
outChan chan error
}

var connStream atomic.Int32
var inChan chan remoteResult

func init() {
connStream.Store(0)
inChan = make(chan remoteResult)

ln, err := net.Listen("tcp", "localhost:4444")
Expand Down Expand Up @@ -53,6 +56,8 @@ func handleConnection(conn net.Conn) {

buf := make([]byte, 64*1024)
go func() {
connStream.Add(1)
defer connStream.Add(-1)
for {
select {
case rm := <-inChan:
Expand Down Expand Up @@ -86,6 +91,10 @@ func handleConnection(conn net.Conn) {
}

func ScrapeRemote(i *InstaData) error {
if connStream.Load() == 0 {
return errors.New("Remote scraper is not running")
}

remoteRes := remoteResult{
instaData: i,
outChan: make(chan error),
Expand Down

0 comments on commit 4a67803

Please sign in to comment.