Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close worker if jobchan is closed #24

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,21 @@ func (p *Pool) AddWorkers(workers []Worker) {
func (p *Pool) startWorker(w Worker) {
defer func() {
if r := recover(); r != nil {
if err, ok := r.(error); ok && err.Error() == "send on closed channel" {
w.Close()
return
}
log.Error("[BridgeWorker][addToQueue] recover from panic", "message", r, "trace", string(debug.Stack()))
}
}()
for {
// push worker chan into queue if worker has not closed yet
if !w.IsClose() {
w.WorkersQueue() <- w.Channel()
}
w.WorkersQueue() <- w.Channel()
select {
case job := <-w.Channel():
if job == nil {
continue
}
log.Info("processing job", "id", job.GetID(), "nextTry", job.GetNextTry(), "retryCount", job.GetRetryCount(), "type", job.GetType())
if job.GetNextTry() == 0 || job.GetNextTry() <= time.Now().Unix() {
metrics.Pusher.IncrGauge(metrics.ProcessingJobMetric, 1)
Expand Down Expand Up @@ -212,7 +217,8 @@ func (p *Pool) Start(closeFunc func()) {
close(p.SuccessJobChan)
close(p.FailedJobChan)
close(p.Queue)


log.Info("finish closing pool")
// send signal to stop the program
p.stop <- struct{}{}
return
Expand All @@ -225,7 +231,6 @@ func (p *Pool) PrepareJob(job JobHandler) error {
if job == nil {
return nil
}
log.Info("[PrepareJobChan] preparing new job", "job", job.String())
// deduplication: get hash from data and type and check if it exists in `processedJobs` or not.
hash := p.utils.RlpHash(struct {
Data []byte
Expand All @@ -234,6 +239,7 @@ func (p *Pool) PrepareJob(job JobHandler) error {
Data: job.GetData(),
Type: job.GetType(),
})
log.Info("[PrepareJobChan] preparing new job", "job", job.String(), "hash", hash.Hex())
if _, ok := p.processedJobs.Load(hash); ok {
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (u *utils) NewEthClient(url string) (EthClient, error) {
}

func newKeyedTransactorWithChainID(signMethod ISign, chainID *big.Int) (*bind.TransactOpts, error) {
if signMethod == nil {
return nil, errors.New("no sign method found")
}
keyAddr := signMethod.GetAddress()
signer := types.LatestSignerForChainID(chainID)
return &bind.TransactOpts{
Expand Down