@@ -50,7 +50,7 @@ type Handle struct {
50
50
// external dependencies
51
51
jobsDB jobsdb.JobsDB
52
52
errorDB jobsdb.JobsDB
53
- throttlerFactory * rtThrottler.Factory
53
+ throttlerFactory rtThrottler.Factory
54
54
backendConfig backendconfig.BackendConfig
55
55
Reporting reporter
56
56
transientSources transientsource.Service
@@ -228,7 +228,7 @@ func (rt *Handle) pickup(ctx context.Context, partition string, workers []*worke
228
228
firstJob = job
229
229
}
230
230
lastJob = job
231
- slot , err := rt .findWorkerSlot (workers , job , blockedOrderKeys )
231
+ slot , err := rt .findWorkerSlot (ctx , workers , job , blockedOrderKeys )
232
232
if err == nil {
233
233
status := jobsdb.JobStatusT {
234
234
JobID : job .JobID ,
@@ -306,6 +306,8 @@ func (rt *Handle) commitStatusList(workerJobStatuses *[]workerJobStatus) {
306
306
if err != nil {
307
307
rt .logger .Error ("Unmarshal of job parameters failed. " , string (workerJobStatus .job .Parameters ))
308
308
}
309
+ errorCode , _ := strconv .Atoi (workerJobStatus .status .ErrorCode )
310
+ rt .throttlerFactory .Get (rt .destType , parameters .DestinationID ).ResponseCodeReceived (errorCode ) // send response code to throttler
309
311
// Update metrics maps
310
312
// REPORTING - ROUTER - START
311
313
workspaceID := workerJobStatus .status .WorkspaceId
@@ -320,10 +322,6 @@ func (rt *Handle) commitStatusList(workerJobStatuses *[]workerJobStatus) {
320
322
}
321
323
sd , ok := statusDetailsMap [key ]
322
324
if ! ok {
323
- errorCode , err := strconv .Atoi (workerJobStatus .status .ErrorCode )
324
- if err != nil {
325
- errorCode = 200 // TODO handle properly
326
- }
327
325
sampleEvent := workerJobStatus .job .EventPayload
328
326
if rt .transientSources .Apply (parameters .SourceID ) {
329
327
sampleEvent = routerutils .EmptyPayload
@@ -487,7 +485,7 @@ func (rt *Handle) getQueryParams(partition string, pickUpCount int) jobsdb.GetQu
487
485
return params
488
486
}
489
487
490
- func (rt * Handle ) findWorkerSlot (workers []* worker , job * jobsdb.JobT , blockedOrderKeys map [string ]struct {}) (* workerSlot , error ) {
488
+ func (rt * Handle ) findWorkerSlot (ctx context. Context , workers []* worker , job * jobsdb.JobT , blockedOrderKeys map [string ]struct {}) (* workerSlot , error ) {
491
489
if rt .backgroundCtx .Err () != nil {
492
490
return nil , types .ErrContextCancelled
493
491
}
@@ -516,7 +514,7 @@ func (rt *Handle) findWorkerSlot(workers []*worker, job *jobsdb.JobT, blockedOrd
516
514
if rt .shouldBackoff (job ) {
517
515
return nil , types .ErrJobBackoff
518
516
}
519
- if rt .shouldThrottle (job , parameters ) {
517
+ if rt .shouldThrottle (ctx , job , parameters ) {
520
518
return nil , types .ErrDestinationThrottled
521
519
}
522
520
@@ -557,7 +555,7 @@ func (rt *Handle) findWorkerSlot(workers []*worker, job *jobsdb.JobT, blockedOrd
557
555
return nil , types .ErrBarrierExists
558
556
}
559
557
rt .logger .Debugf ("EventOrder: job %d of orderKey %s is allowed to be processed" , job .JobID , orderKey )
560
- if rt .shouldThrottle (job , parameters ) {
558
+ if rt .shouldThrottle (ctx , job , parameters ) {
561
559
blockedOrderKeys [orderKey ] = struct {}{}
562
560
worker .barrier .Leave (orderKey , job .JobID )
563
561
slot .Release ()
@@ -571,7 +569,7 @@ func (*Handle) shouldBackoff(job *jobsdb.JobT) bool {
571
569
return job .LastJobStatus .JobState == jobsdb .Failed .State && job .LastJobStatus .AttemptNum > 0 && time .Until (job .LastJobStatus .RetryTime ) > 0
572
570
}
573
571
574
- func (rt * Handle ) shouldThrottle (job * jobsdb.JobT , parameters routerutils.JobParameters ) (limited bool ) {
572
+ func (rt * Handle ) shouldThrottle (ctx context. Context , job * jobsdb.JobT , parameters routerutils.JobParameters ) (limited bool ) {
575
573
if rt .throttlerFactory == nil {
576
574
// throttlerFactory could be nil when throttling is disabled or misconfigured.
577
575
// in case of misconfiguration, logging errors are emitted.
@@ -584,7 +582,7 @@ func (rt *Handle) shouldThrottle(job *jobsdb.JobT, parameters routerutils.JobPar
584
582
throttler := rt .throttlerFactory .Get (rt .destType , parameters .DestinationID )
585
583
throttlingCost := rt .getThrottlingCost (job )
586
584
587
- limited , err := throttler .CheckLimitReached (parameters .DestinationID , throttlingCost )
585
+ limited , err := throttler .CheckLimitReached (ctx , parameters .DestinationID , throttlingCost )
588
586
if err != nil {
589
587
// we can't throttle, let's hit the destination, worst case we get a 429
590
588
rt .throttlingErrorStat .Count (1 )
0 commit comments