-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from bhagatvansh/main
Fixes #57 , channels and go routine added to bark client @bhagatvansh good work on this one.
- Loading branch information
Showing
11 changed files
with
128 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package channels | ||
|
||
import "github.com/techrail/bark/models" | ||
|
||
const ClientChannelCapacity = 10000 | ||
|
||
var ClientChannel chan models.BarkLog | ||
|
||
func init() { | ||
ClientChannel = make(chan models.BarkLog, ClientChannelCapacity) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/techrail/bark/client/services/ingestion" | ||
"github.com/techrail/bark/models" | ||
) | ||
|
||
func SendSingleToClientChannel(l models.BarkLog) { | ||
|
||
go ingestion.InsertSingleRequest(l) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package client | ||
package network | ||
|
||
import ( | ||
"encoding/json" | ||
`fmt` | ||
"fmt" | ||
|
||
"github.com/valyala/fasthttp" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package clientLogSender | ||
|
||
import ( | ||
"fmt" | ||
"github.com/techrail/bark/client/channels" | ||
"github.com/techrail/bark/client/network" | ||
"github.com/techrail/bark/constants" | ||
"github.com/techrail/bark/models" | ||
"time" | ||
) | ||
|
||
const logBatchSizeStandard = 100 | ||
|
||
func StartSendingLogs(serverUrl string) { | ||
clientChannelLength := 0 | ||
for { | ||
clientChannelLength = len(channels.ClientChannel) | ||
var logBatch = []models.BarkLog{} | ||
if clientChannelLength > logBatchSizeStandard { | ||
// Bulk insert | ||
for i := 0; i < logBatchSizeStandard; i++ { | ||
elem, ok := <-channels.ClientChannel | ||
if !ok { | ||
fmt.Println("E# - Error occurred while getting batch from channel") | ||
break // Something went wrong | ||
} | ||
logBatch = append(logBatch, elem) | ||
} | ||
_, err := network.PostLogs(serverUrl+constants.BatchInsertUrl, logBatch) | ||
|
||
if err.Severity == 1 { | ||
fmt.Println(err.Msg) | ||
} | ||
fmt.Println("L# - Batch sent at ", time.Now().Format("2006-01-02 15:04:05")) | ||
} else if clientChannelLength > 0 && clientChannelLength < logBatchSizeStandard { | ||
// Commit one at a time | ||
singleLog := <-channels.ClientChannel | ||
_, err := network.PostLog(serverUrl+constants.SingleInsertUrl, singleLog) | ||
if err.Severity == 1 { | ||
fmt.Println(err.Msg) | ||
} | ||
} else { | ||
time.Sleep(1 * time.Second) | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package ingestion | ||
|
||
import ( | ||
"fmt" | ||
"github.com/techrail/bark/client/channels" | ||
"github.com/techrail/bark/models" | ||
) | ||
|
||
func InsertSingleRequest(logEntry models.BarkLog) { | ||
if len(channels.ClientChannel) > channels.ClientChannelCapacity-1 { | ||
fmt.Printf("E#1LB9MN - Channel is full. Cannot push. Log received: | %v\n", logEntry) | ||
return | ||
} | ||
channels.ClientChannel <- logEntry | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters