Skip to content

Commit

Permalink
Merge pull request #66 from vortex14/proxy-service-new-features
Browse files Browse the repository at this point in the history
updated
  • Loading branch information
vortex14 authored Feb 19, 2023
2 parents e277e96 + 974a362 commit 3a2e90b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
7 changes: 3 additions & 4 deletions elements/forms/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (p *BasePipeline) SafeRun(

p.RunMiddlewareStack(context, func(middleware interfaces.MiddlewareInterface, _err error) {
middlewareErr = _err
logger.Error("exit from middleware stack . Error: ", err.Error())
logger.Error("exit from middleware stack . Error: ", middlewareErr.Error())
}, func(returnedContext Context.Context) {
context = returnedContext
})
Expand All @@ -138,7 +138,6 @@ func (p *BasePipeline) SafeRun(
retry.Attempts(retryMaxCount),
retry.RetryIf(func(_err error) bool {
var status bool
err = _err
switch _err {
case Errors.ForceSkipPipelines:
status = false
Expand All @@ -147,12 +146,12 @@ func (p *BasePipeline) SafeRun(
default:
status = true
}
logger.Errorf("RetryIf .... %t, delay: %+v", status, p.Options.Retry.Delay)
logger.Errorf("RetryIf .... %t, delay: %+v; count: %d", status, p.Options.Retry.Delay, retryCount)
return status
}),
)

if err != nil || eR != nil {
if eR != nil {
catch(err)
}

Expand Down
3 changes: 2 additions & 1 deletion elements/forms/pipeline_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (g *PipelineGroup) Run(context Context.Context) error {
continue
}

pipeline.Run(mainContext, func(p interfaces.BasePipelineInterface, err error) {
pipeline.Run(middlewareContext, func(p interfaces.BasePipelineInterface, err error) {
switch err {
case Errors.ForceSkipPipelines:
forceSkip = true
Expand All @@ -73,6 +73,7 @@ func (g *PipelineGroup) Run(context Context.Context) error {
}

}, func(returnedResultPipelineContext Context.Context) {
errStack = nil
mainContext = returnedResultPipelineContext
})

Expand Down
2 changes: 1 addition & 1 deletion extensions/pipelines/http/emulator/rod/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (t *HttpRodResponsePipeline) Run(
}

reject(t, err)
t.Cancel(context, logger, err)
//t.Cancel(context, logger, err)
})

}
Expand Down
64 changes: 64 additions & 0 deletions extensions/pipelines/http/emulator/rod/test_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package rod

import (
"errors"
"github.com/PuerkitoBio/goquery"
"github.com/vortex14/gotyphoon/elements/forms"
"github.com/vortex14/gotyphoon/elements/models/label"
"github.com/vortex14/gotyphoon/elements/models/task"
"github.com/vortex14/gotyphoon/extensions/data/fake"
"github.com/vortex14/gotyphoon/interfaces"
Expand Down Expand Up @@ -80,3 +83,64 @@ func TestCreateRodPipeline(t *testing.T) {
})

}

func TestRetryResponse(t *testing.T) {
Convey("Move by coords", t, func() {
count := 0
g1 := forms.PipelineGroup{
MetaInfo: &label.MetaInfo{
Name: "Rod group",
},
Stages: []interfaces.BasePipelineInterface{
CreateRodRequestPipeline(
forms.GetCustomRetryOptions(2, time.Duration(3)*time.Second),
&DetailsOptions{
SleepAfter: 0,
Options: Options{
Debug: true,
},
},
),
&HttpRodResponsePipeline{
BasePipeline: &forms.BasePipeline{
NotIgnorePanic: true,
Options: &forms.Options{
Retry: forms.RetryOptions{
MaxCount: 5, Delay: time.Duration(3) * time.Second,
},
},
MetaInfo: &label.MetaInfo{
Name: "http response from rod emulator",
},
},
Fn: func(context context.Context, task interfaces.TaskInterface, logger interfaces.LoggerInterface,
browser *rod.Browser, page *rod.Page, body *string, doc *goquery.Document) (error, context.Context) {
if count == 2 {
return nil, context
}
count += 1
return errors.New("a new error"), context
},
Cn: func(err error,
context context.Context,
task interfaces.TaskInterface,
logger interfaces.LoggerInterface) {

logger.Error("--- ", err.Error())
},
},
},
}

_task := fake.CreateDefaultTask()
_task.SetFetcherUrl("https://google.com/")
_task.SetFetcherTimeout(600)
ctxGroup := task.NewTaskCtx(_task)

e := g1.Run(ctxGroup)

So(count, ShouldEqual, 2)

So(e, ShouldBeNil)
})
}

0 comments on commit 3a2e90b

Please sign in to comment.