|
19810
|
Explorer (⇧⌘E)
Search (⇧⌘F)
SlackFileEditViewGoH Explorer (⇧⌘E)
Search (⇧⌘F)
SlackFileEditViewGoHistoryWindowHelpAPPDOCKER2-881DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed>Spayload Thesearch payload with filters, sorts, prope* @return array The search response with'results''total''paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 @ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lirHomeDMsActivityFilesLater..•More• [Platform) Refinemen…. 24 m left100% <78• Mon 11 May 16:36:42ED→Describe what you are looking forJiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...^ Direct messagesP. Aneliya Angelova®. Galya DimitrovaPetko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev• VesE Lukas Kovalik y... 0::: AppsS Jira CloudToastGanala Cala# support8 346 0MessagesC FilesBookmarksKara Joneswas added .Tuesday, April 28th~More v+Wednesday, April 29th ~Lauren Hudson 12:58 PMHi team, I'm trying to set up auto detect for LesMills, but when I add a new playbook (because theywant it applied across all teams), it's pulling in a loadof activity types that l am not able to delete. Anyideas please?Screenshot 2026-04-29 at 10.54.42.png •1 reply 12 days agoLauren Hudson 6:17 PMHello, request from Norstella to update theirJiminny to match this shared spreadsheet. lssomebody from the support team able to helpplease?Numbers Document -Message #support+Аа...
|
Code
|
Client.php — app — 9 problems in this file
|
NULL
|
19810
|
|
19811
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 12 pending changes
12
i Client.ohp g XV APP" services• Hubspol~OpportunitySynestrategy.• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Wwlallawwaa# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy> Redis~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.ohoBatchSvncRedisService.ohvI Cllient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho•FieldDefinitions.ohn• FieldTvoeConverter.oho# HubspotClientinterface.php#R HubspotTokenManager.phpR PayloadBuilder.php* PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> MetadataMiarationv Pipedrive• OpportunitySvncStrateav• ProspectSearchStrateavOUTIINETIMELINGi8 JY-20725-handle-HS-search-rate-limit* ©06A902app > Services > Crm › Hubspot › f* Client.php › •g Client > search()1mp Lements HubspotclientintertaceSthis->setBaseUrl(self:: BASE_URL) :sthis->setVersion(self::MIN APT VERSION):* Execute a Hubspot APl call wich rate Limit nanduing.* On a 429, stores the absolute expiry timestamp with SET NX (Tirst writer wins).* This means all subsequent iobs that also receive 429 in the same burst do not* reset the TTL = the window is anchored to the first 429. not the last.* Readers compute the remaining wait from the stored timestamp, so jobs that checkanaram callabled: T sapicall The Ap call to execute•athrows RateLimitExcention When rate Umit is hit or cached rate Uimit is active• Greturn T The result of the ApT callprivate function executeRequest(callable $apicall)ScacheKev = Sthis-saetRateLimitCacheKev0•ScachedExpiresAt = Redis:: get(ScacheKey);if (is string(ScachedExpiresAt) && is numeric(ScachedExpiresAt) ) {Sremaining = max1,1nt ScachedExpiresAt- timeo):throw new RateLimitExceotiond'Hubspot rate limit (cached circuit-breaker)',$remainingtryeturn sapicallo:} catchable $e) (if (Sthi.:HubspotRateLimit(Se)) {SretrvAfter = sthis-narseRetrvAfter(se)// NX: only the first job to receive a 429 in this burst sets the key.Subsequent 429S 1nthe same burst leaveTll untouchedso thewindow 1s not reset by every concurrent 10b hittina the Limit.Redis::set ScacheKev. (string) (time• + SretrvAfter), 'nx".'ex" = SretrvAfterl):sthis->loo-swarnina'Hubsoot Received 429 from APT".Iteam id!- Sthis-sconfia-steam id."confia id'= Sthic-sconfia-snettd).throw new RateLimitExcention"Hubsoot returned 429'. SretrvAfter. Se?throw te.: [Platform] Refinemen... 24 m left100% L2Mon 11 May 16:36:41›* Review rate limit handli... XReview rate limit handling for HubSpot jo..? handienuospotkateLimitfix @tests/Unit/Services/Crm/Hubspot/Pagination/HubspotPaginationServiceTest.php and @tests/Unit/Jobs/Crm/MatchActivityCrmDataTest.php• Edit MatchActivityCrmDataTest.phppublic function testralledhethoclogsError(): voitpublic function testfal ledMethodlogsError(): Voldsexcepcion = new kuncimeexcepcion("lest Talture);sexception = new \kuncimeexception( lest Tallure");Sentry::shouldReceive'captureException->once)->with Sexception:Siob = new MatchActivitvCrmData(activitvid: 123.Siob = new MatchActivitvCrmDataactivitvid: 123fromConfiguration: null,remotoSearch. +ruefromConfiguration: null,• Now the pagination service test. The root problem is createMock(Client::class) mocks search() to return (, sothe hubspotClientMock->request() chain is never reached. The fix is to mocksearch() directly and drop the HTTP client chain entirely.• Write HubspotPaginationServiceTest.php<?ohodeclare(strict types=1);MatchActivitycrmDataTest - two changes• $job->tries → $job->maxExceptions : the job has no $tries property; it uses retryUntil() for retry bounding and maxExceptions for exception counting• unquerone assertion 360→ 260Hmatches 120 * 60 + 60 afterithe REURY WINDOW MNULES Changerthe od value sbo diont matchithe o ditormula either solt was already brokertectFailedMethodl.oocFrror.added\Centrv:•chouldReceive/( "cantureSycention'=sonceo since failedo now callsitHubspotPaginationServiceTest — structural fix:he oricina litests mocked netainstanca 0E>dat dltenti0reduesiti@lexo ectina the rea ldltentzu seanch @ltolbe calledlthrouch that chain Buta oreat eMock di llentrura lassilmocksseanch<oo (return[] ), so request() was never reached - every test was silently returning 0 results. Fixed by mocking search() directly on SclientMock, which is the actual boundary the pagination service interacts withDronned the now-unused sfactorvMock. ShubsnotClientMock.and createHubsnotResnonse().$endpoint = self::BASE URL."/crm/v3/objects/{$objectType)/search":return $this->executeRequest(function () use (Sendpoint, $payload) <Sresponse = Sthis-"POSt". Sendpoint. Wison' =>$payload]):return Sresponse->toArray0:10 lines selectedAsk before edit.8 SignIn...
|
Code
|
Client.php — app — 9 problems in this file
|
NULL
|
19811
|
|
19812
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 12 pending changes
12
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
SlackFileEditViewGoHistoryWindowHelp•APPDOCKERO ₴1DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed>Spayload Thesearch payload with filters, sorts, prope* @return array The search response with'results''total'*'paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 @ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lirHomeDMsActivityFilesLater..•More• [Platform) Refinemen…. 24 m left100% <78• Mon 11 May 16:36:47ED→Describe what you are looking forJiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...^ Direct messagesP. Aneliya Angelova®. Galya DimitrovaPetko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev• VesE Lukas Kovalik y... 0::: AppsS Jira CloudToastGanala Cala# support8 346 0MessagesC FilesBookmarksKara Joneswas added .Tuesday, April 28th~More v+Wednesday, April 29th ~Lauren Hudson 12:58 PMHi team, I'm trying to set up auto detect for LesMills, but when I add a new playbook (because theywant it applied across all teams), it's pulling in a loadof activity types that l am not able to delete. Anyideas please?Screenshot 2026-04-29 at 10.54.42.png •1 reply 12 days agoLauren Hudson 6:17 PMHello, request from Norstella to update theirJiminny to match this shared spreadsheet. lssomebody from the support team able to helpplease?Numbers Document -Message #support+Аа...
|
Code
|
Client.php — app — 9 problems in this file
|
NULL
|
19812
|
|
19813
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 12 pending changes
12
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
: [Platform] Refinemen... 24 m left100% 5• Mon 11 May 16:36:47Client.php - app - 9 problems in this fileClient.php 9 xDv 23 00EXPLORE:m RateLimitException.ohdV Appapp > Services > Crm › Hubspot › f* Client.php › °g Clientclass Client extends Baseclient 1mplements Hubspotclientintertacev Services123• Hubspol~OpportunitySynestrategy..• HubsnotLastModified@nenSvncStra..137# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.V Dadinationi# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy→Hoal~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.phoBatchSvncRedisService.ohvCliient.oho|• ClosedDea|StagesService.oho* DealFieldsService.oho* DecorateActivitv.oho•FieldDefinitions.ohn• FieldTvneConverter.ohn# HubspotClientinterface.php# HubspotTokenManager.php€ DavloadRuilder nhn* PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.phpIntearationapo• Listeners> MetadataMiarationV Pipedrive• OpportunitySvncStrateav• ProspectSearchStrateavOUTIINE, TIMELING1MCALi8 JY-20725-handle-HS-search-rate-limit* ©SEEEBДБESpub lic tunction 1sHubspotRateL1m1t Throwable Se: boolreturn talsepubLic tunction parseretryArter(Throwable se: 1ny1t method exists(se, 'getResponseMeaders")) ‹Sheaders = Se->aetResponseHeaders@ ?:0•$value = $headers('Retry-After') ?? $headers('retry-after') ?? null;$value = $value[0] ?7 null;if (is numeric(Svalue)) {$message = strtolower($e->getMessage));if (str contains($message, 'daily')) {return 600if str contains(Smessage, "ten secondly') <return 10:if (str_contains($message, 'secondly')) {return 1.Sthis->loq->warning('(Hubspot) No retry-after header or known message, using default'. [get_class(Se)= Smessage,return 10.public function getMinimumApiVersion(): stringreturn celf.-MtN ApT VERSTON•public function getInstance(): Factoryreturnnew Factory([= Sthis→>accessToken.= true.''base url => Sthis->baseUruoublic function aetNewinstance: Discovervreturn HubSpot\Factorv::createWithAccessToken/Sthis-saccessToken@6A902|23 Review rate limit handli...Review rate limit handling for HubSpot jo..? handienuospotkateLimitfix @tests/Unit/Services/Crm/Hubspot/Pagination/HubspotPaginationServiceTest.php and @tests/Unit/Jobs/Crm/MatchActivityCrmDataTest.php• Edit MatchAct vitycrmbatalest.on:public function testralledhethoclogsError(): voitpublic function testfal ledMethodlogsError(): Voldsexcepcion = new kuncimeexcepcion("lest Talture);sexcepcion = new kuncimeexception("lest Talture);Sentry::shouldReceive'captureException->once)->with Sexception:Siob = new MatchActivitvCrmData(activitvid: 123.Siob = new MatchActivitvCrmDatafromConfiguration: null,remotoSearch. +ruefromConfiguration: null,createMock(Client::class) mocks search() toreturn (], sothe hubspotClientMock->request( chain is never reached. The fix is to mocksearch() directly and drop the HTTP client chain entirely.• Write HubspotPaginationServiceTest.php<?ohodeclare(strict types=1):MatchActivityCrmDataTest - two changes• $job->tries → $job->maxExceptions : the job has no $tries property; it uses retryUntil() for retry bounding and maxExceptions for exception counting• unquerone assertion 360→ 260Hmatches 120 * 60 + 60 afterithe REURY WINDOW MNULES Changerthe od value sbo diont matchithe o ditormula either solt was already broker•tectFailedMethodl.oocFrror•added \Sentrv:: chouldReceive( "cantureFycention' _soncel since failedo now calls itHubspotPaginationServiceTest — structural fix:he oricina litests mocked netainstanca 0E>dat dltenti0reduesiti@lexo ectina the rea ldltentzu seanch @ltolbe calledlthrouch that chain Buta oreat eMock di llentrura lassilmocksseanch<oo (return[] ), so request() was never reached - every test was silently returning 0 results. Fixed by mocking search() directly on SclientMock, which is the actual boundary the pagination service interacts withDronned the now-unused SfactorvMock. ShubsnotClientMock.and createHubsnotResnonse().$endpoint = self::BASE URL."/crm/v3/objects/{$objectType)/search":return $this->executeRequest(function () use (Sendpoint, $payload) <Sresponse = Sthis-›"POSt". Sendpoint. Wison' =>$payload]):return Sresponse->toArray0:11 Client.ohoAsk before edit.A tnkoe Vouolil 160 minutoe ondlSpaces: 4 UTF-8 LF ( PHP 8 SignIn 8.3P 0...
|
Code
|
Client.php — app — 9 problems in this file
|
NULL
|
19813
|
|
19814
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 12 pending changes
SlackFileEditViewGoHistoryWindowHelpAPPDOCKER0 ₴1DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed>Spayload Thesearch payload with filters, sorts, prope* @return array The search response with'results''total'*'paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 @ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lirHomeDMsActivityFilesLater..•More• [Platform) Refinemen…. 24 m left100% <78• Mon 11 May 16:36:49ED→Describe what you are looking forJiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...^ Direct messagesP. Aneliya Angelova®. Galya DimitrovaPetko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev• VesE Lukas Kovalik y... 0::: AppsS Jira CloudToastGanala Cala# support8 346 0MessagesC FilesBookmarksKara Joneswas added .Tuesday, April 28th~More v+Wednesday, April 29th ~Lauren Hudson 12:58 PMHi team, I'm trying to set up auto detect for LesMills, but when I add a new playbook (because theywant it applied across all teams), it's pulling in a loadof activity types that l am not able to delete. Anyideas please?Screenshot 2026-04-29 at 10.54.42.png •1 reply 12 days agoLauren Hudson 6:17 PMHello, request from Norstella to update theirJiminny to match this shared spreadsheet. lssomebody from the support team able to helpplease?Numbers Document -Message #support+Аа...
|
Code
|
Client.php — app — 9 problems in this file
|
NULL
|
19814
|
|
19815
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G)
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
i Client.ohp g XV APP• Hubspol~OpportunitySynestrategy..• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Wwlallawwaa# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.phoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn• FieldTvoeConverter.oho# HubspotClientinterface.php# HubspotTokenManager.phpR PayloadBuilder.php** PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> Metadata• MiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGi8 JY-20725-handle-HS-search-rate-limit* ©app > Services > Crm › Hubspot › f* Client.php › °g Client › parseRetryAfter ()class Client extends Baseclient 1mpLements HubspotclientiIntertace123pub lic tunction 1sHubspotRateL1m1t Throwable Se: boolpub L1c• tunction-parseretryArter(Throwable se):• 1nc1t• method exists se,'getResponseMeaders"))•‹Sheaders =Se->aetResoonseHeaderso-?:-0*$value = $headers ('Retry-After')•?? Sheaders['retry-after')•?? null;$value = $value[0]-??-null;if. (1s numeric(svatue)). +Smessage = strtolower($e->getMessage));it• (sur contains(smessage, ' dally y)'1if• (str_contains(Smessage,'ten secondly")) •1return-10:if• (str_contains($message, 'secondly')) -{return-1;Sthis->loq->warning(* (Hubspot)•No retry-after header or known message, using default'.•lget_class($e),message" .= Smessage.return.10.public function getMinimumApiVersion(): stringreturn celf.-MtN ApT VERSTON•public function getInstance(): Factoryreturn= Sthis→>accesstoken,'oauth?'base url => sthis->baseUruoublic function aetNewinstance: Discovervreturn HubSpot\Factorv::createWithAccessToken/Sthis-saccessToken@6A902|* [Platform] Refinemen... 24 m left100% 5Mon 11 May 16:36:51*0&.3 Review rate limit handli... XReview rate limit handling for HubSpot jo..? handienudspotkateLimifix @tests/Unit/Services/Crm/Hubspot/Pagination/HubspotPaginationServiceTest.php and @tests/Unit/Jobs/Crm/MatchActivityCrmDataTest.php^Edit MatchActivityCrmbatarest.phgpubliC function testfal ledMethodLogsError (): VOldpublic function testfal ledMethodlogsError(): Voldsexcepcion = new kuncimeexcepcion("lest Talture);sexcepcion = new kuncimeexception("lest Talture);Sentry::shouldReceive'captureException'->once->w1th Sexception=Siob = new MatchActivitvcrmData(activitvid: 123.Siob = new MatchActivitvCrmDatafromConfiguration: null,remotoSearch. +ruefromConfiguration: null,• Now the pagination service test. The root problem is createMock(Client::class) mocks search() to return (, sothe hubspotClientMock->request() chain is never reached. The fix is to mocksearch() directly and drop the HTTP client chain entirely.• Write HubspotPaginationServiceTest.php<?ohodeclare(strict types=1):MatchActivityCrmDataTest - two changes• $job->tries → $job->maxExceptions : the job has no $tries property; it uses retryUntil() for retry bounding and maxExceptions for exception counting• unquerone assertion 360→ 260Hmatches 120 * 60 + 60 afterithe REURY WANDOW MNULES Changerthe od value sbo diont matchithe o ditormula either solt was already broker•tectFailedMethodl.oocFrror•added \Sentrv:: chouldReceive( "cantureFycention' _soncel since failedo now calls itHubspotPaginationServiceTest — structural fix:he oricina litests mocked netainstanca 0E>dat dltenti0reduesiti@lexo ectina the rea ldltentzu seanch @ltolbe calledlthrouch that chain Buta oreat eMock di llentrura lassilmocksseanch<oo (return[] ), so request() was never reached - every test was silently returning 0 results. Fixed by mocking search() directly on SclientMock, which is the actual boundary the pagination service interacts withDronped the now-unused sfactorMock. ShubsootClientMock.and createHubsnotResnonse(.$endpoint = self::BASE URL."/crm/v3/objects/{$objectType)/search":return $this->executeRequest(function () use (Sendpoint, Spayload) <Sreso$payload]):"POSt". Sendpoint. Wison' =>return Sresponse->toArray0:and…9 107 lines selectedAsk before edit.88 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19815
|
|
19913
|
SlackFileEditViewGoHistoryWindowHelpAPP ()DOCKER0 SlackFileEditViewGoHistoryWindowHelpAPP ()DOCKER0 ₴1DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed>Spayload Thesearch payload with filters, sorts, prope* @return array The search response with'results''total'*'paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 0ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lir• 0EDHomeDMsActivityFilesLater..•More→Jiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...• Direct messages®. Aneliya Angelova®. Galya DimitrovaPetko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev• VesE Lukas Kovalik y... OE:: Appsã Jira CloudToast100% <78• Mon 11 May 17:12:37Describe what you are looking for# support8 346 0MessagesC FilesBookmarksKara Joneswas added.Tuesday, April 28th~More v+Wednesday, April 29th ~Lauren Hudson 12:58 PMHi team, I'm trying to set up auto detect for LesMills, but when I add a new playbook (because theywant it applied across all teams), it's pulling in a loadof activity types that l am not able to delete. Anyideas please?Screenshot 2026-04-29 at 10.54.42.png •1 reply 12 days agoLauren Hudson 6:17 PMHello, request from Norstella to update theirJiminny to match this shared spreadsheet. lssomebody from the support team able to helpplease?Numbers Document •Message #support+...
|
Code
|
✻ [Claude Code] ClientTest.php (ClientTest.php) — ✻ [Claude Code] ClientTest.php (ClientTest.php) — app...
|
NULL
|
19913
|
|
19914
|
FirefoxEditVIewNew TabJy 20820 es reindex stream m FirefoxEditVIewNew TabJy 20820 es reindex stream mode# (UY-20725] [HubSpot] Optimise CFSevenShores Hi@ JY-20725 add HS rate limit har X© Pipelines - jiminny/app+ New TabHistory BookmarksProtllesToolsWindow HelpO github.com/jimir— have zero test coverage. In particular:• parseRetryAfter() : the Retry-After header parsing, fallback to message keyword matching, and thedefault-10-second case• isHubspotRateLimit() : each of the exception type branches• executerequest . tne cachea circul-breaker patn early throw wnen keais key exists, andtne sel nx pauwhen a live 429 is receivedThese are the most impactful paths to cover to get over the 70% gate.Minor observations5. Test constants duplicated from production codeHandleHubspotRateLimitTest.php re-declares MAX RETRY DELAY = 600. MIN_RETRY DELAY = 1. andJITTER SECONDS = 5 (lines 20-22). If these ever change in the middleware, the tests will silently use the old valuesand could still pass while testing the wrong bounds. Consider testing relative to the actual delay value returnedrather than hard-coding the expected range.6. Double-clamping in RateLimitExceptionThe constructor default SretryAfter = 1 (line 13) and getRetryAfter() calling max($this->retryAfter, 1) (line21) both guard against zero/negative values. The max() in the getter is unreachable given the current signaturedetault. Not a bua, but a minor inconsistency.7. RateLimitException in MatchActivityCrmData::failed()Ihe failedo hook (line 1/2) checks Sexception instanceof RateLimitExcedtion. but the middleware alwavs callsSjob->release() without re-throwing, so failed() would only fire for rate limit exceptions if the retryUntil()window expires with a pending rate-limit release, or if somehow the middleware is not applied. The check isdetensive and harmless. but worth notina in a comment since the nath is non-obvious)s8 This branch has not been deployedNo deploymentsAdd a commentWritoPreviewHB»0ssociationMulti;ption;iations as DealWithfervice:ine';$0100% L2Mon 11 May 17:12:370 000• 2 C;→ Review rate limit handli...*Keview fate lmit nanaling tor nuospouo..< Client.php#62-168Add coverage of new methods in Client public function search(string $objectType, array Spayload): array• Thought for 21s ?• Bash Check if ClientTest has tearDown or Mockery cleanurgrep -n "tearDown\ |Mockery::close\ |MockeryPHPUnit" /Users/lukas/jiminny/app/tests/Unit/Services/Crm/Hubspot/ClientTest.php | head -10OUT (Bash comoleted with no outout)• Bash Check existina imoorts for APl excentions in ClientTestgrep -n "DealApiException vicontactApiExceptiion V ICompanyApiExcepti on V Rate !mitException" 7Users/Lukas/#lminny/apo//tests/Unit7/Services/crm /Hubspot/cuentrest. pho head =10OUT (Bash completed with no output)• Thought for 1s ›• Now I have a clear picture. Let me write the new tests. I'll add them to the end of ClientTest.php (before the closing } ), with the necessary imports added at the top• Read ClientTest.php• Now I'll add the necessary imports and test methods:• Edit ClientTest.ohouse GuzZleHtto Psr/ Response:ciations\Api\BatchApi;use HubSpot\Client\Crm\Associations\Mocuse nusporrelentiem assocraczons modelruo Licoo ecteo,use nubsootsePubLicAssociationMulti.use HubSpot\CLient\Crm\Deals\Api\BasicApi as DealsBasicApi;lodel\Puo Licob ectlo• use nubspot cllent crm companzes Apicxcepcion as companyapiexcepclonuse Hubspot Client crm contacts ApiException as contactAp1Exception;use Hubspot clent crm deals Aoi BasicAdi as DealsbasicAo1:use HubSpot\CLient\Crm\Deals\Model|SimplePublicObjectWithAssociations asuse HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations asMake this edit to ClientTest.php?11 Yes7Yes. alllow all edits this session3 NoTell Claude what to do insteadEsc to cancelLn 12, Col 1 Spaces: 4 UTF-8 LF PHP 8 Sign In 8.3 g...
|
Code
|
✻ [Claude Code] ClientTest.php (ClientTest.php) — ✻ [Claude Code] ClientTest.php (ClientTest.php) — app...
|
NULL
|
19914
|
|
19915
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 12 pending changes
12
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
SlackFileEditViewGoHistoryWindowHelpAPP ()DOCKER₴81DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed>Spayload Thesearch payload with filters, sorts, prope* @return array The search response with'results''total'*'paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 @ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lir• 0EDHomeDMsActivityFilesLater..•More→Jiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...• Direct messages®. Aneliya Angelova®. Galya DimitrovaPetko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev. VesE Lukas Kovalik y... OE:: Appsã Jira CloudToast100% <78• Mon 11 May 17:12:41Describe what you are looking for# support8 346 0MessagesC FilesBookmarksKara Joneswas added.Tuesday, April 28th~More v+Wednesday, April 29th ~Lauren Hudson 12:58 PMHi team, I'm trying to set up auto detect for LesMills, but when I add a new playbook (because theywant it applied across all teams), it's pulling in a loadof activity types that l am not able to delete. Anyideas please?Screenshot 2026-04-29 at 10.54.42.png •1 reply 12 days agoLauren Hudson 6:17 PMHello, request from Norstella to update theirJiminny to match this shared spreadsheet. lssomebody from the support team able to helpplease?Numbers Document •Message #support+...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19915
|
|
19916
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 12 pending changes
12
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
WindovUsers › lukas › jiminny > app > tests › Unit › Services › Crm › Hubspot › *** ClientTest.php ›...• 2 C→= Review rate limit handli..V APP" services• Hubspol~OpportunitySynestrategy..# HubspotLastModifiedOpenSyncStra...,# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Pagination# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy> Redis~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.ohoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn• FieldTvoeConverter.oho# HubspotClientinterface.php#R HubspotTokenManager.phpR PayloadBuilder.php** PemoteCrmObiectManinulator.nhnR ResponseNormalize.php• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> MetadataMiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGMYSOLi8 JY-20725-handle-HS-search-rate-limit* ©HnkGnotlCldontlCrmlAccheiottonclAnflPotchAns.putPub LicoblectlohePublicAssociationMultiuse HubSpot\Client\Crm\Associations\Model\Public0bjectId;12 use HubSpot\Client\Crm\Deals\Api\BasicApi as DealsBasicApi;use HubSpot\Client\Crm\Deals\Model\SimplePublic0bjectWithAssociations as Dealuse Hubsoot clent crm Pipelines Ap1 Pipelinesao1?useHubSoot Client Crm Pinelines Model CollectionResponsePipeline:HubSoot client crn. Pinelines Model Error.HubSoot\ Client\ Crnl Pinelines Model Pineline:HubSpot\Client\Crm\Pipelines\Model\PipelineStage;NNNNuse Jiminny services crm hubspoc raqinacion hubspotraqinacionservice.use Leaque Authz clent Token Accesstoken:31 use PHPUnit\Framework\Mock0bject\Mock0bject;22 uce Perll.oalNulll.onger.use SevenShores\Hubspot\Endpoints\Engagements:use SevenShores|Hubspot\Htto\Response as HubspotResponse:*oruniescsinsevarateproceccesnPocopuolnnsstatlesnanclass ClientTest extends Testcaseorivate const strina RESPONSE TYPE STAGE FIELD = 'stage'.nrivate const strina RESPONSE TYPF PTPFLINE FTFID = Ininelinel.* avar Client&Mock0biectprivate Client Sclient:Configuration Sconfia.* @var SocialAccountServicesMock0bject@6 A9©21Client.php 9<tphpdeclare (strict tvoes=1):namespace leststuntebservecestemtnuospot,use ouzzlentuo rsr/kesponse.IsePublicAssociationMulti:(Model\PubLicObjectId;use nuospoticurentiermndeaisapt basacapi as vealsbasicapt,use Hubspot client crm Deals Model S1mp LePub L1cob1ectW1thAssoclations as DealWithAuse Hubsoot cllent Crm Pipelines Ao1 PioeUnesao1:use HubSpot Client Crm Pinelines Model CollectionResponsePipeline:use HubSoot Client crm. Pinelines Model Error.use HubSnot Client\ Crml Pinelines Model Pineline:use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;use HubSnot| Glient\Grml Pronertiec|AnilGoreAnievery as Dealsbiscovery;eldJiminny\Services\Crm\Hubspot\Client;use Jiminny services erm hubspot nubspoclokenmanager,use Jiminny services crm hubspoc raqnacion hubspotraqinacionservice:use Jiminny Services Socia AccountService:use PHPUnit Framework MockOhiect MockOhiect:use PerlloalNulll.oager.use SevenShores|Huhsnot|Endnointc|Fnaanementc.not\Http\Client as HubspotClient;use SevenShores\Hubspot\Http\Response as HubspotResponse:• ArunTectcTnSenarateProcaçcedAnrocoruoGlnhalCtoto dicohlodclass ClientTest extends Testcaseorivate const strina RESPONSE TYPE STAGE FTELD = 'stage'.private const string RESPONSE TYPE PIPELINE FIELD = 'pipeline';private const string RESPONSE TYPE REGULAR FIELD = 'regular';avar Client&Mock0bjectAriuoto Cliont dolsont.private Configuration Sconfia:* evar SocialAccountServicesMockObiectUsers/ukas/1minnvlaop/tests/Unit/Services/crm/=ubspot/cllientest.onouse GuzzleHtto Psr7 Response:use HuhSnot Clrient| CrmlAcsociat ons\An.BatchAni:use HubSnot\Client|CrmlAcsociationc|Model\BatchTnnutPublic0biecttd:use HubSpot\Client\Crm\Associations\Model\BatchResponsePublicAssociationMulti;use HubSpot\Client\Crm\Deals\Api\BasicApi as DealsBasicApi;use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations asvedtwrthassoclations,use HubSpot\Client\Crm\Pipelines\Api\PipelinesApi;use nubspot cllenc cr ripeuines model coulectionkesponseripeuineuse Hubspot cuent crm Pipelunes Model Pideuineuse HubSpot\Client\Crm Pipelines Model\PipelineStage;use HubSnot cuient erm. Pronerties Ant Coreant:use HubSpot\Client\Crm\Properties\Model\Property;use HubSpot\Discovery as HubSpotDiscovery;use HubSpot\Discovery\Crm\Deals\Discovery as DealsDiscoveryuseuse Jiminny services tehilospot ragination nuospotraginatzonservice,use Jiminny services socla laccountselvice,Leaque \OAuchz ellentloken\accessloken;use PHPUnit\Framework\Mock0biect\Mock0biect:use PHPUnilt Framework Testcase:use SevenShores\Hubspot\Endpoints\Engagements;use SevenShoresl Huhsnotl Factorv.use SevenShorec|HubcnotlHttnlClient ac HubcnotClient.use SevenShores\Hubspot\Http\Response as HubspotResponse:100% 1Mon 11 May 17:12:43V*90₴use GuzzleHtto Psr7 Response:use HuhSnot Clrient| CrmlAcsociat ons\An. RatchAni:use HubSnot\Client|CrmlAcsociationc|Model\BatchTnnutPublic0biecttd:use HubSpot\Client\Crm\Associations\Model\BatchResponsePublicAssociationMulti;ent\Crm\Deals\Model\SimplePublicObjectWithAssociations asvedtwrthassoclacions,HubSpot\Client\Crm\Pipelines\Api\PipelinesApi;nubspot cllent crm rpeuines model coulectionkesponseripeuine.use Hubspot clent crm Pipelunes Model Pipeuineuse HubSpot\Client\Crm Pipelines Model\PipelineStage;use HubSnot cuient erm. Pronerties Ant Coreani:use HubSpot\Client\Crm\Properties\Model\Property;use HubSnot\Discovery as HubSnothiscovervuse HubSpot\Discovery\Crm\Deals\Discovery as DealsDiscovery:useusespot ragination nubspotraginattonservice,useJiminny services socla laccountselvice,League \OAuchz \ellentloken\Accessloken;PHPUnit Framework Mockob1ect Mockoblectuse PHPUnilt Framework Testcase:use Psr.Loa NullLoager:use SevenShores|Hubsnot\Endnoints|Engagements.use SevenShorec| HubcnotlHttnlClient ac Huhcnotclient.use SevenShores\Hubspot\Http\Response as HubspotResponse:88 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19916
|
|
19917
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 12 pending changes
12
Run and Debug (⇧⌘D)
Remote Explorer
SlackFileEditViewGoHistoryWindowHelpAPP ()DOCKER- ₴81DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed>Spayload Thesearch payload with filters, sorts, prope* @return array The search response with'results''total'*'paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 @ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lir• 0EDHomeDMsActivityFilesLater..•More→Jiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...^ Direct messagesP. Aneliya Angelova®. Galya Dimitrova. Petko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev. VesE Lukas Kovalik y... O::: AppsS Jira CloudToast100% <78• Mon 11 May 17:12:46Describe what you are looking for# support8 346 0MessagesC FilesBookmarksKara Joneswas added .Tuesday, April 28th~More v+Wednesday, April 29th ~Lauren Hudson 12:58 PMHi team, I'm trying to set up auto detect for LesMills, but when I add a new playbook (because theywant it applied across all teams), it's pulling in a loadof activity types that l am not able to delete. Anyideas please?Screenshot 2026-04-29 at 10.54.42.png •1 reply 12 days agoLauren Hudson 6:17 PMHello, request from Norstella to update theirJiminny to match this shared spreadsheet. lssomebody from the support team able to helpplease?Numbers Document •Message #support+...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19917
|
|
19918
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 12 pending changes
12
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
WindovUsers › lukas › jiminny > app > tests › Unit › Services › Crm › Hubspot › ** ClientTest.php › ...V APP" services• Hubspol~OpportunitySynestrategy..# HubspotLastModifiedOpenSyncStra...,# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Pagination# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy> Redis~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.ohoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn|• FieldTvoeConverter.ohn# HubspotClientinterface.php#R HubspotTokenManager.phpR PayloadBuilder.php** PemoteCrmObiectManinulator.nhnR ResponseNormalize.php• Service.php#R SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> MetadataMiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGMYSOLi8 JY-20725-handle-HS-search-rate-limit* ©HnkGnotlCldontlCrmlAccheiotfonclAnflPotchAns.putPub LicoblectldhePublicAssociationMultiuse HubSpot\Client\Crm\Associations\Model\Public0bjectId;12 use HubSpot\Client\Crm\Deals\Api\BasicApi as DealsBasicApi;use HubSpot\Client\Crm\Deals\Model\SimplePublic0bjectWithAssociations as Dealuse Hubsoot clent Crm Pipelines Ap1 Pipelinesao1?useHubSoot Client Crm Pinelines Model Collect ionResponsePipeline:HubSoot client crn. Pinelines Model Error.HubSoot\ Client\ Crnl Pinelines Model Pineline:HubSpot\Client\Crm\Pipelines\Model\PipelineStage;NNNNuse Jiminny services crm hubspoc raqinacion hubspotraqinacionservice.use Leaque Authz clent Token Accesstoken:31 use PHPUnit\Framework\Mock0bject\Mock0bject;22 uce Perll.oalNulll.onger.use SevenShores\Hubspot\Endpoints\Engagements:use SevenShores|Hubspot\Htto\Response as HubspotResponse:*oruniescsinsevarateproceccesAnPocoPolnnsrstodeshlanclass ClientTest extends Testcaseorivate const strina RESPONSE TYPE STAGE FIELD = 'stage'.nrivate const strina RESPONSE TYPF PTPFLINE FTFID = Ininelinel.* avar Client&Mock0biectprivate Client Sclient:Configuration Sconfia.* @var SocialAccountServicesMock0bject@6 A9©21#Client.oho 9<tphpdeclare (strict tvoes=1):namespace leststuntebservecestemtnuospot,use ouzzlenttorsr/ kesponse,sePublicAssociationMulti:use nuospoticurent ermbeaisapt basacapi as vealsbasicapt,use HubSpot\Client\Crm\Deals\Model\SimplePublic0bjectWithAssociations as DealWithuse Hubsoot cllent Crm Pipelines Ao1 PioeUnesao1:use HubSpot Client Crm Pipelines Model CollectionResponsePipeline:use HubSoot Client crm. Pinelines Model Error.use HubSnot Client\ Crml Pinelines Model Pineline:use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;use HubSnot| Glient\ Grml Pronertiec| AnilGoreAnieery as Dealsbiscovery;ield;use Jiminny\Services\Crm\Hubspot\Client;use Jiminny services erm hubspot nubspoclokenmanager,use Jiminny services crm hubspoc raqnacion hubspotraqinacionservice:use Jiminny Services Socia AccountService:use PHPUnit Framework MockOhiect MockOhiect:use PerlloalNulll.oager.use SevenShores|Huhsnot|Endnointc|Fnaanementc.not\Http\Client as HubspotClient;use SevenShores\Hubspot\Http\Response as HubspotResponse:AnrocoruoGlnhalCtoto dicohlodclass ClientTest extends Testcaseorivate const strina RESPONSE TYPE STAGE FTELD = 'stage'.private const string RESPONSE TYPE PIPELINE FIELD = 'pipeline';private const string RESPONSE TYPE REGULAR FIELD = 'regular';* avar Client&Mock0biectariuoto Cliont coldont.private Configuration Sconfia:* evar SocialAccountServicesMockObiect100% LzMon 11 May 17:12:47• 2 C→ Review rate limit handli...xmAIKeview fate lmit nanaling for nuospouo..<› Client.nhn#62-1681Add coverage of new methods in Client public tunction search(string sobiectlype, array spayload): array•Thought for 21s ?• Bash Check if ClientTest has tearDown or Mockery cleanurgrep -n "tearDown\ |Mockery::close\ |MockeryPHPUnit" /Users/lukas/jiminny/app/tests/Unit/Services/Crm/Hubspot/ClientTest.php | head -10(Bash comoleted with no outout)• Bash Check existina imoorts for APl excentions in ClientTestgrep -n "DealApiException vicontactApiExceptiion V ICompanyApiExcepti on V Rate !mitException" 7Users/Lukas/#lminny/apo//tests/Unit7/Services/crm /Hubspot/cuentrest. pho head =10OUT (Bash completed with no output)• Thouaht for 1c >• Now I have a clear picture. Let me write the new tests. I'll add them to the end of ClientTest.php (before the closing } ), with the necessary imports added at the top• Read GlientTect.nhnlNow l'lladd the nececcarv imnorts and toct methods.• Edit ClientTest.ohouse GuzzleHtto Psr/ Response:use GuzzleHtto Psr7 Response:ciations\ Api\ BatchAnieruoescassocracsonmulteuse nubspotsePubLicAssociationMulti.use nubspottelentier assocraczons modelruo Licoo ecteo,lodel\PuoLicob ectlo• use nubspot cllent crn companzes Apicxcepclon as companyapiexcepclon;use Hubspot Client crm contacts ApiException as contactAp1Exception;use HubSpot\Client\Crm\Deals\Api\BasicApi as DealsBasicApi:use Hubspot clent crm deals Aoi BasicAdi as DealsbasicAo1:use HubSoot cuient crn. Deals ModeSimolePubucobiectwithAssociationsasuse HubSpot\Client\Crm\Deals \Model\5impLePubLicObjectwithAssociations a Click to expandMake this edit to CLientTest.php?7Yes. alllow all edits this session3 NdTall Alaudh what te de tnstnadEsc to cance88 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19918
|
|
19919
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 12 pending changes
12
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
SlackFileEditViewGoHistoryWindowHelpAPP ()DOCKER₴81DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed>Spayload Thesearch payload with filters, sorts, prope* @return array The search response with'results''total'*'paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 @ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lir• 0EDHomeDMsActivityFilesLater..•More→Jiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...^ Direct messagesP. Aneliya Angelova®. Galya Dimitrova. Petko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev. VesE Lukas Kovalik y... O::: AppsS Jira CloudToast100% <78• Mon 11 May 17:12:48Describe what you are looking for# support8 346 0MessagesC FilesBookmarksKara Joneswas added .Tuesday, April 28th~More v+Wednesday, April 29th ~Lauren Hudson 12:58 PMHi team, I'm trying to set up auto detect for LesMills, but when I add a new playbook (because theywant it applied across all teams), it's pulling in a loadof activity types that l am not able to delete. Anyideas please?Screenshot 2026-04-29 at 10.54.42.png •1 reply 12 days agoLauren Hudson 6:17 PMHello, request from Norstella to update theirJiminny to match this shared spreadsheet. lssomebody from the support team able to helpplease?Numbers Document •Message #support+...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19919
|
|
19920
|
Explorer (⇧⌘E)
i Client.ohp g XV APP" services Explorer (⇧⌘E)
i Client.ohp g XV APP" services• Hubspol~OpportunitySynestrategy..• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Wwlallawwaa# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.ohoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn|• FieldTvoeConverter.ohn# HubspotClientinterface.php# HubspotTokenManager.phpR PayloadBuilder.php** PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> Metadata• MiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGi8 JY-20725-handle-HS-search-rate-limit* ©app > Services > Crm › Hubspot › f* Client.php › g Client > parseRetryAfter()class Client extends Baseclient 1mpLements HubspotclientiIntertacepub lic tunction 1sHubspotRateL1m1t Throwable Se : bool123134pub L1c• tunction-parseretryArter(Throwable se):• 1nc1t• method exists se,'getResponseMeaders"))•‹Sheaders =Se->aetResoonseHeaders@-?:-0*$value = $headers ('Retry-After')•?? Sheaders['retry-after')•?? null;$value = $value[0]-??-null;if. (1s numeric(svatue)). +Smessage = strtolower($e->getMessage));it• (sur contains(smessage, ' 'dally ))'1if• (str_contains(Smessage,'ten secondly")) •{• return - 10:if• (str_contains($message, 'secondly')) -{return-1;Sthis->loq->warning(* (Hubspot)•No retry-after header or known message, using default'.•lget_class($e),message" .= Smessage.return.10.public function getMinimumApiVersion(): stringreturn celf.-MTN ApT VERSTON.public function getInstance(): Factorynew ractoryl= Sthis→>accesstoken,'oauth?'''base url => Sthis->baseUruoublic function aetNewinstance: Discovervreturn HubSpot\Factorv::createWithAccessToken/Sthis-saccessToken@6A902|100% LzMon 11 May 17:12:5108 0 0 0* M&I3 Review rate limit handli... XKeview fate lmit nanaling tor nuospouo..<› Client.nhn#62-1681Add coverage of new methods in Client public function search(string $objectType, array Spayload): arrayaren en uunetsion construct linarentaa constructu /Alsers/A mkas/A5im inny/laoo/vendorlauzza lehtit o/lauzza le/src/Excenta on//Request sxcentsion. ohohead STssage, Scode, Sprevious):• Bash Check if Clienttest has tearDown or Mockery cleanuo .qrep -n "tearDownMockery::closeMockeryPHPUnit'/Users/lukas/niminny/app/tests/Unit/Services/crm/Hubspot/ClientTest.php head -10OUT (Bash completed with no output)• Bash Check existina imoorts for APl excentions in Clienttestgrep -n "DealApiException\|ContactApiException\|CompanyApiException\|RateLimitException' /Users/lukas/jiminny/app/tests/Unit/Services/Crm/Hubspot/ClientTest.php | head -10OUT (Bash completed with no output)• Thought for 1s >• Now I have a clear picture. Let me write the new tests. I'll add them to the end of ClientTest.php (before the closing } ), with the necessary imports added at the top• Read ClientTest.phpNow l'lladd the nececcarv imnorts and test methads.• Edit CLientTest.ohoAdded 6 linesuse GuzZleHtto Psr/ Response:use HubSoot\CLient\Crm\Associations\Ani\BatchAoiuse HubSoot\Client\CrmlAssociat.ions|Model BatchInoutPubLic0biectId:use HubSnot\Client\Grm|Accocjationc|Model\RatchRecnoncePublicAccociatjonMulti•use HubSoot\Client\CrmlAssociat.ions|Mode1 BatchInoutPubLic0biectId:use HubSnot\Client\Grm\Accociationc|Model\RatchRecnoncePublicAccocfatjonMulti.use HubSnotlClient\Grm|Accociationc|ModellPublic0hiecttdlnvAniExcention;use Huosoot clent crm deals Ao1 BasicAo1 as DealsBasicAo1:use HubSpot\Client\Crm\Deals\Model\SimplePublic0bjectWithAssociations as+) Crm\DeaLs\Model|SimplePublic0bjectWithAssociations a clickto expandRoonina7 ClientTest.oho#Ask before edit.8 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19920
|
|
19921
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
Client.php 9 xV APP" services• Hubspol~OpportunitySynestrategy..• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Wwlallawwaa# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.ohoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn• FieldTvoeConverter.oho# HubspotClientinterface.php# HubspotTokenManager.phpR PayloadBuilder.php** PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> Metadata• MiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGi8 JY-20725-handle-HS-search-rate-limit* ©app > Services > Crm › Hubspot › f* Client.php › •g Client › parseRetryAfter()class Client extends Baseclient 1mpLements HubspotclientIntertace123134pub lic tunction 1sHubspotRateL1m1t Throwable Se: boolpub L1c• tunction-parseretryArter(Throwable se):• 1nc1t• method exists se,'getResponseMeaders")) •<Sheaders =Se->aetResoonseHeaders@-?:-0*$value = $headers ('Retry-After') -?? Sheaders('retry-after']-?? null;$value = $value[0]-??-null;if. (1s numeric(svatue)). +Smessage = strtolower($e->getMessage));it• (sur contains(smessage, ' 'dally ))'1if• (str_contains(Smessage,'ten secondly")) •1return-10:if• (str_contains($message, 'secondly')) -{return-1;Sthis->loq->warning(* (Hubspot)•No retry-after header or known message, using default'.•lget_class($e),message" .= Smessage.return.10.public function getMinimumApiVersion(): stringreturn celf.-MTN ApT VERSTON.public function getInstance(): Factorynew ractoryl= Sthis→>accesstoken,'oauth?'''base url => Sthis->baseUruoublic function aetNewinstance: Discovervreturn HubSpot\Factorv::createWithAccessToken/Sthis-saccessToken@6A902|‹S0 hh100% LzMon 11 May 17:12:55•2 C3›* Review rate limit handli... X*mA .•Review rate limit handling for HubSpot jo.<› Client.ohn#62-168Add coverage of new methods in Client public function search(string $objectType, array Spayload): arrayouT 30:public function constructparent:: constructSmessage, Scode, Sprevious:• Read RequestException.php• Thouaht for 21s >• Bash Check if ClientTest has tearDown or Mockery cleanurqrep -n "tearDownMockery::closeMockeryPHPUnit"/Users/lukas/iminny/app/tests/Unit/Services/Crm/Hubspot/ClientTest.pp head =10OUT (Bash completed with no output)• Bash Check existina imoorts for APl excentions in ClientTestarep -n "DealApit xception VicontactAp -xceptiion VIcompanyAp -xception VRatelmitxceptilon"/Users/Aukas/#mnny/app//tests/Un t7/Serv ces/crm/Hubspot/clftentiest.oho Thead =lOUT (Bash completed with no output)• Thouaht for 1c >• Now I have a clear picture. Let me write the new tests. I'll add them to the end of ClientTest.php (before the closing ). with the necessary imports added at the top• Read ClientTest.php• Now l'll add the necessary imports and test methods:• Edit GlientTect.nhnuse bubspotCltent CremsAssoe;use HubSpot\Client\Crm\Associations\Model\BatchResponsePublicAssociationMulti:use nubspouse Hubspot clhresponsePub L1cassoc1at1onMult1;use Hubspot client crm assoclations Model Pub Licobi ectlause Hubspot cllent crm assoclations Model Pub Licobi ectla:ouse HubSpot Client Crm Companies ApiException as CompanvApiException:use HubSoot Client Crm Deals Api BasicAni as DealsBasicAoi:ouse HubSpot Client Crm Contacts ApiException as ContactApiException:use HubSoot Client Crm Deals Aoi BasicApi as DealsBasicAoi:ause HubSnotClient|Crml Deal clAn:Excentionlas DealAn:Excentionuse HubSnot\Client\Crm|Dealc|ModellSimnlePublic0biectwithAccociationcacuse HubSnot\Client\Crm|Dealc|Model\SimnlePublic0biectWithAccociationgacl• Now add the new test methods before the closina ? ,* HonkindQueue another meccadoM ClientTest.oh#Ask before edit.8 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19921
|
|
19922
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
FieldTypeConverter.php
HubspotClientInterface.php
HubspotTokenManager.php
PayloadBuilder.php
RemoteCrmObjectManipulator.php
ResponseNormalize.php
Service.php
SyncFieldAction.php
SyncRelatedActivityManager.php
WebhookSyncBatchProcessor.php
IntegrationApp
Listeners
Metadata
Migration
Pipedrive
OpportunitySyncStrategy
ProspectSearchStrategy
ApiFields.php
OpportunitySyncStrategy
Hubspot
Crm
Services
app
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
MySQL Section
MYSQL
MYSQL
MatchActivityCrmData.php, Editor Group 1
RateLimitException.php, Editor Group 1
HandleHubspotRateLimit.php, Editor Group 1
Client.php, Editor Group 1
HubspotPaginationService.php, Editor Group 1
Client.php, Editor Group 1
Review rate limit handli…, Editor Group 2
remote
app (Git) - JY-20725-handle-HS-search-rate-limit*, Checkout Branch/Tag...
JY-20725-handle-HS-search-rate-limit*
app (Git) - Synchronize Changes
Errors: 6, Warnings: 9, Infos: 2
6
9
2
Notifications
key, PHP extension: Premium features not active.
Sign In
Sign In
Diff editor
Clear
Review rate limit handling for HubSpot job queue
Session history
New session
Message actions
RateLimitException.php#9-9
RateLimitException.php#9-9
Reveiw the diff. Mostly
@app/Jobs/Crm/MatchActivityCrmData.php
,
@app/Exceptions/RateLimitException.php
,
@app/Jobs/Middleware/HandleHubspotRateLimit.php
,
@app/Services/Crm/Hubspot/Client.php
and
@app/Services/Crm/Hubspot/Pagination/HubspotPaginationService.php
. The issue is I am trying to make sure that instant spike of MatchActivityCrmData jobs willl handle 429 exceptions from hubspot. Revewi ti carefully and try to see potential issues and bottlenecks. Also RateLimitException was changerd from LogicException to RuntimeException. Is it ok. This exception is used by other paerts of code. Will ti break anything?
Thought for 5s
Thought for 5s
I'll review the implementation carefully. Let me first check how
RateLimitException
is used elsewhere and look at the test files and
PaginationState
.
Bash
Find all usages of RateLimitException outside the changed files
IN
grep -rn "RateLimitException" /Users/lukas/jiminny/app/app --include="*.php" | grep -v "HandleHubspotRateLimit\|MatchActivityCrmData\|Client.php\|RateLimitException.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:13:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
/Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php:17:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php:68: RateLimitException |
/Users/lukas/jiminny/app/app/Component/TranscriptionSummary/Jobs/SummarizeTranscriptionJob.php:15:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/TranscriptionSummary/Jobs/SummarizeTranscriptionJob.php:58: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
/Users/lukas/jiminny/app/app/Component/AiActivityType/Jobs/GenerateAiActivityTypeJob.php:19:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/AiActivityType/Jobs/GenerateAiActivityTypeJob.php:76: RateLimitException |
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/HubspotClientInterface.php:8:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/HubspotClientInterface.php:50: * @throws RateLimitException When rate limit is hit
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/Pagination/HubspotPaginationService.php:195: // RateLimitException and other exceptions are re-thrown as-is
Read
PaginationState.php
PaginationState.php
Read
HandleHubspotRateLimitTest.php
HandleHubspotRateLimitTest.php
Bash
Check how RateLimitException is used in GenerateActionItemsJob
IN
grep -rn "RateLimitException\|LogicException\|RuntimeException" /Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php | head -20
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:13:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
Bash
Find all catch blocks or instanceof checks for RateLimitException
IN
grep -rn "catch.*RateLimitException\|instanceof RateLimitException" /Users/lukas/jiminny/app/app --include="*.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Jobs/Middleware/HandleHubspotRateLimit.php:11: * Job middleware that catches RateLimitException from HubSpot API calls
/Users/lukas/jiminny/app/app/Jobs/Middleware/HandleHubspotRateLimit.php:24: } catch (RateLimitException $e) {
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:149: if (! $e instanceof RateLimitException) {
Bash
Find all test references to RateLimitException
IN
grep -rn "RateLimitException" /Users/lukas/jiminny/app/tests --include="*.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:8:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:13:#[CoversClass(RateLimitException::class)]
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:14:class RateLimitExceptionTest extends TestCase
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:18: $exception = new RateLimitException();
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:28: $exception = new RateLimitException('Hubspot rate limit', 30, $previous);
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:52: $exception = new RateLimitException('test', $input);
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:10:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:49: public function testPropagatesNonRateLimitExceptions(): void
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:103: throw new RateLimitException('rate limited', $retryAfter);
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:150: throw new RateLimitException('rate limited', 1);
Bash
Check retry/failure handling in GenerateActionItemsJob
IN
grep -n "RateLimitException\|retryUntil\|backoff\|maxExceptions\|maxTries\|release\|failed" /Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php | head -30
Copy code to clipboard
OUT
13:use Jiminny\Exceptions\RateLimitException;
51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
56: $this->release(30);
Bash
Check retry/failure handling in GenerateAiCallScoringJob
IN
grep -n "RateLimitException\|retryUntil\|backoff\|maxExceptions\|maxTries\|release\|failed" /Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php | head -30
Copy code to clipboard
OUT
17:use Jiminny\Exceptions\RateLimitException;
68: RateLimitException |
75: $this->release(30);
Bash
Check retry config in MatchActivityCrmData
IN
grep -n "retryAfter\|RETRY_WINDOW\|retryUntil\|maxTries" /Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php
Copy code to clipboard
OUT
34: private const int RETRY_WINDOW_MINUTES = 30;
45: public function retryUntil(): \DateTimeInterface
47: return now()->addMinutes(self::RETRY_WINDOW_MINUTES);
77: return self::RETRY_WINDOW_MINUTES * 60 + 60;
Bash
Check the cache key format
IN
grep -n "getRateLimitCacheKey\|hubspot:ratelimit" /Users/lukas/jiminny/app/app/Services/Crm/Hubspot/Client.php
Copy code to clipboard
OUT
78: $cacheKey = $this->getRateLimitCacheKey();
110: private function getRateLimitCacheKey(): string
112: return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
Bash
Find other jobs that might use the rate limit middleware
IN
grep -rn "class.*Middleware\|HandleHubspotRateLimit" /Users/lukas/jiminny/app/app/Jobs --include="*.php" | grep -v "HandleHubspotRateLimit.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:18:use Jiminny\Jobs\Middleware\HandleHubspotRateLimit;
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:42: return [new HandleHubspotRateLimit()];
Read
HubspotClientInterface.php
HubspotClientInterface.php
Thought for 73s
Thought for 73s
Now I have a complete picture. Here's my full analysis:
Review Summary
Review Summary
RuntimeException vs LogicException — Safe ✓
RuntimeException
vs
LogicException
— Safe ✓
The change is semantically correct and won't break anything.
LogicException
is for programmer errors (invalid arguments, contract violations). A rate limit from an external API is a runtime condition —
RuntimeException
is the right parent. All callers catch
RateLimitException
by name explicitly (union catches in
GenerateActionItemsJob
,
GenerateAiCallScoringJob
,
SummarizeTranscriptionJob
,
GenerateAiActivityTypeJob
) or check
instanceof RateLimitException
— none relies on the parent class type, so nothing breaks.
Issue 1 — Circuit breaker stores stale delay (most important bug)
Issue 1 — Circuit breaker stores stale delay (most important bug)
Client.php:94
Client.php:94
Copy code to clipboard
Redis::setex($cacheKey, $retryAfter, (string) $retryAfter);
The TTL is
$retryAfter
seconds, but the
stored value
is also the original
$retryAfter
. If a second job reads this cache 20 seconds later, it throws
RateLimitException(retryAfter=30)
and gets delayed 30 more seconds — even though only 10 remain. In a spike of 100 jobs, each subsequent job inflates its wait.
Fix:
store the absolute expiry timestamp, reconstruct the remaining delay when reading:
Copy code to clipboard
// on 429:
Redis::setex($cacheKey, $retryAfter, (string) (time() + $retryAfter));
// in the cached-read branch:
$remaining = max(1, (int) $cachedRetryAfter - time());
throw new RateLimitException('Hubspot rate limit (cached circuit-breaker)', $remaining);
Issue 2 — retryUntil() window may expire under sustained rate limiting
Issue 2 —
retryUntil()
window may expire under sustained rate limiting
MatchActivityCrmData.php:45-47
MatchActivityCrmData.php:45-47
retryUntil()
is calculated as
now() + 30 min
at
dispatch time
and stored in the job payload. With
MAX_RETRY_DELAY = 600s
, you only get ~3 rate-limit-triggered releases before the 30-minute window closes and the job is permanently failed. For a heavy 429 spike (daily limit, parsed as 600s), this can easily happen.
Consider increasing
RETRY_WINDOW_MINUTES
to 60 or more, or making it configurable. The
uniqueFor()
value should be updated to match.
Issue 3 — Only search() uses the circuit breaker, but other methods can still hit 429
Issue 3 — Only
search()
uses the circuit breaker, but other methods can still hit 429
Client.php:76-108
Client.php:76-108
executeRequest()
is only called from
search()
. Methods like
getOpportunityById()
,
batchReadObjects()
,
getContactByEmail()
bypass it entirely. If HubSpot's 429 is account-wide (not search-endpoint-specific), those methods will keep firing even while the circuit breaker is supposedly open. This is likely fine because the search endpoint has its own tighter quota (5 RPS), but it's worth being explicit in a comment.
Issue 4 — object $job type in middleware has no compile-time safety
Issue 4 —
object $job
type in middleware has no compile-time safety
HandleHubspotRateLimit.php:20
HandleHubspotRateLimit.php:20
Copy code to clipboard
public function handle(object $job, callable $next): void
Calling
$job->attempts()
and...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19922
|
|
19923
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
selectionViewlerminalWindowm RateLimitException.ohdUsers > lukas › jiminny › app › tests > Unit > Services > Crm > Hubspot › #* ClientTest.php100% L2Mon 11 May 17:13:28EXPLORERV APPV appv Serviceserm• Hubspol~OpportunitySyncStrategy..• HubsnotL astModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....• HubsootSinaleSvncStrategy.onp## HubspotSyncStrategyBase.php# HubsnotWebhookBatchSyncstrateg.V Dadinationi# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy) Dodic~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.phoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho•FieldDefinitions.ohn• FieldTvoeConverter.oho# HubspotClientinterface.php# HubspotTokenManager.php€ DavloadRuilder nhnRemoteCrmObjectManipulator.php«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php• SuncPelatedActivitvManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> Metadata> MigrationV Pipedrive• OpportunitySvncStrateav• ProspectSearchStrateavOUTIINETIMELINGia JY-20725-handle-HS-search-rate-limit* @26A902#Client.oho 9"* Claude Code Clientlest.oho X« HubspotPaginati * % 00 M→ = Review rate limit handli..Review rate limit handling for HubSpot jo...<› Client.nhn#62-1681Add coverage of new methods in Client public function search(string $objectType, array Spayload): array• Now I have a clear picture. Let me write the new tests. I'll add them to the end of ClientTest.php (before the closing } ), with the necessary imports added at the top• Read ClientTest.php• Now l'll add the necessary imports and test methods:• Edit CLientTest.ohouse Guzzlehtto Psrz Response:use HubSoot Cuient Crm Associations Ao1 BatchAoi:use HubSnot Client| Crm Associationc|Mode BatchTnnutPuhlic0hiecttd:use HubSnot\Client|CrnlAçsociations|Model\RatchReçnonsePublicAcsociationMulti•use HubSpot\Client\Crm\Deals\Api\BasicApi as DealsBasicApi;use HubSpot\CLient\Cm\Dea1s Mode1(5imp LePubLicObj ectwithAssociations as• Now add the new test methods before the closing }• Edit ClientTest.phppublic function testRemoveAssociations(): voidSobiectType = 'deals':= 'contacts':inouts' =['from' » ('id' » 'deal1'], 'to' » ['id' = 'contact1']],use Guzzlehtto Psrz Resoonse:use HubSoot Cuient Crn Associations Api BatchApi:use HubSnot.Client.CrmlAssociations.ModeBatchTnnutPuhlic0hiecttdeuse HubSnot\Client\Crm|Açsociations|Mode1\RatchReçnonsePublicAçsociationMulti.HubSpot (C/1ent Crbeats VoESimorus cotieExceptSsoctations a5public function testRemoveAssociations(): voidsobiectlype = "dealssassociat ionivoe"contacts'inouts' =('from' = ('id' = 'deal1'), 'to' = ('id' = 'contact1')),"success':Make this edit to CLientTest.php?1Yes1 Yes. alllow all edits this session3 NoTell Claude what to do insteadEsc to cancel88 SignIn...
|
Code
|
✻ [Claude Code] ClientTest.php (ClientTest.php) — ✻ [Claude Code] ClientTest.php (ClientTest.php) — app...
|
NULL
|
19923
|
|
19924
|
v App~ Opportunity SyncStratey...• HubsnotLastModi v App~ Opportunity SyncStratey...• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php# HubsnotWebhookBatchSyncstrateg.Pagination# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy→Hoal~ Servicelraits#Opportunitysyncirait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• Webhookw BatchSvncCollector.oho# BatchSvncRedisService.ohoCliient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn• FieldTvneConverter.ohn# HubspotClientinterface.php• HubsootTokenManager.onp€ DavloadRuilder nhn# RemoteCrmObjectManipulator.php«* PecnonceNormalize nhnw service.php#R SyncFieldAction.php# SynckelatedActivityManager.php# WebhookSyncBatchProcessor.phpIntearationapo› MetadataHandleHubspotRateLimit.phpClient.php 9* [Claude Codel ClientTest.php X90inny › app › tests › Unit › Services › Crm > Hubspot › « ClientTest.php › 9g ClientTestClienttest extends Testcaseclass Clienttest extends Testcasepub lic tunction testRemoveAssoclations: vo1d1778Sthis->assertSame($expectedResponse, Sresult);$this->assertSame($expectedResponse, Sresult);search() / executeRequest() tests$redisMock = Mockery::mock('alias:Illuminate\Support\Facades\Redis');sredtsmock→>shoulakecervel get→oncel→›andketurhnutehsth1s→>cont10=>method(getid)→>w1llReturn(42);Soavload = 'filters' =>00:Sresponselata = 'results' as Td s 1'r 'total e> 1, nadina' =>athic_shubsnotclientMockSoynocte(sthie soncol))Client::BASE URL . '/crm/v3/obiects/contacts/search'.>willReturn(ShubspotResponse:Sresult = Sthis->client-ssearch/ "contacts'. Snavload).senis->asserrtoane sresponsevata, SresulunMockery::closeGredicMock = Mockerve.mock/laliac,Tlluminatel Sunnortl Facadec) Redict)•Sthis->cont1o->methoddetid") ->w1u Return(42):sthis-shubsnotclentMock-sexnects/Sthic-snevero=smethod/request'schis->expectexcepczonmessacel nuospor race limit (cached circult-oreaker.trysthis->client->search"contacts'.finallyMockerv::closed:PA 1M 20725100% L2Mon 11 May 17:13:31• 2 C→ = Review rate limit handli..Keview fate lmit nanaling for nuospouo..<› Client.nhn#62-1681Add coverage of new methods in Client public tunction search(string sobiectlype, array spayload): array• Now I have a clear picture. Let me write the new tests. I'll add them to the end of ClientTest.php (before the closing } ), with the necessary imports added at the top• Read ClientTest.ohp• Now I'll add the necessary imoorts and test methods:• cait clentrest.phpuse Hubspot Cllent crm Associations Ap1 BatchAp1use Hubsoot cllent crm Associations Mode BatchinoutPub lacoblectid:use HubSpot Client Crm Associations Model BatchResponsePublicAssociat ionMult 1:use Hubsoot cuient Crn Associations Model Publicobiectid:use HubSpot\Client\Crm\Deals\Api\BasicApi as DealsBasicApi;use HubSpot\Client\Crm\ Deals\Model\SimplePublic0biectWithAssociations as• Now add the new test methods before the closing } :• Edit ClientTest.ohopublic function testRemoveAssociations(): void"deals';SassociationType = 'contacts':Spayload =('from' => ('id' => 'deal1'], 'to' => ('id' => 'contact1']].use buzzlencco rsr/ kesponseuse Hubspot Cllent crm assoclations Ap1 BatchAp1;use Hubsoot cllent crm Associations Mode BatchinoutPub lacoblectid:use HubSoot Client Crm Associations Model BatchResponsePuolicAssociationMulti:use HubSoot cuient Crn Associations Model Pubuicobiectildause HubSnot\ Client\ Crml Comnanies AniExcention as ComnanvAniExcention:use HubSpot\Client\ Crm\Deals\Model\SimplePublic0biectWithAssociations aspublic function testRemoveAssociations(): voidSassociationType = 'contacts':spay load =('from' = ['id' => 'deal1'], 'to' = ('id' => 'contact1']].notResnonse(('statust = "succecc'1):Make this edit to CLientTest.php?7Yes. alllow all edits this session3 NoEsc to canceLn 1799, Col 1 Spaces:4 UTF-8 LF PHP 8 SignIn 8.3 P...
|
Code
|
✻ [Claude Code] ClientTest.php (ClientTest.php) — ✻ [Claude Code] ClientTest.php (ClientTest.php) — app...
|
NULL
|
19924
|
|
19925
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php...
|
Code
|
✻ [Claude Code] ClientTest.php (ClientTest.php) — ✻ [Claude Code] ClientTest.php (ClientTest.php) — app...
|
NULL
|
19925
|
|
19926
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
Users > lukas > jiminny › app › tests › Unit › Services > Crm › Hubspot › # ClientTest.php › • ClientTestClient.php 9* [Claude Codel ClientTest.php X12791class Clienttest extends Testcase1864public tunction testSearchReturnsDecodedArrav0nSuccess: vo1d1823t~ Opportunity SyncStratey...• HubsnotLastModified@nenSvncStra.# HubspotLastModifiedSyncStrategy..• HubsootSinaleSvncStrategy.onp## HubspotSyncStrategyBase.php# HubsnotWebhookBatchSyncstrateg.Pagination# HubspotPaginationService.php# PaginationConfig.phpwPaginationstate.phpProspectsearchstrategy#Opportunitysyncirait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• Utils• Webhookw BatchSvncCollector.oho# BatchSvncRedisService.ohoCliient.oho* ClosedDealStagesService.oho* DealFieldsService.oho• DecorateActivitv.oho• FieldDefinitions.ohn• FieldTvneConverter.ohn# HubspotClientinterface.php• HubsootTokenManager.onp€ DavloadRuilder nhn# RemoteCrmObjectManipulator.php*• PecnonceNormalize nhnw service.php# SyncFieldAction.php# SynckelatedActivityManager.phpIntearationADooublie function tectCearchThrowcPatel_imi+FycentionbhenGircuitRreakerdctive/).Stuturerimestamp = (string) (Cime() + 36);SredisMock-sshouldReceive( 'aet'->once@->andReturn(SfutureTimestamo•scnas-contigonecnod getto owetthecurm,42),schis→>nuospocculentmock→>expects schis-never→mechodrequestrsthis→>expectExcention Rateumit-xceot 1on::class)^sthis->expectExceptzon(Rateuemtexceptzonte tasst: (cached circuit-breaker'$this->client->search('contacts', 0);Mockery:: close():public function testSearchThrowsRateLimitExceptionAndSetsNx0nFresh429(): void$redisMock = Mockery::mock('alias:Illuminate\Support\Facades\Redis');Sreasmock»>shoulakecervel ger→oncel→anakecurmnutunsrea1smock→>shou lakeceivel ser')"nuospot.ratelumit.oortal:42',Mockery:: type('string"),'ey' => 11sch1s→>cont10→>mechod( gecla)→>w1llketurn(42);cnsualooalllaetenew BadRequest 'Rate Limit exceeded", 429):-wil1ThrowExcention/ShadRequest)Sthis->expectException(RateLimitException::class):Sthis->expectExceptionMessage('Hubspot returned 429'):trysthis-sclient-ssearch"contacts'. "finally 4Mockerv.closel)SredisMock = Mockerv: :mocklalias: u luminate Sunnort Facades Redis'MYSOLPA 1M 20725100% LzMon 11 May 17:14:04• 2 C→ = Review rate limit handli..Keview fate lmit nanaling for nuospouo..<› Client.nhn#62-1681Add coverage of new methods in Client public tunction search(string sobiectlype, array Spayload): array• Now I have a clear picture. Let me write the new tests. I'll add them to the end of ClientTest.php (before the closing } ), with the necessary imports added at the top• Read Clienttest.ohp• Now I'll add the necessary imoorts and test methods:• cait clentrest.phouse GuzzleHttp\Psr7\Responseuse HubSpot\Client\Crm\Associations\Api\BatchApiuse Hubsoot cllent crm Associations Mode BatchinoutPub lacoblectid:use HubSpot Client Crm Associations Model BatchResponsePublicAssociat ionMult 1:use Hubsnot cuient Crn Associations Model Publicobiectiduse HubSpot\Client\Crm\Deals\Api\BasicApi as DealsBasicApi;use HubSpot\Client\Crm\ Deals\Model\SimplePublic0biectWithAssociations as• Now add the new test methods before the closing } :• Edit ClientTest.ohopublic function testRemoveAssociations(): void'deals';SassociationType = 'contacts':Spayload =('from' => ('id' => 'deal1'], 'to' => ('id' => 'contact1']].rateHubSnotRecnonse/f'status! →Make this edit to CLientTest.php?7Yes. alllow all edits this session3 NdEsc to canceuse buzzlencco rsr/ kesponseuse Hubspot Cllent crm Associations Ap1 BatchAp1;use Hubsoot cllent crm Associations Mode BatchinoutPuo lacoblectid:use HubSoot Client Crm Associations Model BatchResponsePuolicAssociationMulti:use HubSoot cuient Crn Associations Model Publicobiectidause HubSnot\ Client\ Crml Comnanies AniExcention as ComnanvAniExcention:use HubSpot\Client\ Crm\Deals\Model\SimplePublic0biectWithAssociations aspublic function testRemoveAssociations(): voidSassociationType = 'contacts':spay load =('from' = ['id' => 'deal1'], 'to' => ('id' => 'contact1']].notResnonse(('statust = Isuccecs'1):Ln 1799, Col 1 Spaces:4 UTF-8 LF PHP 8 SignIn 8.3 P...
|
Code
|
✻ [Claude Code] ClientTest.php (ClientTest.php) — ✻ [Claude Code] ClientTest.php (ClientTest.php) — app...
|
NULL
|
19926
|
|
19927
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
...
|
Code
|
✻ [Claude Code] ClientTest.php (ClientTest.php) — ✻ [Claude Code] ClientTest.php (ClientTest.php) — app...
|
NULL
|
19927
|
|
19928
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
...
|
Code
|
✻ [Claude Code] ClientTest.php (ClientTest.php) — ✻ [Claude Code] ClientTest.php (ClientTest.php) — app...
|
NULL
|
19928
|
|
19929
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php...
|
Code
|
✻ [Claude Code] ClientTest.php (ClientTest.php) — ✻ [Claude Code] ClientTest.php (ClientTest.php) — app...
|
NULL
|
19929
|
|
19930
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
FieldTypeConverter.php
HubspotClientInterface.php
HubspotTokenManager.php
PayloadBuilder.php
RemoteCrmObjectManipulator.php
ResponseNormalize.php
Service.php
SyncFieldAction.php
SyncRelatedActivityManager.php
WebhookSyncBatchProcessor.php...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19930
|
|
19931
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
SlackFileEditViewGoHistoryWindowHelpAPP ()DOCKERO ₴1DEV (docker)₴2APP (-zsh)-zsh* @param stringSobjectType The objecttype('deals''companies''contacts''cal)* @param array<string, mixed›Spayload Thesearch payload with filters, sorts,propsereturn arrayThesearch response withresults''total''paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors@return array The search response with 'results'*/'total', 'paging' keyspublic function search(string SobjectType, array Spayload): arrayenddiffapp/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diffnnv/ann/ConsolnhoHomeDMsActivityPS-$1Slack$crmService->syncOpportunity('374720564');|if ($i % 25=0 {Sthis->info("Syncingopportunity {$i}");Sthis->info("Matching contact {$i}");ScrmService->syncOpportunity('374720564');ScrmService-›matchByName('Robot');}end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containerimage +Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-dED→Jiminny ...# conrusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-officeNoricnyarmgulure®. Galya Dimitrova L. Petko Kashinski&. Stefka Stoyanovae. Vasil Vasilev&. Nikolay Ivanov(3 Aneliya Angelova, ...Stoyan Tanev. VesE Lukas Kovalik y…..E:: AppsJira Cloud• Toast(abl100% C8• Mon 11 May 17:14:15Describe what you are looking for# support8 34• MessagesC Files• BookmarksKara Joneswas added .Tuesday, April 28th~More v+Wednesday, April 29th ~Lauren Hudson 12:58 PMHi team, I'm trying to set up auto detect for LesMills, but when I add a new playbook (because theywant it applied across all teams), it's pulling in a loadof activity types that l am not able to delete. Anyideas please?1 reply 12 days agoLauren Hudson 6:17 PMHello, request from Norstella to update theirJiminny to match this shared spreadsheet. lssomebody from the support team able to helpplease?Numbers Document -Message #support+Aa...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19931
|
|
19934
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19934
|
|
19935
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
i Client.ohp g XV APP• Hubspol~OpportunitySynestrategy..• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Wwlallawwaa# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.phoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn• FieldTvoeConverter.oho# HubspotClientinterface.php# HubspotTokenManager.phpR PayloadBuilder.php** PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> Metadata• MiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGi8 JY-20725-handle-HS-search-rate-limit* ©@6A9026app > Services > Crm › Hubspot › f* Client.php › °g Client › parseRetryAfter ()class Client extends Baseclient 1mpLements Hubspotclientintertace123pub lic tunction 1sHubspotRateL1m1t Throwable se: bool137pub L1c• tunction-parseretryArter(Throwable se):• 1nc1t• method exists se,'getResponseMeaders"))•‹Sheaders =Se->aetResoonseHeaderso-?:-0*$value = $headers ('Retry-After')•?? Sheaders['retry-after')•?? null;$value = $value [0] •22-null;if. (1s numeric(svatue)). +Smessage = strtolower($e->getMessage));it• (sur contains(smessage, ' 'dally ))'1if• (str_contains(Smessage,'ten secondly")) •1return-10:if• (str_contains($message, 'secondly')) -{return-1;Sthis->loq->warning(* (Hubspot)•No retry-after header or known message, using default'.•lget_class($e),message" .= Smessage.return.10.public function getMinimumApiVersion(): stringreturn celf.-MTN ApT VERSTON.public function getInstance(): Factorynew ractoryl= Sthis→>accesstoken,'oauth?'''base url => Sthis->baseUruoublic function aetNewinstance: Discovervreturn HubSpot\Factorv::createWithAccessToken/Sthis-saccessToken100% LzMon 11 May 17:14:22* m&• 2 C3 Review rate limit handli... XKeview fate lmit nanaling tor nuospouo..<› Client.nhn#62-1681Add coverage of new methods in Client public function search(string $objectType, array Spayload): arrayOUT (Bash completed with no output)• Thought for 1s >• Now I have a clear picture. Let me write the new tests. I'll add them to the end of ClientTest.php (before the closing } ), with the necessary imports added at the top• Read ClientTest.php• Now l'll add the necessary imports and test methods:• Edit ClientTest.phpuse Guzzbet(pent7CPmAssoclations V/Api BatchApi;use HubSnot|Glient\Grm\Accociationc|Model\RatchTnnutPublic0hiecttdeuse HubSpot\Client\Crm\Associations\Model\BatchResponsePublicAssociationMulti;use GuzzleHttol Psr7l Response:use HubSnotlGlient\Grm|Accociationc|Model\RatchTnnutPuhlic0hiecttdeuse HubSpot\Client\Crm\Associations\Model\BatchResponsePublicAssociationMulti;use HubSpot\Client\Crm\Deals\Api\BasicApi as DealsBasicApi;use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations asHubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations as• Now add the new test methods oetore the closina .• Edit ClientTest.phppublic function testRemoveAssociations(): voidpublic function testRemoveAssociations(): voidSobnecttype ="deals"SassociatiionTvoe = 'contacts':Spavload ="innutc! = [Sobnecttype = "deals'SassociationTvoe =Spavload ="inouts! =f['from' => ['id' => 'deal1'], 'to' => ['id' => 'contact1']],['from' => ['id' => 'deal1'], 'to' => ['id' => 'contact1']],thintina* Crunching….(9 107 lines selectedAsk before edit.88 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19935
|
|
19995
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G)
Client.php 9 xV APP" services• Hubspol~OpportunitySynestrategy.• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Wwlallawwaa# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.ohoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn|• FieldTvoeConverter.ohn# HubspotClientinterface.php# HubspotTokenManager.phpR PayloadBuilder.php€ PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> Metadata• MiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGi8 JY-20725-handle-HS-search-rate-limit* ©app > Services > Crm › Hubspot › f* Client.php › °g Client › parseRetryAfter ()class Client extends Baseclient 1mpLements Hubspotclientintertace123pub lic tunction 1sHubspotRateL1m1t Throwable Se : bool137pubd L1c• tunction-parseretryArter(Tnrowable se): •1nc1t• method exists se,'getResponseMeaders"))•‹Sheaders =Se->aetResoonseHeaderso-?:-0*$value = $headers ('Retry-After')•?? Sheaders['retry-after')•?? null;$value = $value [0] •22-null;if. (1s numeric(svatue)). +Smessage = strtolower($e->getMessage));it• (sur contains(smessage, ' dally y)'1if• (str_contains(Smessage,'ten secondly")) •1• return - 10:if• (str_contains($message, 'secondly')) -{return-1;Sthis->loq->warning(* (Hubspot)•No retry-after header or known message, using default'.-[get_class($e),message" .= Smessage.return.10.public function getMinimumApiVersion(): stringreturn celf.-MtN ApT VERSTON•public function getInstance(): Factorynew ractoryl= Sthis→>accesstoken,'oauth?"base url => sthis->baseUruoublic function aetNewinstance: Discovervreturn HubSpot\Factorv::createWithAccessToken/Sthis-saccessToken@6A9026• 2 C→ Review rate limit handli... XReview rate limit handling for HubSpot jo..<› Client.nhn#62-169Add coverage of new methods in Client public function search(string $objectType, array Spayload): array< 40 hl100% Lz• Mon 11 May 17:16:0408000*0&.• Read Response.php (lines 101-130)• Thouaht for Os ›•Bach Sind aetDataFromPesnonse in HubsnotResnonsearep -n "aetDataFromResoponse" /Users/lukas/iiminny/aop/vendor/hubspot/hubspot-oho/src/Htto/Response.ohoOUT 25private function getDataFromReseInterface Gresnonse'• Read Response.oho (lines 380-399)• Bash Check PHPUnit bootstrap contigurationgrep -n "bootstrap\|bootstrap" /Users/lukas/jiminny/app/phpunit.xml 2>/dev/null | head -5 || cat /Users/lukas/jiminny/app/phpunit.xml | head -20AKohOun tXM INSHXST EATETOR IMNMAWAHO EOT20OVAXMIS ChEMASInSiTanCelXST laNo NamesOAces ChemalLo cataIon=lhTatOSA ls Chema-ohoun EaderAeASYhoun taXcdl hoo tsi tranE"vendor auto oadHoholcol loEsET• Thouaht for 3s ;• Good — the bootstran is iust Comooser's autoloader. no Laravel bootstrannina. Now let's run the new tests;• Bash Run the new ClientTest methodsIN php vendor/bin/phpunit tests/Unit/Services/Crm/Hubspot/ClientTest.php -filter="testSearch|testIsHubspotRateLimit|testParseRetryAfter" --n0-coverage 2>&1 | tail -50Run the new ClientTest methods1 ves7 Yes, alllow oho vendorlbin/oh.... for alll oroiects3 NoTell Claude what to do insteadEsc to cancel8 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19995
|
|
19996
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G)
Run and Debug (⇧⌘D)
Remote Explorer
SlackFileEditViewGoHistoryWindowHelpAPP ()DOCKER₴81DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed>Spayload Thesearch payload with filters, sorts, prop‹* @return array The search response with'results''total''paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 @ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lir• 0EDHomeDMsActivityFilesLater...More→Jiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...• Direct messages®. Aneliya Angelova®. Galya DimitrovaPetko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev• VesE Lukas Kovalik y... 0::: AppsS Jira CloudToast(abl100% <78• Mon 11 May 17:16:05Describe what you are looking for# releases8 226 0MessagesC Files• Bookmarkslo Puonicumihailmihaylovjir]Today ~4ff69be1 - JY-17836: Handle non-botactivitiesaf953504 - Merge pull request #12067 fromjiminny/JY-17836-participant-speeches-hotfixjiminny/app Added by GitHubGitHub APP 5:10 PM13 new commits pushed to master by ilian-jiminny9353b609 - JY-20395 wipbee402b7 - JY-20395 Stop fetching ALLheaders (including file) for email importd6a0fe5a - JY-20395 lintdaa0373e - JY-20395 lint fixesaf59d609 - JY-20395 Removed no longer usedmethodsShow morejiminny/app | Added by GitHubCircleCl APP 5:11 PMDeployment Successful!Project: appWhen:05/11/202614:11:35Tag:View JobMessage #releases..•...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19996
|
|
19997
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Client.php 9 xV APPapp > Services > Crm › Hubspot › f* Client.php › °g Client › parseRetryAfter ()class Client extends Baseclient 1mpLements Hubspotclientintertace123pub lic tunction 1sHubspotRateL1m1t Throwable Se : bool137• Hubspol~OpportunitySynestrategy.• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Wwlallawwaa# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.ohoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn|• FieldTvoeConverter.ohn# HubspotClientinterface.php# HubspotTokenManager.phpR PayloadBuilder.php€ PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> Metadata• MiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGi8 JY-20725-handle-HS-search-rate-limit* ©pubd L1c• tunction-parseretryArter(Tnrowable se): •1nc1t• method exists se,'getResponseMeaders"))•‹Sheaders =Se->aetResoonseHeaderso-?:-0*$value = $headers ('Retry-After')•?? Sheaders['retry-after')•?? null;$value = $value [0] •22-null;if. (1s numeric(svatue)). +Smessage = strtolower($e->getMessage));it• (sur contains(smessage, ' dally y)'1if• (str_contains(Smessage,'ten secondly")) •1return-10:if• (str_contains($message, 'secondly')) -{return-1;Sthis->loq->warning(* (Hubspot)•No retry-after header or known message, using default'.-[get_class($e),message" .= Smessage.return.10.public function getMinimumApiVersion(): stringreturn celf.-MtN ApT VERSTON•public function getInstance(): Factorynew ractoryl= Sthis→>accesstoken,'oauth?"base url => sthis->baseUruoublic function aetNewinstance: Discovervreturn HubSpot\Factorv::createWithAccessToken/Sthis-saccessToken@6A9026• 2 C→ Review rate limit handli... XReview rate limit handling for HubSpot jo..<› Client.nhn#62-169Add coverage of new methods in Client public function search(string $objectType, array Spayload): array< 40 hl100% Lz• Mon 11 May 17:16:0808000*0&.• Read Response.php• Read Response.php (lines 101-130)• Thouaht for Os ›•Bach Sind aetDataFromPesnonse in HubsnotResnonsearep -n "aetDataFromResoponse" /Users/lukas/iiminny/aop/vendor/hubspot/hubspot-oho/src/Htto/Response.ohoOUT 25private function getDataFromReseInterface Gresnonse'• Read Response.oho (lines 380-399)• Bash Check PHPUnit bootstrap contigurationgrep -n "bootstrap\|bootstrap" /Users/lukas/jiminny/app/phpunit.xml 2>/dev/null | head -5 || cat /Users/lukas/jiminny/app/phpunit.xml | head -20AKohOun tXM INSHXST EATETOR IMNMAWAHO EOT20OVAXMIS ChEMASInSiTanCelXST laNo NamesOAces ChemalLo cataIon=lhTatOSA ls Chema-ohoun EaderAeASYhoun taXcdl hoo tsi tranE"vendor auto oadHoholcol loEsET• Thouaht for 3s ;• Good — the bootstran is iust Comooser's autoloader. no Laravel bootstrannina. Now let's run the new tests;• Bash Run the new ClientTest methodsIN php vendor/bin/phpunit tests/Unit/Services/Crm/Hubspot/ClientTest.php -filter="testSearch|testIsHubspotRateLimit|testParseRetryAfter" --n0-coverage 2>&1 | tail -50Run the new ClientTest methods11 Yes7 Yes, alllow oho vendorlbin/oh.... for alll oroiects3 NoTell Claude what to do insteadEsc to cancel8 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19997
|
|
19998
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19998
|
|
19999
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
...
|
Code
|
Review rate limit handli… — app
|
NULL
|
19999
|
|
20000
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20000
|
|
20001
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
SlackFileEditViewGoHistoryWindowHelpAPP ()DOCKER- ₴81DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed>Spayload Thesearch payload with filters, sorts, prop‹* @return array The search response with'results''total''paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 @ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lir• 0EDHomeDMsActivityFilesLater...More→Jiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...^ Direct messagesP. Aneliya Angelova®. Galya DimitrovaPetko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev• VesE Lukas Kovalik y... 0::: AppsS Jira CloudToast(abl100% <78• Mon 11 May 17:16:18Describe what you are looking for# releases8 226 0MessagesC Files• Bookmarkso Puonicumihailmihaylovjir]Today ~4ff69be1 - JY-17836: Handle non-botactivitiesaf953504 - Merge pull request #12067 fromjiminny/JY-17836-participant-speeches-hotfixjiminny/app Added by GitHubGitHub APP 5:10 PM13 new commits pushed to master by ilian-jiminny9353b609 - JY-20395 wipbee402b7 - JY-20395 Stop fetching ALLheaders (including file) for email importd6a0fe5a - JY-20395 lintdaa0373e - JY-20395 lint fixesaf59d609 - JY-20395 Removed no longer usedmethodsShow morejiminny/app | Added by GitHubCircleCl APP 5:11 PMDeployment Successful!Project: appWhen:05/11/202614:11:35Tag:View JobMessage #releases..•...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20001
|
|
20002
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
Client.php 9 xV APPapp > Services > Crm › Hubspot › f* Client.php › °g Client › parseRetryAfter ()class Client extends Baseclient 1mpLements Hubspotclientintertace123pub lic tunction 1sHubspotRateL1m1t Throwable Se : bool137• Hubspol~OpportunitySynestrategy..• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Wwlallawwaa# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.phoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho• FieldDefinitions.ohn• FieldTvoeConverter.oho# HubspotClientinterface.php# HubspotTokenManager.phpR PayloadBuilder.php€ PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> Metadata• MiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGi8 JY-20725-handle-HS-search-rate-limit* ©pubd L1c• tunction-parseretryArter(Tnrowable se): •1nc1t• method exists se,'getResponseMeaders"))•‹Sheaders =Se->aetResoonseHeaderso-?:-0*$value = $headers ('Retry-After')•?? Sheaders['retry-after')•?? null;$value = $value [0] •22-null;if. (1s numeric(svatue)). +Smessage = strtolower($e->getMessage));it• (sur contains(smessage, ' dally y)'1if• (str_contains(Smessage,'ten secondly")) •1return-10:if• (str_contains($message, 'secondly')) -{return-1;Sthis->loq->warning(* (Hubspot)•No retry-after header or known message, using default'..lget_class($e),message" .= Smessage.return.10.public function getMinimumApiVersion(): stringreturn celf.-MtN ApT VERSTON•public function getInstance(): Factorynew ractoryl= Sthis→>accesstoken,'oauth?'''base url => Sthis->baseUruoublic function aetNewinstance: Discovervreturn HubSpot\Factorv::createWithAccessToken/Sthis-saccessToken@6A9026S0 h100% LzP• Mon 11 May 17:16:18• 2 C0 000→ Review rate limit handli... X*mA .•Review rate limit handling for HubSpot jo.<› Client.nhn#62-169Add coverage of new methods in Client public function search(string $objectType, array Spayload): array25:private function detDataFromResponse ResponseInterface Sresponse• Read Response.pho (lines 380-399)• Bash Check PHPUnit bootstrap configurationgrep -n "bootstrap\|bootstrap" /Users/lukas/jiminny/app/phpunit.xml 2>/dev/null | head -5 || cat /Users/lukas/jiminny/app/phpunit.xml | head -20OUT 2:<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema—instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="t• Thouaht for 3s›• Good — the bootstrao is iust Comooser's autoloader. no Laravel bootstrabpina. Now let's run the new tests-• Bash Run the new ClientTest methodsIN php vendor/bin/phpunit tests/Unit/Services/Crm/Hubspot/ClientTest.php -filter="testSearch|testIsHubspotRateLimit|testParseRetryAfter" --no-coverage 2>&1 | tail -50OUT (eval):1: command not found: oho• Bash Run the new ClientTest methods with php8.2IN php8.2 vendor/bin/phpunit tests/Unit/Services/Crm/Hubspot/ClientTest.php -filter="testSearch|testIsHubspotRateLimit|testParseRetryAfter" --no-coverage 2>81 | tail -60OUT (eval):1: command not found: oho8.2• Bash Find PHP binarvIN which php && php --version 2>&1Allow this bash command?which pho && pho --version 2>61lFind PHP binary2 Yes. allow ohn --version for all proiects3 NdTell Claude what to do insteadEsc to cancel8 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20002
|
|
20004
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20004
|
|
20005
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20005
|
|
20006
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
FieldTypeConverter.php
HubspotClientInterface.php
HubspotTokenManager.php
PayloadBuilder.php
RemoteCrmObjectManipulator.php
ResponseNormalize.php
Service.php
SyncFieldAction.php
SyncRelatedActivityManager.php
WebhookSyncBatchProcessor.php
IntegrationApp
Listeners
Metadata
Migration
Pipedrive
OpportunitySyncStrategy
ProspectSearchStrategy
ApiFields.php
OpportunitySyncStrategy
Hubspot
Crm
Services
app
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
MySQL Section
MYSQL
MYSQL
MatchActivityCrmData.php, Editor Group 1
RateLimitException.php, Editor Group 1
HandleHubspotRateLimit.php, Editor Group 1
Client.php, Editor Group 1
HubspotPaginationService.php, Editor Group 1
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm\Hubspot;
use HubSpot\Client\Crm\Deals\ApiException as DealApiException;
use HubSpot\Client\Crm\Contacts\ApiException as ContactApiException;
use HubSpot\Client\Crm\Companies\ApiException as CompanyApiException;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations as ContactsWithAssociations;
use HubSpot\Client\Crm\Companies\Model\SimplePublicObjectWithAssociations as CompaniesWithAssociations;
use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations as DealWithAssociations;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectInput;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectWithAssociations as ObjectWithAssociations;
use HubSpot\Client\Crm\Pipelines\Model\Error;
use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;
use HubSpot\Client\Crm\Properties\Model\Property;
use HubSpot\Discovery\Discovery;
use Jiminny\Exceptions\CrmException;
use Jiminny\Exceptions\RateLimitException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Jobs\Crm\NoteObject;
use Jiminny\Models\Crm\Field;
use Jiminny\Services\Crm\BaseClient;
use Jiminny\Services\Crm\Hubspot\DTO\Response\Owner;
use Jiminny\Services\SocialAccountService;
use SevenShores\Hubspot\Exceptions\BadRequest;
use SevenShores\Hubspot\Exceptions\HubspotException;
use SevenShores\Hubspot\Factory;
use SevenShores\Hubspot\Http\Response;
use Jiminny\Services\Crm\Hubspot\Pagination\HubspotPaginationService;
use Illuminate\Support\Facades\Redis;
use Throwable;
/**
* @phpstan-type CrmFieldOption array{id:string, label:string, value?:string}
*/
class Client extends BaseClient implements HubspotClientInterface
{
public const string MIN_API_VERSION = '2';
public const string BASE_URL = '[URL_WITH_CREDENTIALS] T
*
* @param callable(): T $apiCall The API call to execute
*
* @throws RateLimitException When rate limit is hit or cached rate limit is active
*
* @return T The result of the API call
*/
private function executeRequest(callable $apiCall)
{
$cacheKey = $this->getRateLimitCacheKey();
$cachedExpiresAt = Redis::get($cacheKey);
if (is_string($cachedExpiresAt) && is_numeric($cachedExpiresAt)) {
$remaining = max(1, (int) $cachedExpiresAt - time());
throw new RateLimitException(
'Hubspot rate limit (cached circuit-breaker)',
$remaining,
);
}
try {
return $apiCall();
} catch (Throwable $e) {
if ($this->isHubspotRateLimit($e)) {
$retryAfter = $this->parseRetryAfter($e);
// NX: only the first job to receive a 429 in this burst sets the key.
// Subsequent 429s in the same burst leave the TTL untouched so the
// window is not reset by every concurrent job hitting the limit.
Redis::set($cacheKey, (string) (time() + $retryAfter), ['nx', 'ex' => $retryAfter]);
$this->log->warning('[Hubspot] Received 429 from API', [
'team_id' => $this->config->team_id,
'config_id' => $this->config->getId(),
'retry_after' => $retryAfter,
'reason' => $e->getMessage(),
]);
throw new RateLimitException('Hubspot returned 429', $retryAfter, $e);
}
throw $e;
}
}
private function getRateLimitCacheKey(): string
{
return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
}
public function isHubspotRateLimit(Throwable $e): bool
{
if ($e instanceof BadRequest
|| $e instanceof DealApiException
|| $e instanceof ContactApiException
|| $e instanceof CompanyApiException
|| $e instanceof \GuzzleHttp\Exception\RequestException
) {
return (int) $e->getCode() === 429;
}
return false;
}
public function parseRetryAfter(Throwable $e): int
{
if (method_exists($e, 'getResponseHeaders')) {
$headers = $e->getResponseHeaders() ?: [];
$value = $headers['Retry-After'] ?? $headers['retry-after'] ?? null;
if (is_array($value)) {
$value = $value[0] ?? null;
}
if (is_numeric($value)) {
return (int) $value;
}
}
$message = strtolower($e->getMessage());
if (str_contains($message, 'daily')) {
return 600;
}
if (str_contains($message, 'ten secondly')) {
return 10;
}
if (str_contains($message, 'secondly')) {
return 1;
}
$this->log->warning('[Hubspot] No retry-after header or known message, using default', [
'exception_class' => get_class($e),
'message' => $message,
]);
return 10;
}
public function getMinimumApiVersion(): string
{
return self::MIN_API_VERSION;
}
public function getInstance(): Factory
{
return new Factory([
'key' => $this->accessToken,
'oauth2' => true,
'base_url' => $this->baseUrl,
]);
}
public function getNewInstance(): Discovery
{
return \HubSpot\Factory::createWithAccessToken($this->accessToken);
}
/**
* Secondly and daily limits for Hubspot API
*
* Product Tier: Free & Starter | Professional & Enterprise | API add-on (any tier)
* Burst: 100/10 seconds | 150/10 seconds | 200/10 seconds
* Daily: 250,000 | 500,000 | 1,000,000
*
* Official documentation states: The search endpoints are rate limited to five requests per second.
* Since with 5 RPS were still hitting secondly rate limits we lowered it to 4
*/
public function getPaginatedData(array $payload, string $type, int $offset = 0): array
{
$total = 0;
$lastId = null;
$rows = [];
foreach ($this->getPaginatedDataGenerator($payload, $type, $offset, $total, $lastId) as $row) {
$rows[] = $row;
}
return ['results' => $rows, 'total' => $total, 'last_record' => $lastId];
}
/**
* @throws HubspotException
* @throws SocialAccountTokenInvalidException
* @throws BadRequest
*/
public function getPaginatedDataGenerator(
array $payload,
string $type,
int $offset = 0,
int &$total = 0,
?string &$lastRecordId = null
): \Generator {
return $this->paginationService->getPaginatedDataGenerator(
$this,
$payload,
$type,
$offset,
$total,
$lastRecordId
);
}
/**
* Execute a search request against HubSpot CRM objects with rate limiting.
*
* @param string $objectType The object type ('deals', 'companies', 'contacts', 'calls')
* @param array<string, mixed> $payload The search payload with filters, sorts, properties, etc.
*
* @throws RateLimitException When rate limit is hit
* @throws HubspotException On API errors
*
* @return array The search response with 'results', 'total', 'paging' keys
*/
public function search(string $objectType, array $payload): array
{
$endpoint = self::BASE_URL . "/crm/v3/objects/{$objectType}/search";
return $this->executeRequest(function () use ($endpoint, $payload) {
$response = $this->getInstance()->getClient()->request('POST', $endpoint, ['json' => $payload]);
return $response->toArray();
});
}
/**
* @throws DealApiException
* @throws CrmException
*/
public function getOpportunityById(string $crmId, array $fields): array
{
try {
$deal = $this->getNewInstance()->crm()->deals()->basicApi()->getById(
$crmId,
implode(',', $fields),
'companies,contacts'
);
} catch (DealApiException $e) {
$this->log->info('[Hubspot] Failed to fetch opportunity', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $deal instanceof DealWithAssociations) {
throw new CrmException('Deal not found');
}
return [
'id' => $deal->getId(),
'properties' => $deal->getProperties(),
'associations' => $deal->getAssociations(),
];
}
/**
* Generic batch read method for HubSpot objects
*
* @param string $objectType The object type ('deals', 'companies', 'contacts')
* @param array<string> $crmIds Array of HubSpot object IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with object data
*/
private function batchReadObjects(string $objectType, array $crmIds, array $fields): array
{
if (empty($crmIds)) {
return [];
}
$this->validateBatchSize($objectType, $crmIds);
$this->ensureValidToken();
try {
$batchConfig = $this->createBatchConfiguration($objectType);
$batchReadRequest = $this->prepareBatchRequest($batchConfig, $crmIds, $fields);
$response = $batchConfig['api']->read($batchReadRequest);
$this->validateApiResponse($response, $objectType);
$results = $this->processApiResults($response);
$this->logBatchResults($objectType, $crmIds, $results);
return $results;
} catch (\Throwable $e) {
$this->handleBatchError($e, $objectType, $crmIds);
}
}
private function validateBatchSize(string $objectType, array $crmIds): void
{
if (count($crmIds) > 100) {
throw new \InvalidArgumentException("Batch size cannot exceed 100 {$objectType}");
}
}
private function createBatchConfiguration(string $objectType): array
{
$configurations = [
'deals' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Deals\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Deals\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->deals()->batchApi(),
],
'companies' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Companies\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Companies\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->companies()->batchApi(),
],
'contacts' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Contacts\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->contacts()->batchApi(),
],
];
if (! isset($configurations[$objectType])) {
throw new \InvalidArgumentException("Unsupported object type: {$objectType}");
}
return $configurations[$objectType];
}
private function prepareBatchRequest(array $batchConfig, array $crmIds, array $fields): object
{
$batchReadRequest = $batchConfig['batchReadRequest'];
$inputClass = $batchConfig['inputClass'];
$inputs = array_map(function ($crmId) use ($inputClass) {
$input = new $inputClass();
$input->setId($crmId);
return $input;
}, $crmIds);
$batchReadRequest->setInputs($inputs);
$batchReadRequest->setProperties($fields);
return $batchReadRequest;
}
private function validateApiResponse($response, string $objectType): void
{
if (! $response) {
throw new CrmException("HubSpot API returned null response for {$objectType} batch read");
}
}
private function processApiResults($response): array
{
$results = [];
$responseResults = $response->getResults();
if ($responseResults) {
foreach ($responseResults as $object) {
if ($object && $object->getId()) {
$results[$object->getId()] = [
'id' => $object->getId(),
'properties' => $object->getProperties() ?: [],
];
}
}
}
return $results;
}
private function logBatchResults(string $objectType, array $crmIds, array $results): void
{
$this->log->info("[HubSpot] Batch fetched {$objectType}", [
'requested_count' => count($crmIds),
'returned_count' => count($results),
'crm_ids' => $crmIds,
]);
}
private function handleBatchError(\Throwable $e, string $objectType, array $crmIds): void
{
$errorMessage = $e->getMessage() ?: 'Unknown error';
$errorTrace = $e->getTraceAsString() ?: 'No trace available';
$this->log->error("[HubSpot] Failed to batch fetch {$objectType}", [
'crm_ids' => $crmIds,
'error' => $errorMessage,
'trace' => $errorTrace,
]);
throw new CrmException("Failed to batch fetch {$objectType}: " . $errorMessage);
}
/**
* Batch read multiple opportunities by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot deal IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with opportunity data
*/
public function getOpportunitiesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('deals', $crmIds, $fields);
}
/**
* Batch read multiple companies by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot company IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with company data
*/
public function getCompaniesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('companies', $crmIds, $fields);
}
/**
* Batch read multiple contacts by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot contact IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with contact data
*/
public function getContactsByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('contacts', $crmIds, $fields);
}
/**
* @throws CompanyApiException
* @throws CrmException
*/
public function getAccountById(string $crmId, array $fields): array
{
try {
$company = $this->getNewInstance()->crm()->companies()->basicApi()->getById(
$crmId,
implode(',', $fields),
);
} catch (CompanyApiException $e) {
$this->log->info('[Hubspot] Failed to fetch account', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $company instanceof CompaniesWithAssociations) {
throw new CrmException('Account not found');
}
return [
'id' => $company->getId(),
'properties' => $company->getProperties(),
];
}
/**
* @throws ContactApiException
* @throws CrmException
*/
public function getContactById(string $crmId, array $fields): array
{
try {
$contact = $this->getNewInstance()->crm()->contacts()->basicApi()->getById(
$crmId,
implode(',', $fields)
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm\Hubspot;
use HubSpot\Client\Crm\Deals\ApiException as DealApiException;
use HubSpot\Client\Crm\Contacts\ApiException as ContactApiException;
use HubSpot\Client\Crm\Companies\ApiException as CompanyApiException;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations as ContactsWithAssociations;
use HubSpot\Client\Crm\Companies\Model\SimplePublicObjectWithAssociations as CompaniesWithAssociations;
use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations as DealWithAssociations;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectInput;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectWithAssociations as ObjectWithAssociations;
use HubSpot\Client\Crm\Pipelines\Model\Error;
use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;
use HubSpot\Client\Crm\Properties\Model\Property;
use HubSpot\Discovery\Discovery;
use Jiminny\Exceptions\CrmException;
use Jiminny\Exceptions\RateLimitException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Jobs\Crm\NoteObject;
use Jiminny\Models\Crm\Field;
use Jiminny\Services\Crm\BaseClient;
use Jiminny\Services\Crm\Hubspot\DTO\Response\Owner;
use Jiminny\Services\SocialAccountService;
use SevenShores\Hubspot\Exceptions\BadRequest;
use SevenShores\Hubspot\Exceptions\HubspotException;
use SevenShores\Hubspot\Factory;
use SevenShores\Hubspot\Http\Response;
use Jiminny\Services\Crm\Hubspot\Pagination\HubspotPaginationService;
use Illuminate\Support\Facades\Redis;
use Throwable;
/**
* @phpstan-type CrmFieldOption array{id:string, label:string, value?:string}
*/
class Client extends BaseClient implements HubspotClientInterface
{
public const string MIN_API_VERSION = '2';
public const string BASE_URL = '[URL_WITH_CREDENTIALS] T
*
* @param callable(): T $apiCall The API call to execute
*
* @throws RateLimitException When rate limit is hit or cached rate limit is active
*
* @return T The result of the API call
*/
private function executeRequest(callable $apiCall)
{
$cacheKey = $this->getRateLimitCacheKey();
$cachedExpiresAt = Redis::get($cacheKey);
if (is_string($cachedExpiresAt) && is_numeric($cachedExpiresAt)) {
$remaining = max(1, (int) $cachedExpiresAt - time());
throw new RateLimitException(
'Hubspot rate limit (cached circuit-breaker)',
$remaining,
);
}
try {
return $apiCall();
} catch (Throwable $e) {
if ($this->isHubspotRateLimit($e)) {
$retryAfter = $this->parseRetryAfter($e);
// NX: only the first job to receive a 429 in this burst sets the key.
// Subsequent 429s in the same burst leave the TTL untouched so the
// window is not reset by every concurrent job hitting the limit.
Redis::set($cacheKey, (string) (time() + $retryAfter), ['nx', 'ex' => $retryAfter]);
$this->log->warning('[Hubspot] Received 429 from API', [
'team_id' => $this->config->team_id,
'config_id' => $this->config->getId(),
'retry_after' => $retryAfter,
'reason' => $e->getMessage(),
]);
throw new RateLimitException('Hubspot returned 429', $retryAfter, $e);
}
throw $e;
}
}
private function getRateLimitCacheKey(): string
{
return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
}
public function isHubspotRateLimit(Throwable $e): bool
{
if ($e instanceof BadRequest
|| $e instanceof DealApiException
|| $e instanceof ContactApiException
|| $e instanceof CompanyApiException
|| $e instanceof \GuzzleHttp\Exception\RequestException
) {
return (int) $e->getCode() === 429;
}
return false;
}
public function parseRetryAfter(Throwable $e): int
{
if (method_exists($e, 'getResponseHeaders')) {
$headers = $e->getResponseHeaders() ?: [];
$value = $headers['Retry-After'] ?? $headers['retry-after'] ?? null;
if (is_array($value)) {
$value = $value[0] ?? null;
}
if (is_numeric($value)) {
return (int) $value;
}
}
$message = strtolower($e->getMessage());
if (str_contains($message, 'daily')) {
return 600;
}
if (str_contains($message, 'ten secondly')) {
return 10;
}
if (str_contains($message, 'secondly')) {
return 1;
}
$this->log->warning('[Hubspot] No retry-after header or known message, using default', [
'exception_class' => get_class($e),
'message' => $message,
]);
return 10;
}
public function getMinimumApiVersion(): string
{
return self::MIN_API_VERSION;
}
public function getInstance(): Factory
{
return new Factory([
'key' => $this->accessToken,
'oauth2' => true,
'base_url' => $this->baseUrl,
]);
}
public function getNewInstance(): Discovery
{
return \HubSpot\Factory::createWithAccessToken($this->accessToken);
}
/**
* Secondly and daily limits for Hubspot API
*
* Product Tier: Free & Starter | Professional & Enterprise | API add-on (any tier)
* Burst: 100/10 seconds | 150/10 seconds | 200/10 seconds
* Daily: 250,000 | 500,000 | 1,000,000
*
* Official documentation states: The search endpoints are rate limited to five requests per second.
* Since with 5 RPS were still hitting secondly rate limits we lowered it to 4
*/
public function getPaginatedData(array $payload, string $type, int $offset = 0): array
{
$total = 0;
$lastId = null;
$rows = [];
foreach ($this->getPaginatedDataGenerator($payload, $type, $offset, $total, $lastId) as $row) {
$rows[] = $row;
}
return ['results' => $rows, 'total' => $total, 'last_record' => $lastId];
}
/**
* @throws HubspotException
* @throws SocialAccountTokenInvalidException
* @throws BadRequest
*/
public function getPaginatedDataGenerator(
array $payload,
string $type,
int $offset = 0,
int &$total = 0,
?string &$lastRecordId = null
): \Generator {
return $this->paginationService->getPaginatedDataGenerator(
$this,
$payload,
$type,
$offset,
$total,
$lastRecordId
);
}
/**
* Execute a search request against HubSpot CRM objects with rate limiting.
*
* @param string $objectType The object type ('deals', 'companies', 'contacts', 'calls')
* @param array<string, mixed> $payload The search payload with filters, sorts, properties, etc.
*
* @throws RateLimitException When rate limit is hit
* @throws HubspotException On API errors
*
* @return array The search response with 'results', 'total', 'paging' keys
*/
public function search(string $objectType, array $payload): array
{
$endpoint = self::BASE_URL . "/crm/v3/objects/{$objectType}/search";
return $this->executeRequest(function () use ($endpoint, $payload) {
$response = $this->getInstance()->getClient()->request('POST', $endpoint, ['json' => $payload]);
return $response->toArray();
});
}
/**
* @throws DealApiException
* @throws CrmException
*/
public function getOpportunityById(string $crmId, array $fields): array
{
try {
$deal = $this->getNewInstance()->crm()->deals()->basicApi()->getById(
$crmId,
implode(',', $fields),
'companies,contacts'
);
} catch (DealApiException $e) {
$this->log->info('[Hubspot] Failed to fetch opportunity', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $deal instanceof DealWithAssociations) {
throw new CrmException('Deal not found');
}
return [
'id' => $deal->getId(),
'properties' => $deal->getProperties(),
'associations' => $deal->getAssociations(),
];
}
/**
* Generic batch read method for HubSpot objects
*
* @param string $objectType The object type ('deals', 'companies', 'contacts')
* @param array<string> $crmIds Array of HubSpot object IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with object data
*/
private function batchReadObjects(string $objectType, array $crmIds, array $fields): array
{
if (empty($crmIds)) {
return [];
}
$this->validateBatchSize($objectType, $crmIds);
$this->ensureValidToken();
try {
$batchConfig = $this->createBatchConfiguration($objectType);
$batchReadRequest = $this->prepareBatchRequest($batchConfig, $crmIds, $fields);
$response = $batchConfig['api']->read($batchReadRequest);
$this->validateApiResponse($response, $objectType);
$results = $this->processApiResults($response);
$this->logBatchResults($objectType, $crmIds, $results);
return $results;
} catch (\Throwable $e) {
$this->handleBatchError($e, $objectType, $crmIds);
}
}
private function validateBatchSize(string $objectType, array $crmIds): void
{
if (count($crmIds) > 100) {
throw new \InvalidArgumentException("Batch size cannot exceed 100 {$objectType}");
}
}
private function createBatchConfiguration(string $objectType): array
{
$configurations = [
'deals' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Deals\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Deals\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->deals()->batchApi(),
],
'companies' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Companies\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Companies\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->companies()->batchApi(),
],
'contacts' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Contacts\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->contacts()->batchApi(),
],
];
if (! isset($configurations[$objectType])) {
throw new \InvalidArgumentException("Unsupported object type: {$objectType}");
}
return $configurations[$objectType];
}
private function prepareBatchRequest(array $batchConfig, array $crmIds, array $fields): object
{
$batchReadRequest = $batchConfig['batchReadRequest'];
$inputClass = $batchConfig['inputClass'];
$inputs = array_map(function ($crmId) use ($inputClass) {
$input = new $inputClass();
$input->setId($crmId);
return $input;
}, $crmIds);
$batchReadRequest->setInputs($inputs);
$batchReadRequest->setProperties($fields);
return $batchReadRequest;
}
private function validateApiResponse($response, string $objectType): void
{
if (! $response) {
throw new CrmException("HubSpot API returned null response for {$objectType} batch read");
}
}
private function processApiResults($response): array
{
$results = [];
$responseResults = $response->getResults();
if ($responseResults) {
foreach ($responseResults as $object) {
if ($object && $object->getId()) {
$results[$object->getId()] = [
'id' => $object->getId(),
'properties' => $object->getProperties() ?: [],
];
}
}
}
return $results;
}
private function logBatchResults(string $objectType, array $crmIds, array $results): void
{
$this->log->info("[HubSpot] Batch fetched {$objectType}", [
'requested_count' => count($crmIds),
'returned_count' => count($results),
'crm_ids' => $crmIds,
]);
}
private function handleBatchError(\Throwable $e, string $objectType, array $crmIds): void
{
$errorMessage = $e->getMessage() ?: 'Unknown error';
$errorTrace = $e->getTraceAsString() ?: 'No trace available';
$this->log->error("[HubSpot] Failed to batch fetch {$objectType}", [
'crm_ids' => $crmIds,
'error' => $errorMessage,
'trace' => $errorTrace,
]);
throw new CrmException("Failed to batch fetch {$objectType}: " . $errorMessage);
}
/**
* Batch read multiple opportunities by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot deal IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with opportunity data
*/
public function getOpportunitiesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('deals', $crmIds, $fields);
}
/**
* Batch read multiple companies by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot company IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with company data
*/
public function getCompaniesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('companies', $crmIds, $fields);
}
/**
* Batch read multiple contacts by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot contact IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with contact data
*/
public function getContactsByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('contacts', $crmIds, $fields);
}
/**
* @throws CompanyApiException
* @throws CrmException
*/
public function getAccountById(string $crmId, array $fields): array
{
try {
$company = $this->getNewInstance()->crm()->companies()->basicApi()->getById(
$crmId,
implode(',', $fields),
);
} catch (CompanyApiException $e) {
$this->log->info('[Hubspot] Failed to fetch account', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $company instanceof CompaniesWithAssociations) {
throw new CrmException('Account not found');
}
return [
'id' => $company->getId(),
'properties' => $company->getProperties(),
];
}
/**
* @throws ContactApiException
* @throws CrmException
*/
public function getContactById(string $crmId, array $fields): array
{
try {
$contact = $this->getNewInstance()->crm()->contacts()->basicApi()->getById(
$crmId,
implode(',', $fields)
Review rate limit handli…, Editor Group 2
remote
app (Git) - JY-20725-handle-HS-search-rate-limit*, Checkout Branch/Tag...
JY-20725-handle-HS-search-rate-limit*
app (Git) - Synchronize Changes
Errors: 6, Warnings: 9, Infos: 2
6
9
2
Notifications
key, PHP extension: Premium features not active.
Sign In
Sign In
Diff editor
Clear
Review rate limit handling for HubSpot job queue
Session history
New session
Message actions
RateLimitException.php#9-9
RateLimitException.php#9-9
Reveiw the diff. Mostly
@app/Jobs/Crm/MatchActivityCrmData.php
,
@app/Exceptions/RateLimitException.php
,
@app/Jobs/Middleware/HandleHubspotRateLimit.php
,
@app/Services/Crm/Hubspot/Client.php
and
@app/Services/Crm/Hubspot/Pagination/HubspotPaginationService.php
. The issue is I am trying to make sure that instant spike of MatchActivityCrmData jobs willl handle 429 exceptions from hubspot. Revewi ti carefully and try to see potential issues and bottlenecks. Also RateLimitException was changerd from LogicException to RuntimeException. Is it ok. This exception is used by other paerts of code. Will ti break anything?
Thought for 5s
Thought for 5s
I'll review the implementation carefully. Let me first check how
RateLimitException
is used elsewhere and look at the test files and
PaginationState
.
Bash
Find all usages of RateLimitException outside the changed files
IN
grep -rn "RateLimitException" /Users/lukas/jiminny/app/app --include="*.php" | grep -v "HandleHubspotRateLimit\|MatchActivityCrmData\|Client.php\|RateLimitException.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:13:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
/Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php:17:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php:68: RateLimitException |
/Users/lukas/jiminny/app/app/Component/TranscriptionSummary/Jobs/SummarizeTranscriptionJob.php:15:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/TranscriptionSummary/Jobs/SummarizeTranscriptionJob.php:58: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
/Users/lukas/jiminny/app/app/Component/AiActivityType/Jobs/GenerateAiActivityTypeJob.php:19:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/AiActivityType/Jobs/GenerateAiActivityTypeJob.php:76: RateLimitException |
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/HubspotClientInterface.php:8:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/HubspotClientInterface.php:50: * @throws RateLimitException When rate limit is hit
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/Pagination/HubspotPaginationService.php:195: // RateLimitException and other exceptions are re-thrown as-is
Read
PaginationState.php
PaginationState.php
Read
HandleHubspotRateLimitTest.php
HandleHubspotRateLimitTest.php
Bash
Check how RateLimitException is used in GenerateActionItemsJob
IN
grep -rn "RateLimitException\|LogicException\|RuntimeException" /Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php | head -20
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:13:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
Bash
Find all catch blocks or instanceof checks for RateLimitException
IN
grep -rn "catch.*RateLimitException\|instanceof RateLimitException" /Users/lukas/jiminny/app/app --include="*.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Jobs/Middleware/HandleHubspotRateLimit.php:11: * Job middleware that catches RateLimitException from HubSpot API calls
/Users/lukas/jiminny/app/app/Jobs/Middleware/HandleHubspotRateLimit.php:24: } catch (RateLimitException $e) {
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:149: if (! $e instanceof RateLimitException) {
Bash
Find all test references to RateLimitException
IN
grep -rn "RateLimitException" /Users/lukas/jiminny/app/tests --include="*.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:8:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:13:#[CoversClass(RateLimitException::class)]
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:14:class RateLimitExceptionTest extends TestCase
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:18: $exception = new RateLimitException();
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:28: $exception = new RateLimitException('Hubspot rate limit', 30, $previous);
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:52: $exception = new RateLimitException('test', $input);
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:10:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:49: public function testPropagatesNonRateLimitExceptions(): void
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:103: throw new RateLimitException('rate limited', $retryAfter);
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:150: throw new RateLimitException('rate limited', 1);
Bash
Check retry/failure handling in GenerateActionItemsJob
IN
grep -n "RateLimitException\|retryUntil\|backoff\|maxExceptions\|maxTries\|release\|failed" /Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php | head -30
Copy code to clipboard
OUT
13:use Jiminny\Exceptions\RateLimitException;
51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
56: $this->release(30);
Bash
Check retry/failure handling in GenerateAiCallScoringJob
IN
grep -n "RateLimitException\|retryUntil\|backoff\|maxExceptions\|maxTries\|release\|failed" /Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php | head -30
Copy code to clipboard
OUT
17:use Jiminny\Exceptions\RateLimitException;
68: RateLimitException |
75: $this->release(30);
Bash
Check retry config in MatchActivityCrmData
IN
grep -n "retryAfter\|RETRY_WINDOW\|retryUntil\|maxTries" /Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php
Copy code to clipboard...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20006
|
|
20025
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G)
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
FieldTypeConverter.php
HubspotClientInterface.php
HubspotTokenManager.php
PayloadBuilder.php
RemoteCrmObjectManipulator.php
ResponseNormalize.php
Service.php...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20025
|
|
20026
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G)
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20026
|
|
20027
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
FieldTypeConverter.php
HubspotClientInterface.php
HubspotTokenManager.php
PayloadBuilder.php
RemoteCrmObjectManipulator.php
ResponseNormalize.php
Service.php
SyncFieldAction.php
SyncRelatedActivityManager.php
WebhookSyncBatchProcessor.php
IntegrationApp
Listeners
Metadata
Migration
Pipedrive
OpportunitySyncStrategy
ProspectSearchStrategy
ApiFields.php
OpportunitySyncStrategy
Hubspot
Crm
Services
app
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
MySQL Section
MYSQL
MYSQL
MatchActivityCrmData.php, Editor Group 1
RateLimitException.php, Editor Group 1
HandleHubspotRateLimit.php, Editor Group 1
Client.php, Editor Group 1
HubspotPaginationService.php, Editor Group 1
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm\Hubspot;
use HubSpot\Client\Crm\Deals\ApiException as DealApiException;
use HubSpot\Client\Crm\Contacts\ApiException as ContactApiException;
use HubSpot\Client\Crm\Companies\ApiException as CompanyApiException;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations as ContactsWithAssociations;
use HubSpot\Client\Crm\Companies\Model\SimplePublicObjectWithAssociations as CompaniesWithAssociations;
use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations as DealWithAssociations;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectInput;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectWithAssociations as ObjectWithAssociations;
use HubSpot\Client\Crm\Pipelines\Model\Error;
use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;
use HubSpot\Client\Crm\Properties\Model\Property;
use HubSpot\Discovery\Discovery;
use Jiminny\Exceptions\CrmException;
use Jiminny\Exceptions\RateLimitException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Jobs\Crm\NoteObject;
use Jiminny\Models\Crm\Field;
use Jiminny\Services\Crm\BaseClient;
use Jiminny\Services\Crm\Hubspot\DTO\Response\Owner;
use Jiminny\Services\SocialAccountService;
use SevenShores\Hubspot\Exceptions\BadRequest;
use SevenShores\Hubspot\Exceptions\HubspotException;
use SevenShores\Hubspot\Factory;
use SevenShores\Hubspot\Http\Response;
use Jiminny\Services\Crm\Hubspot\Pagination\HubspotPaginationService;
use Illuminate\Support\Facades\Redis;
use Throwable;
/**
* @phpstan-type CrmFieldOption array{id:string, label:string, value?:string}
*/
class Client extends BaseClient implements HubspotClientInterface
{
public const string MIN_API_VERSION = '2';
public const string BASE_URL = '[URL_WITH_CREDENTIALS] T
*
* @param callable(): T $apiCall The API call to execute
*
* @throws RateLimitException When rate limit is hit or cached rate limit is active
*
* @return T The result of the API call
*/
private function executeRequest(callable $apiCall)
{
$cacheKey = $this->getRateLimitCacheKey();
$cachedExpiresAt = Redis::get($cacheKey);
if (is_string($cachedExpiresAt) && is_numeric($cachedExpiresAt)) {
$remaining = max(1, (int) $cachedExpiresAt - time());
throw new RateLimitException(
'Hubspot rate limit (cached circuit-breaker)',
$remaining,
);
}
try {
return $apiCall();
} catch (Throwable $e) {
if ($this->isHubspotRateLimit($e)) {
$retryAfter = $this->parseRetryAfter($e);
// NX: only the first job to receive a 429 in this burst sets the key.
// Subsequent 429s in the same burst leave the TTL untouched so the
// window is not reset by every concurrent job hitting the limit.
Redis::set($cacheKey, (string) (time() + $retryAfter), ['nx', 'ex' => $retryAfter]);
$this->log->warning('[Hubspot] Received 429 from API', [
'team_id' => $this->config->team_id,
'config_id' => $this->config->getId(),
'retry_after' => $retryAfter,
'reason' => $e->getMessage(),
]);
throw new RateLimitException('Hubspot returned 429', $retryAfter, $e);
}
throw $e;
}
}
private function getRateLimitCacheKey(): string
{
return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
}
public function isHubspotRateLimit(Throwable $e): bool
{
if ($e instanceof BadRequest
|| $e instanceof DealApiException
|| $e instanceof ContactApiException
|| $e instanceof CompanyApiException
|| $e instanceof \GuzzleHttp\Exception\RequestException
) {
return (int) $e->getCode() === 429;
}
return false;
}
public function parseRetryAfter(Throwable $e): int
{
if (method_exists($e, 'getResponseHeaders')) {
$headers = $e->getResponseHeaders() ?: [];
$value = $headers['Retry-After'] ?? $headers['retry-after'] ?? null;
if (is_array($value)) {
$value = $value[0] ?? null;
}
if (is_numeric($value)) {
return (int) $value;
}
}
$message = strtolower($e->getMessage());
if (str_contains($message, 'daily')) {
return 600;
}
if (str_contains($message, 'ten secondly')) {
return 10;
}
if (str_contains($message, 'secondly')) {
return 1;
}
$this->log->warning('[Hubspot] No retry-after header or known message, using default', [
'exception_class' => get_class($e),
'message' => $message,
]);
return 10;
}
public function getMinimumApiVersion(): string
{
return self::MIN_API_VERSION;
}
public function getInstance(): Factory
{
return new Factory([
'key' => $this->accessToken,
'oauth2' => true,
'base_url' => $this->baseUrl,
]);
}
public function getNewInstance(): Discovery
{
return \HubSpot\Factory::createWithAccessToken($this->accessToken);
}
/**
* Secondly and daily limits for Hubspot API
*
* Product Tier: Free & Starter | Professional & Enterprise | API add-on (any tier)
* Burst: 100/10 seconds | 150/10 seconds | 200/10 seconds
* Daily: 250,000 | 500,000 | 1,000,000
*
* Official documentation states: The search endpoints are rate limited to five requests per second.
* Since with 5 RPS were still hitting secondly rate limits we lowered it to 4
*/
public function getPaginatedData(array $payload, string $type, int $offset = 0): array
{
$total = 0;
$lastId = null;
$rows = [];
foreach ($this->getPaginatedDataGenerator($payload, $type, $offset, $total, $lastId) as $row) {
$rows[] = $row;
}
return ['results' => $rows, 'total' => $total, 'last_record' => $lastId];
}
/**
* @throws HubspotException
* @throws SocialAccountTokenInvalidException
* @throws BadRequest
*/
public function getPaginatedDataGenerator(
array $payload,
string $type,
int $offset = 0,
int &$total = 0,
?string &$lastRecordId = null
): \Generator {
return $this->paginationService->getPaginatedDataGenerator(
$this,
$payload,
$type,
$offset,
$total,
$lastRecordId
);
}
/**
* Execute a search request against HubSpot CRM objects with rate limiting.
*
* @param string $objectType The object type ('deals', 'companies', 'contacts', 'calls')
* @param array<string, mixed> $payload The search payload with filters, sorts, properties, etc.
*
* @throws RateLimitException When rate limit is hit
* @throws HubspotException On API errors
*
* @return array The search response with 'results', 'total', 'paging' keys
*/
public function search(string $objectType, array $payload): array
{
$endpoint = self::BASE_URL . "/crm/v3/objects/{$objectType}/search";
return $this->executeRequest(function () use ($endpoint, $payload) {
$response = $this->getInstance()->getClient()->request('POST', $endpoint, ['json' => $payload]);
return $response->toArray();
});
}
/**
* @throws DealApiException
* @throws CrmException
*/
public function getOpportunityById(string $crmId, array $fields): array
{
try {
$deal = $this->getNewInstance()->crm()->deals()->basicApi()->getById(
$crmId,
implode(',', $fields),
'companies,contacts'
);
} catch (DealApiException $e) {
$this->log->info('[Hubspot] Failed to fetch opportunity', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $deal instanceof DealWithAssociations) {
throw new CrmException('Deal not found');
}
return [
'id' => $deal->getId(),
'properties' => $deal->getProperties(),
'associations' => $deal->getAssociations(),
];
}
/**
* Generic batch read method for HubSpot objects
*
* @param string $objectType The object type ('deals', 'companies', 'contacts')
* @param array<string> $crmIds Array of HubSpot object IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with object data
*/
private function batchReadObjects(string $objectType, array $crmIds, array $fields): array
{
if (empty($crmIds)) {
return [];
}
$this->validateBatchSize($objectType, $crmIds);
$this->ensureValidToken();
try {
$batchConfig = $this->createBatchConfiguration($objectType);
$batchReadRequest = $this->prepareBatchRequest($batchConfig, $crmIds, $fields);
$response = $batchConfig['api']->read($batchReadRequest);
$this->validateApiResponse($response, $objectType);
$results = $this->processApiResults($response);
$this->logBatchResults($objectType, $crmIds, $results);
return $results;
} catch (\Throwable $e) {
$this->handleBatchError($e, $objectType, $crmIds);
}
}
private function validateBatchSize(string $objectType, array $crmIds): void
{
if (count($crmIds) > 100) {
throw new \InvalidArgumentException("Batch size cannot exceed 100 {$objectType}");
}
}
private function createBatchConfiguration(string $objectType): array
{
$configurations = [
'deals' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Deals\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Deals\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->deals()->batchApi(),
],
'companies' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Companies\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Companies\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->companies()->batchApi(),
],
'contacts' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Contacts\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->contacts()->batchApi(),
],
];
if (! isset($configurations[$objectType])) {
throw new \InvalidArgumentException("Unsupported object type: {$objectType}");
}
return $configurations[$objectType];
}
private function prepareBatchRequest(array $batchConfig, array $crmIds, array $fields): object
{
$batchReadRequest = $batchConfig['batchReadRequest'];
$inputClass = $batchConfig['inputClass'];
$inputs = array_map(function ($crmId) use ($inputClass) {
$input = new $inputClass();
$input->setId($crmId);
return $input;
}, $crmIds);
$batchReadRequest->setInputs($inputs);
$batchReadRequest->setProperties($fields);
return $batchReadRequest;
}
private function validateApiResponse($response, string $objectType): void
{
if (! $response) {
throw new CrmException("HubSpot API returned null response for {$objectType} batch read");
}
}
private function processApiResults($response): array
{
$results = [];
$responseResults = $response->getResults();
if ($responseResults) {
foreach ($responseResults as $object) {
if ($object && $object->getId()) {
$results[$object->getId()] = [
'id' => $object->getId(),
'properties' => $object->getProperties() ?: [],
];
}
}
}
return $results;
}
private function logBatchResults(string $objectType, array $crmIds, array $results): void
{
$this->log->info("[HubSpot] Batch fetched {$objectType}", [
'requested_count' => count($crmIds),
'returned_count' => count($results),
'crm_ids' => $crmIds,
]);
}
private function handleBatchError(\Throwable $e, string $objectType, array $crmIds): void
{
$errorMessage = $e->getMessage() ?: 'Unknown error';
$errorTrace = $e->getTraceAsString() ?: 'No trace available';
$this->log->error("[HubSpot] Failed to batch fetch {$objectType}", [
'crm_ids' => $crmIds,
'error' => $errorMessage,
'trace' => $errorTrace,
]);
throw new CrmException("Failed to batch fetch {$objectType}: " . $errorMessage);
}
/**
* Batch read multiple opportunities by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot deal IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with opportunity data
*/
public function getOpportunitiesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('deals', $crmIds, $fields);
}
/**
* Batch read multiple companies by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot company IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with company data
*/
public function getCompaniesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('companies', $crmIds, $fields);
}
/**
* Batch read multiple contacts by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot contact IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with contact data
*/
public function getContactsByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('contacts', $crmIds, $fields);
}
/**
* @throws CompanyApiException
* @throws CrmException
*/
public function getAccountById(string $crmId, array $fields): array
{
try {
$company = $this->getNewInstance()->crm()->companies()->basicApi()->getById(
$crmId,
implode(',', $fields),
);
} catch (CompanyApiException $e) {
$this->log->info('[Hubspot] Failed to fetch account', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $company instanceof CompaniesWithAssociations) {
throw new CrmException('Account not found');
}
return [
'id' => $company->getId(),
'properties' => $company->getProperties(),
];
}
/**
* @throws ContactApiException
* @throws CrmException
*/
public function getContactById(string $crmId, array $fields): array
{
try {
$contact = $this->getNewInstance()->crm()->contacts()->basicApi()->getById(
$crmId,
implode(',', $fields)
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm\Hubspot;
use HubSpot\Client\Crm\Deals\ApiException as DealApiException;
use HubSpot\Client\Crm\Contacts\ApiException as ContactApiException;
use HubSpot\Client\Crm\Companies\ApiException as CompanyApiException;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations as ContactsWithAssociations;
use HubSpot\Client\Crm\Companies\Model\SimplePublicObjectWithAssociations as CompaniesWithAssociations;
use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations as DealWithAssociations;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectInput;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectWithAssociations as ObjectWithAssociations;
use HubSpot\Client\Crm\Pipelines\Model\Error;
use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;
use HubSpot\Client\Crm\Properties\Model\Property;
use HubSpot\Discovery\Discovery;
use Jiminny\Exceptions\CrmException;
use Jiminny\Exceptions\RateLimitException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Jobs\Crm\NoteObject;
use Jiminny\Models\Crm\Field;
use Jiminny\Services\Crm\BaseClient;
use Jiminny\Services\Crm\Hubspot\DTO\Response\Owner;
use Jiminny\Services\SocialAccountService;
use SevenShores\Hubspot\Exceptions\BadRequest;
use SevenShores\Hubspot\Exceptions\HubspotException;
use SevenShores\Hubspot\Factory;
use SevenShores\Hubspot\Http\Response;
use Jiminny\Services\Crm\Hubspot\Pagination\HubspotPaginationService;
use Illuminate\Support\Facades\Redis;
use Throwable;
/**
* @phpstan-type CrmFieldOption array{id:string, label:string, value?:string}
*/
class Client extends BaseClient implements HubspotClientInterface
{
public const string MIN_API_VERSION = '2';
public const string BASE_URL = '[URL_WITH_CREDENTIALS] T
*
* @param callable(): T $apiCall The API call to execute
*
* @throws RateLimitException When rate limit is hit or cached rate limit is active
*
* @return T The result of the API call
*/
private function executeRequest(callable $apiCall)
{
$cacheKey = $this->getRateLimitCacheKey();
$cachedExpiresAt = Redis::get($cacheKey);
if (is_string($cachedExpiresAt) && is_numeric($cachedExpiresAt)) {
$remaining = max(1, (int) $cachedExpiresAt - time());
throw new RateLimitException(
'Hubspot rate limit (cached circuit-breaker)',
$remaining,
);
}
try {
return $apiCall();
} catch (Throwable $e) {
if ($this->isHubspotRateLimit($e)) {
$retryAfter = $this->parseRetryAfter($e);
// NX: only the first job to receive a 429 in this burst sets the key.
// Subsequent 429s in the same burst leave the TTL untouched so the
// window is not reset by every concurrent job hitting the limit.
Redis::set($cacheKey, (string) (time() + $retryAfter), ['nx', 'ex' => $retryAfter]);
$this->log->warning('[Hubspot] Received 429 from API', [
'team_id' => $this->config->team_id,
'config_id' => $this->config->getId(),
'retry_after' => $retryAfter,
'reason' => $e->getMessage(),
]);
throw new RateLimitException('Hubspot returned 429', $retryAfter, $e);
}
throw $e;
}
}
private function getRateLimitCacheKey(): string
{
return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
}
public function isHubspotRateLimit(Throwable $e): bool
{
if ($e instanceof BadRequest
|| $e instanceof DealApiException
|| $e instanceof ContactApiException
|| $e instanceof CompanyApiException
|| $e instanceof \GuzzleHttp\Exception\RequestException
) {
return (int) $e->getCode() === 429;
}
return false;
}
public function parseRetryAfter(Throwable $e): int
{
if (method_exists($e, 'getResponseHeaders')) {
$headers = $e->getResponseHeaders() ?: [];
$value = $headers['Retry-After'] ?? $headers['retry-after'] ?? null;
if (is_array($value)) {
$value = $value[0] ?? null;
}
if (is_numeric($value)) {
return (int) $value;
}
}
$message = strtolower($e->getMessage());
if (str_contains($message, 'daily')) {
return 600;
}
if (str_contains($message, 'ten secondly')) {
return 10;
}
if (str_contains($message, 'secondly')) {
return 1;
}
$this->log->warning('[Hubspot] No retry-after header or known message, using default', [
'exception_class' => get_class($e),
'message' => $message,
]);
return 10;
}
public function getMinimumApiVersion(): string
{
return self::MIN_API_VERSION;
}
public function getInstance(): Factory
{
return new Factory([
'key' => $this->accessToken,
'oauth2' => true,
'base_url' => $this->baseUrl,
]);
}
public function getNewInstance(): Discovery
{
return \HubSpot\Factory::createWithAccessToken($this->accessToken);
}
/**
* Secondly and daily limits for Hubspot API
*
* Product Tier: Free & Starter | Professional & Enterprise | API add-on (any tier)
* Burst: 100/10 seconds | 150/10 seconds | 200/10 seconds
* Daily: 250,000 | 500,000 | 1,000,000
*
* Official documentation states: The search endpoints are rate limited to five requests per second.
* Since with 5 RPS were still hitting secondly rate limits we lowered it to 4
*/
public function getPaginatedData(array $payload, string $type, int $offset = 0): array
{
$total = 0;
$lastId = null;
$rows = [];
foreach ($this->getPaginatedDataGenerator($payload, $type, $offset, $total, $lastId) as $row) {
$rows[] = $row;
}
return ['results' => $rows, 'total' => $total, 'last_record' => $lastId];
}
/**
* @throws HubspotException
* @throws SocialAccountTokenInvalidException
* @throws BadRequest
*/
public function getPaginatedDataGenerator(
array $payload,
string $type,
int $offset = 0,
int &$total = 0,
?string &$lastRecordId = null
): \Generator {
return $this->paginationService->getPaginatedDataGenerator(
$this,
$payload,
$type,
$offset,
$total,
$lastRecordId
);
}
/**
* Execute a search request against HubSpot CRM objects with rate limiting.
*
* @param string $objectType The object type ('deals', 'companies', 'contacts', 'calls')
* @param array<string, mixed> $payload The search payload with filters, sorts, properties, etc.
*
* @throws RateLimitException When rate limit is hit
* @throws HubspotException On API errors
*
* @return array The search response with 'results', 'total', 'paging' keys
*/
public function search(string $objectType, array $payload): array
{
$endpoint = self::BASE_URL . "/crm/v3/objects/{$objectType}/search";
return $this->executeRequest(function () use ($endpoint, $payload) {
$response = $this->getInstance()->getClient()->request('POST', $endpoint, ['json' => $payload]);
return $response->toArray();
});
}
/**
* @throws DealApiException
* @throws CrmException
*/
public function getOpportunityById(string $crmId, array $fields): array
{
try {
$deal = $this->getNewInstance()->crm()->deals()->basicApi()->getById(
$crmId,
implode(',', $fields),
'companies,contacts'
);
} catch (DealApiException $e) {
$this->log->info('[Hubspot] Failed to fetch opportunity', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $deal instanceof DealWithAssociations) {
throw new CrmException('Deal not found');
}
return [
'id' => $deal->getId(),
'properties' => $deal->getProperties(),
'associations' => $deal->getAssociations(),
];
}
/**
* Generic batch read method for HubSpot objects
*
* @param string $objectType The object type ('deals', 'companies', 'contacts')
* @param array<string> $crmIds Array of HubSpot object IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with object data
*/
private function batchReadObjects(string $objectType, array $crmIds, array $fields): array
{
if (empty($crmIds)) {
return [];
}
$this->validateBatchSize($objectType, $crmIds);
$this->ensureValidToken();
try {
$batchConfig = $this->createBatchConfiguration($objectType);
$batchReadRequest = $this->prepareBatchRequest($batchConfig, $crmIds, $fields);
$response = $batchConfig['api']->read($batchReadRequest);
$this->validateApiResponse($response, $objectType);
$results = $this->processApiResults($response);
$this->logBatchResults($objectType, $crmIds, $results);
return $results;
} catch (\Throwable $e) {
$this->handleBatchError($e, $objectType, $crmIds);
}
}
private function validateBatchSize(string $objectType, array $crmIds): void
{
if (count($crmIds) > 100) {
throw new \InvalidArgumentException("Batch size cannot exceed 100 {$objectType}");
}
}
private function createBatchConfiguration(string $objectType): array
{
$configurations = [
'deals' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Deals\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Deals\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->deals()->batchApi(),
],
'companies' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Companies\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Companies\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->companies()->batchApi(),
],
'contacts' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Contacts\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->contacts()->batchApi(),
],
];
if (! isset($configurations[$objectType])) {
throw new \InvalidArgumentException("Unsupported object type: {$objectType}");
}
return $configurations[$objectType];
}
private function prepareBatchRequest(array $batchConfig, array $crmIds, array $fields): object
{
$batchReadRequest = $batchConfig['batchReadRequest'];
$inputClass = $batchConfig['inputClass'];
$inputs = array_map(function ($crmId) use ($inputClass) {
$input = new $inputClass();
$input->setId($crmId);
return $input;
}, $crmIds);
$batchReadRequest->setInputs($inputs);
$batchReadRequest->setProperties($fields);
return $batchReadRequest;
}
private function validateApiResponse($response, string $objectType): void
{
if (! $response) {
throw new CrmException("HubSpot API returned null response for {$objectType} batch read");
}
}
private function processApiResults($response): array
{
$results = [];
$responseResults = $response->getResults();
if ($responseResults) {
foreach ($responseResults as $object) {
if ($object && $object->getId()) {
$results[$object->getId()] = [
'id' => $object->getId(),
'properties' => $object->getProperties() ?: [],
];
}
}
}
return $results;
}
private function logBatchResults(string $objectType, array $crmIds, array $results): void
{
$this->log->info("[HubSpot] Batch fetched {$objectType}", [
'requested_count' => count($crmIds),
'returned_count' => count($results),
'crm_ids' => $crmIds,
]);
}
private function handleBatchError(\Throwable $e, string $objectType, array $crmIds): void
{
$errorMessage = $e->getMessage() ?: 'Unknown error';
$errorTrace = $e->getTraceAsString() ?: 'No trace available';
$this->log->error("[HubSpot] Failed to batch fetch {$objectType}", [
'crm_ids' => $crmIds,
'error' => $errorMessage,
'trace' => $errorTrace,
]);
throw new CrmException("Failed to batch fetch {$objectType}: " . $errorMessage);
}
/**
* Batch read multiple opportunities by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot deal IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with opportunity data
*/
public function getOpportunitiesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('deals', $crmIds, $fields);
}
/**
* Batch read multiple companies by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot company IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with company data
*/
public function getCompaniesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('companies', $crmIds, $fields);
}
/**
* Batch read multiple contacts by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot contact IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with contact data
*/
public function getContactsByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('contacts', $crmIds, $fields);
}
/**
* @throws CompanyApiException
* @throws CrmException
*/
public function getAccountById(string $crmId, array $fields): array
{
try {
$company = $this->getNewInstance()->crm()->companies()->basicApi()->getById(
$crmId,
implode(',', $fields),
);
} catch (CompanyApiException $e) {
$this->log->info('[Hubspot] Failed to fetch account', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $company instanceof CompaniesWithAssociations) {
throw new CrmException('Account not found');
}
return [
'id' => $company->getId(),
'properties' => $company->getProperties(),
];
}
/**
* @throws ContactApiException
* @throws CrmException
*/
public function getContactById(string $crmId, array $fields): array
{
try {
$contact = $this->getNewInstance()->crm()->contacts()->basicApi()->getById(
$crmId,
implode(',', $fields)
Review rate limit handli…, Editor Group 2
remote
app (Git) - JY-20725-handle-HS-search-rate-limit*, Checkout Branch/Tag...
JY-20725-handle-HS-search-rate-limit*
app (Git) - Synchronize Changes
Errors: 6, Warnings: 9, Infos: 2
6
9
2
Notifications
key, PHP extension: Premium features not active.
Sign In
Sign In
Diff editor
Clear
Review rate limit handling for HubSpot job queue
Session history
New session
Message actions
RateLimitException.php#9-9
RateLimitException.php#9-9
Reveiw the diff. Mostly
@app/Jobs/Crm/MatchActivityCrmData.php
,
@app/Exceptions/RateLimitException.php
,
@app/Jobs/Middleware/HandleHubspotRateLimit.php
,
@app/Services/Crm/Hubspot/Client.php
and
@app/Services/Crm/Hubspot/Pagination/HubspotPaginationService.php
. The issue is I am trying to make sure that instant spike of MatchActivityCrmData jobs willl handle 429 exceptions from hubspot. Revewi ti carefully and try to see potential issues and bottlenecks. Also RateLimitException was changerd from LogicException to RuntimeException. Is it ok. This exception is used by other paerts of code. Will ti break anything?
Thought for 5s
Thought for 5s
I'll review the implementation carefully. Let me first check how
RateLimitException
is used elsewhere and look at the test files and
PaginationState
.
Bash
Find all usages of RateLimitException outside the changed files
IN
grep -rn "RateLimitException" /Users/lukas/jiminny/app/app --include="*.php" | grep -v "HandleHubspotRateLimit\|MatchActivityCrmData\|Client.php\|RateLimitException.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:13:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
/Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php:17:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php:68: RateLimitException |
/Users/lukas/jiminny/app/app/Component/TranscriptionSummary/Jobs/SummarizeTranscriptionJob.php:15:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/TranscriptionSummary/Jobs/SummarizeTranscriptionJob.php:58: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
/Users/lukas/jiminny/app/app/Component/AiActivityType/Jobs/GenerateAiActivityTypeJob.php:19:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/AiActivityType/Jobs/GenerateAiActivityTypeJob.php:76: RateLimitException |
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/HubspotClientInterface.php:8:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/HubspotClientInterface.php:50: * @throws RateLimitException When rate limit is hit
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/Pagination/HubspotPaginationService.php:195: // RateLimitException and other exceptions are re-thrown as-is
Read
PaginationState.php
PaginationState.php
Read
HandleHubspotRateLimitTest.php
HandleHubspotRateLimitTest.php
Bash
Check how RateLimitException is used in GenerateActionItemsJob
IN
grep -rn "RateLimitException\|LogicException\|RuntimeException" /Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php | head -20
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:13:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
Bash
Find all catch blocks or instanceof checks for RateLimitException
IN
grep -rn "catch.*RateLimitException\|instanceof RateLimitException" /Users/lukas/jiminny/app/app --include="*.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Jobs/Middleware/HandleHubspotRateLimit.php:11: * Job middleware that catches RateLimitException from HubSpot API calls
/Users/lukas/jiminny/app/app/Jobs/Middleware/HandleHubspotRateLimit.php:24: } catch (RateLimitException $e) {
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:149: if (! $e instanceof RateLimitException) {
Bash
Find all test references to RateLimitException
IN
grep -rn "RateLimitException" /Users/lukas/jiminny/app/tests --include="*.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:8:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:13:#[CoversClass(RateLimitException::class)]
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:14:class RateLimitExceptionTest extends TestCase
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:18: $exception = new RateLimitException();
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:28: $exception = new RateLimitException('Hubspot rate limit', 30, $previous);
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:52: $exception = new RateLimitException('test', $input);
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:10:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:49: public function testPropagatesNonRateLimitExceptions(): void
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:103: throw new RateLimitException('rate limited', $retryAfter);
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:150: throw new RateLimitException('rate limited', 1);
Bash
Check retry/failure handling in GenerateActionItemsJob
IN
grep -n "RateLimitException\|retryUntil\|backoff\|maxExceptions\|maxTries\|release\|failed" /Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php | head -30
Copy code to clipboard
OUT
13:use Jiminny\Exceptions\RateLimitException;
51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
56: $this->release(30);
Bash
Check retry/failure handling in GenerateAiCallScoringJob
IN
grep -n "RateLimitException\|retryUntil\|backoff\|maxExceptions\|maxTries\|release\|failed" /Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php | head -30
Copy code to clipboard
OUT
17:use Jiminny\Exceptions\RateLimitException;
68: RateLimitException |
75: $this->release(30);
Bash
Check retry config in MatchActivityCrmData
IN
grep -n "retryAfter\|RETRY_WINDOW\|retryUntil\|maxTries" /Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php
Copy code to clipboard
OUT
34: private const int RETRY_WINDOW_MINUTES = 30;
45: public function retryUntil(): \DateTimeInterface
47: return now()->addMinutes(self::RETRY_WINDOW_MINUTES);
77: return self::RETRY_WINDOW_MINUTES * 60 + 60;
Bash
Check the cache key format
IN
grep -n "getRateLimitCacheKey\|hubspot:ratelimit" /Users/lukas/jiminny/app/app/Services/Crm/Hubspot/Client.php
Copy code to clipboard
OUT
78: $cacheKey = $this->getRateLimitCacheKey();
110: private function getRateLimitCacheKey(): string
112: return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
Bash
Find other jobs that might use the rate limit middleware
IN
grep -rn "class.*Middleware\|HandleHubspotRateLimit" /Users/lukas/jiminny/app/app/Jobs --include="*.php" | grep -v "HandleHubspotRateLimit.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:18:use Jiminny\Jobs\Middleware\HandleHubspotRateLimit;
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:42: return [new HandleHubspotRateLimit()];
Read
HubspotClientInterface.php
HubspotClientInterface.php
Thought for 73s
Thought for 73s
Now I have a complete picture. Here's my full analysis:
Review Summary
Review Summary
RuntimeException vs LogicException — Safe ✓
RuntimeException
vs
LogicException
— Safe ✓
The change is semantically correct and won't break anything.
LogicException
is for programmer errors (invalid arguments, contract violations). A rate limit from an external API is a runtime condition —
RuntimeException
is the right parent. All callers catch
RateLimitException
by name explicitly (union catches in
GenerateActionItemsJob
,
GenerateAiCallScoringJob
,
SummarizeTranscriptionJob
,
GenerateAiActivityTypeJob
) or check
instanceof RateLimitException
— none relies on the parent class type, so nothing breaks.
Issue 1 — Circuit breaker stores stale delay (most important bug)
Issue 1 — Circuit breaker stores stale delay (most important bug)
Client.php:94...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20027
|
|
20028
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
FieldTypeConverter.php
HubspotClientInterface.php
HubspotTokenManager.php
PayloadBuilder.php
RemoteCrmObjectManipulator.php
ResponseNormalize.php
Service.php
SyncFieldAction.php
SyncRelatedActivityManager.php
WebhookSyncBatchProcessor.php
IntegrationApp
Listeners
Metadata
Migration
Pipedrive
OpportunitySyncStrategy
ProspectSearchStrategy
ApiFields.php
OpportunitySyncStrategy
Hubspot
Crm
Services
app
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
MySQL Section
MYSQL
MYSQL
MatchActivityCrmData.php, Editor Group 1
RateLimitException.php, Editor Group 1
HandleHubspotRateLimit.php, Editor Group 1
Client.php, Editor Group 1
HubspotPaginationService.php, Editor Group 1
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm\Hubspot;
use HubSpot\Client\Crm\Deals\ApiException as DealApiException;
use HubSpot\Client\Crm\Contacts\ApiException as ContactApiException;
use HubSpot\Client\Crm\Companies\ApiException as CompanyApiException;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations as ContactsWithAssociations;
use HubSpot\Client\Crm\Companies\Model\SimplePublicObjectWithAssociations as CompaniesWithAssociations;
use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations as DealWithAssociations;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectInput;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectWithAssociations as ObjectWithAssociations;
use HubSpot\Client\Crm\Pipelines\Model\Error;
use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;
use HubSpot\Client\Crm\Properties\Model\Property;
use HubSpot\Discovery\Discovery;
use Jiminny\Exceptions\CrmException;
use Jiminny\Exceptions\RateLimitException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Jobs\Crm\NoteObject;
use Jiminny\Models\Crm\Field;
use Jiminny\Services\Crm\BaseClient;
use Jiminny\Services\Crm\Hubspot\DTO\Response\Owner;
use Jiminny\Services\SocialAccountService;
use SevenShores\Hubspot\Exceptions\BadRequest;
use SevenShores\Hubspot\Exceptions\HubspotException;
use SevenShores\Hubspot\Factory;
use SevenShores\Hubspot\Http\Response;
use Jiminny\Services\Crm\Hubspot\Pagination\HubspotPaginationService;
use Illuminate\Support\Facades\Redis;
use Throwable;
/**
* @phpstan-type CrmFieldOption array{id:string, label:string, value?:string}
*/
class Client extends BaseClient implements HubspotClientInterface
{
public const string MIN_API_VERSION = '2';
public const string BASE_URL = '[URL_WITH_CREDENTIALS] T
*
* @param callable(): T $apiCall The API call to execute
*
* @throws RateLimitException When rate limit is hit or cached rate limit is active
*
* @return T The result of the API call
*/
private function executeRequest(callable $apiCall)
{
$cacheKey = $this->getRateLimitCacheKey();
$cachedExpiresAt = Redis::get($cacheKey);
if (is_string($cachedExpiresAt) && is_numeric($cachedExpiresAt)) {
$remaining = max(1, (int) $cachedExpiresAt - time());
throw new RateLimitException(
'Hubspot rate limit (cached circuit-breaker)',
$remaining,
);
}
try {
return $apiCall();
} catch (Throwable $e) {
if ($this->isHubspotRateLimit($e)) {
$retryAfter = $this->parseRetryAfter($e);
// NX: only the first job to receive a 429 in this burst sets the key.
// Subsequent 429s in the same burst leave the TTL untouched so the
// window is not reset by every concurrent job hitting the limit.
Redis::set($cacheKey, (string) (time() + $retryAfter), ['nx', 'ex' => $retryAfter]);
$this->log->warning('[Hubspot] Received 429 from API', [
'team_id' => $this->config->team_id,
'config_id' => $this->config->getId(),
'retry_after' => $retryAfter,
'reason' => $e->getMessage(),
]);
throw new RateLimitException('Hubspot returned 429', $retryAfter, $e);
}
throw $e;
}
}
private function getRateLimitCacheKey(): string
{
return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
}
public function isHubspotRateLimit(Throwable $e): bool
{
if ($e instanceof BadRequest
|| $e instanceof DealApiException
|| $e instanceof ContactApiException
|| $e instanceof CompanyApiException
|| $e instanceof \GuzzleHttp\Exception\RequestException
) {
return (int) $e->getCode() === 429;
}
return false;
}
public function parseRetryAfter(Throwable $e): int
{
if (method_exists($e, 'getResponseHeaders')) {
$headers = $e->getResponseHeaders() ?: [];
$value = $headers['Retry-After'] ?? $headers['retry-after'] ?? null;
if (is_array($value)) {
$value = $value[0] ?? null;
}
if (is_numeric($value)) {
return (int) $value;
}
}
$message = strtolower($e->getMessage());
if (str_contains($message, 'daily')) {
return 600;
}
if (str_contains($message, 'ten secondly')) {
return 10;
}
if (str_contains($message, 'secondly')) {
return 1;
}
$this->log->warning('[Hubspot] No retry-after header or known message, using default', [
'exception_class' => get_class($e),
'message' => $message,
]);
return 10;
}
public function getMinimumApiVersion(): string
{
return self::MIN_API_VERSION;
}
public function getInstance(): Factory
{
return new Factory([
'key' => $this->accessToken,
'oauth2' => true,
'base_url' => $this->baseUrl,
]);
}
public function getNewInstance(): Discovery
{
return \HubSpot\Factory::createWithAccessToken($this->accessToken);
}
/**
* Secondly and daily limits for Hubspot API
*
* Product Tier: Free & Starter | Professional & Enterprise | API add-on (any tier)
* Burst: 100/10 seconds | 150/10 seconds | 200/10 seconds
* Daily: 250,000 | 500,000 | 1,000,000
*
* Official documentation states: The search endpoints are rate limited to five requests per second.
* Since with 5 RPS were still hitting secondly rate limits we lowered it to 4
*/
public function getPaginatedData(array $payload, string $type, int $offset = 0): array
{
$total = 0;
$lastId = null;
$rows = [];
foreach ($this->getPaginatedDataGenerator($payload, $type, $offset, $total, $lastId) as $row) {
$rows[] = $row;
}
return ['results' => $rows, 'total' => $total, 'last_record' => $lastId];
}
/**
* @throws HubspotException
* @throws SocialAccountTokenInvalidException
* @throws BadRequest
*/
public function getPaginatedDataGenerator(
array $payload,
string $type,
int $offset = 0,
int &$total = 0,
?string &$lastRecordId = null
): \Generator {
return $this->paginationService->getPaginatedDataGenerator(
$this,
$payload,
$type,
$offset,
$total,
$lastRecordId
);
}
/**
* Execute a search request against HubSpot CRM objects with rate limiting.
*
* @param string $objectType The object type ('deals', 'companies', 'contacts', 'calls')
* @param array<string, mixed> $payload The search payload with filters, sorts, properties, etc.
*
* @throws RateLimitException When rate limit is hit
* @throws HubspotException On API errors
*
* @return array The search response with 'results', 'total', 'paging' keys
*/
public function search(string $objectType, array $payload): array
{
$endpoint = self::BASE_URL . "/crm/v3/objects/{$objectType}/search";
return $this->executeRequest(function () use ($endpoint, $payload) {
$response = $this->getInstance()->getClient()->request('POST', $endpoint, ['json' => $payload]);
return $response->toArray();
});
}
/**
* @throws DealApiException
* @throws CrmException
*/
public function getOpportunityById(string $crmId, array $fields): array
{
try {
$deal = $this->getNewInstance()->crm()->deals()->basicApi()->getById(
$crmId,
implode(',', $fields),
'companies,contacts'
);
} catch (DealApiException $e) {
$this->log->info('[Hubspot] Failed to fetch opportunity', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $deal instanceof DealWithAssociations) {
throw new CrmException('Deal not found');
}
return [
'id' => $deal->getId(),
'properties' => $deal->getProperties(),
'associations' => $deal->getAssociations(),
];
}
/**
* Generic batch read method for HubSpot objects
*
* @param string $objectType The object type ('deals', 'companies', 'contacts')
* @param array<string> $crmIds Array of HubSpot object IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with object data
*/
private function batchReadObjects(string $objectType, array $crmIds, array $fields): array
{
if (empty($crmIds)) {
return [];
}
$this->validateBatchSize($objectType, $crmIds);
$this->ensureValidToken();
try {
$batchConfig = $this->createBatchConfiguration($objectType);
$batchReadRequest = $this->prepareBatchRequest($batchConfig, $crmIds, $fields);
$response = $batchConfig['api']->read($batchReadRequest);
$this->validateApiResponse($response, $objectType);
$results = $this->processApiResults($response);
$this->logBatchResults($objectType, $crmIds, $results);
return $results;
} catch (\Throwable $e) {
$this->handleBatchError($e, $objectType, $crmIds);
}
}
private function validateBatchSize(string $objectType, array $crmIds): void
{
if (count($crmIds) > 100) {
throw new \InvalidArgumentException("Batch size cannot exceed 100 {$objectType}");
}
}
private function createBatchConfiguration(string $objectType): array
{
$configurations = [
'deals' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Deals\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Deals\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->deals()->batchApi(),
],
'companies' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Companies\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Companies\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->companies()->batchApi(),
],
'contacts' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Contacts\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->contacts()->batchApi(),
],
];
if (! isset($configurations[$objectType])) {
throw new \InvalidArgumentException("Unsupported object type: {$objectType}");
}
return $configurations[$objectType];
}
private function prepareBatchRequest(array $batchConfig, array $crmIds, array $fields): object
{
$batchReadRequest = $batchConfig['batchReadRequest'];
$inputClass = $batchConfig['inputClass'];
$inputs = array_map(function ($crmId) use ($inputClass) {
$input = new $inputClass();
$input->setId($crmId);
return $input;
}, $crmIds);
$batchReadRequest->setInputs($inputs);
$batchReadRequest->setProperties($fields);
return $batchReadRequest;
}
private function validateApiResponse($response, string $objectType): void
{
if (! $response) {
throw new CrmException("HubSpot API returned null response for {$objectType} batch read");
}
}
private function processApiResults($response): array
{
$results = [];
$responseResults = $response->getResults();
if ($responseResults) {
foreach ($responseResults as $object) {
if ($object && $object->getId()) {
$results[$object->getId()] = [
'id' => $object->getId(),
'properties' => $object->getProperties() ?: [],
];
}
}
}
return $results;
}
private function logBatchResults(string $objectType, array $crmIds, array $results): void
{
$this->log->info("[HubSpot] Batch fetched {$objectType}", [
'requested_count' => count($crmIds),
'returned_count' => count($results),
'crm_ids' => $crmIds,
]);
}
private function handleBatchError(\Throwable $e, string $objectType, array $crmIds): void
{
$errorMessage = $e->getMessage() ?: 'Unknown error';
$errorTrace = $e->getTraceAsString() ?: 'No trace available';
$this->log->error("[HubSpot] Failed to batch fetch {$objectType}", [
'crm_ids' => $crmIds,
'error' => $errorMessage,
'trace' => $errorTrace,
]);
throw new CrmException("Failed to batch fetch {$objectType}: " . $errorMessage);
}
/**
* Batch read multiple opportunities by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot deal IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with opportunity data
*/
public function getOpportunitiesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('deals', $crmIds, $fields);
}
/**
* Batch read multiple companies by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot company IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with company data
*/
public function getCompaniesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('companies', $crmIds, $fields);
}
/**
* Batch read multiple contacts by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot contact IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with contact data
*/
public function getContactsByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('contacts', $crmIds, $fields);
}
/**
* @throws CompanyApiException
* @throws CrmException
*/
public function getAccountById(string $crmId, array $fields): array
{
try {
$company = $this->getNewInstance()->crm()->companies()->basicApi()->getById(
$crmId,
implode(',', $fields),
);
} catch (CompanyApiException $e) {
$this->log->info('[Hubspot] Failed to fetch account', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $company instanceof CompaniesWithAssociations) {
throw new CrmException('Account not found');
}
return [
'id' => $company->getId(),
'properties' => $company->getProperties(),
];
}
/**
* @throws ContactApiException
* @throws CrmException
*/
public function getContactById(string $crmId, array $fields): array
{
try {
$contact = $this->getNewInstance()->crm()->contacts()->basicApi()->getById(
$crmId,
implode(',', $fields)
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm\Hubspot;
use HubSpot\Client\Crm\Deals\ApiException as DealApiException;
use HubSpot\Client\Crm\Contacts\ApiException as ContactApiException;
use HubSpot\Client\Crm\Companies\ApiException as CompanyApiException;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations as ContactsWithAssociations;
use HubSpot\Client\Crm\Companies\Model\SimplePublicObjectWithAssociations as CompaniesWithAssociations;
use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations as DealWithAssociations;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectInput;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectWithAssociations as ObjectWithAssociations;
use HubSpot\Client\Crm\Pipelines\Model\Error;
use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;
use HubSpot\Client\Crm\Properties\Model\Property;
use HubSpot\Discovery\Discovery;
use Jiminny\Exceptions\CrmException;
use Jiminny\Exceptions\RateLimitException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Jobs\Crm\NoteObject;
use Jiminny\Models\Crm\Field;
use Jiminny\Services\Crm\BaseClient;
use Jiminny\Services\Crm\Hubspot\DTO\Response\Owner;
use Jiminny\Services\SocialAccountService;
use SevenShores\Hubspot\Exceptions\BadRequest;
use SevenShores\Hubspot\Exceptions\HubspotException;
use SevenShores\Hubspot\Factory;
use SevenShores\Hubspot\Http\Response;
use Jiminny\Services\Crm\Hubspot\Pagination\HubspotPaginationService;
use Illuminate\Support\Facades\Redis;
use Throwable;
/**
* @phpstan-type CrmFieldOption array{id:string, label:string, value?:string}
*/
class Client extends BaseClient implements HubspotClientInterface
{
public const string MIN_API_VERSION = '2';
public const string BASE_URL = '[URL_WITH_CREDENTIALS] T
*
* @param callable(): T $apiCall The API call to execute
*
* @throws RateLimitException When rate limit is hit or cached rate limit is active
*
* @return T The result of the API call
*/
private function executeRequest(callable $apiCall)
{
$cacheKey = $this->getRateLimitCacheKey();
$cachedExpiresAt = Redis::get($cacheKey);
if (is_string($cachedExpiresAt) && is_numeric($cachedExpiresAt)) {
$remaining = max(1, (int) $cachedExpiresAt - time());
throw new RateLimitException(
'Hubspot rate limit (cached circuit-breaker)',
$remaining,
);
}
try {
return $apiCall();
} catch (Throwable $e) {
if ($this->isHubspotRateLimit($e)) {
$retryAfter = $this->parseRetryAfter($e);
// NX: only the first job to receive a 429 in this burst sets the key.
// Subsequent 429s in the same burst leave the TTL untouched so the
// window is not reset by every concurrent job hitting the limit.
Redis::set($cacheKey, (string) (time() + $retryAfter), ['nx', 'ex' => $retryAfter]);
$this->log->warning('[Hubspot] Received 429 from API', [
'team_id' => $this->config->team_id,
'config_id' => $this->config->getId(),
'retry_after' => $retryAfter,
'reason' => $e->getMessage(),
]);
throw new RateLimitException('Hubspot returned 429', $retryAfter, $e);
}
throw $e;
}
}
private function getRateLimitCacheKey(): string
{
return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
}
public function isHubspotRateLimit(Throwable $e): bool
{
if ($e instanceof BadRequest
|| $e instanceof DealApiException
|| $e instanceof ContactApiException
|| $e instanceof CompanyApiException
|| $e instanceof \GuzzleHttp\Exception\RequestException
) {
return (int) $e->getCode() === 429;
}
return false;
}
public function parseRetryAfter(Throwable $e): int
{
if (method_exists($e, 'getResponseHeaders')) {
$headers = $e->getResponseHeaders() ?: [];
$value = $headers['Retry-After'] ?? $headers['retry-after'] ?? null;
if (is_array($value)) {
$value = $value[0] ?? null;
}
if (is_numeric($value)) {
return (int) $value;
}
}
$message = strtolower($e->getMessage());
if (str_contains($message, 'daily')) {
return 600;
}
if (str_contains($message, 'ten secondly')) {
return 10;
}
if (str_contains($message, 'secondly')) {
return 1;
}
$this->log->warning('[Hubspot] No retry-after header or known message, using default', [
'exception_class' => get_class($e),
'message' => $message,
]);
return 10;
}
public function getMinimumApiVersion(): string
{
return self::MIN_API_VERSION;
}
public function getInstance(): Factory
{
return new Factory([
'key' => $this->accessToken,
'oauth2' => true,
'base_url' => $this->baseUrl,
]);
}
public function getNewInstance(): Discovery
{
return \HubSpot\Factory::createWithAccessToken($this->accessToken);
}
/**
* Secondly and daily limits for Hubspot API
*
* Product Tier: Free & Starter | Professional & Enterprise | API add-on (any tier)
* Burst: 100/10 seconds | 150/10 seconds | 200/10 seconds
* Daily: 250,000 | 500,000 | 1,000,000
*
* Official documentation states: The search endpoints are rate limited to five requests per second.
* Since with 5 RPS were still hitting secondly rate limits we lowered it to 4
*/
public function getPaginatedData(array $payload, string $type, int $offset = 0): array
{
$total = 0;
$lastId = null;
$rows = [];
foreach ($this->getPaginatedDataGenerator($payload, $type, $offset, $total, $lastId) as $row) {
$rows[] = $row;
}
return ['results' => $rows, 'total' => $total, 'last_record' => $lastId];
}
/**
* @throws HubspotException
* @throws SocialAccountTokenInvalidException
* @throws BadRequest
*/
public function getPaginatedDataGenerator(
array $payload,
string $type,
int $offset = 0,
int &$total = 0,
?string &$lastRecordId = null
): \Generator {
return $this->paginationService->getPaginatedDataGenerator(
$this,
$payload,
$type,
$offset,
$total,
$lastRecordId
);
}
/**
* Execute a search request against HubSpot CRM objects with rate limiting.
*
* @param string $objectType The object type ('deals', 'companies', 'contacts', 'calls')
* @param array<string, mixed> $payload The search payload with filters, sorts, properties, etc.
*
* @throws RateLimitException When rate limit is hit
* @throws HubspotException On API errors
*
* @return array The search response with 'results', 'total', 'paging' keys
*/
public function search(string $objectType, array $payload): array
{
$endpoint = self::BASE_URL . "/crm/v3/objects/{$objectType}/search";
return $this->executeRequest(function () use ($endpoint, $payload) {
$response = $this->getInstance()->getClient()->request('POST', $endpoint, ['json' => $payload]);
return $response->toArray();
});
}
/**
* @throws DealApiException
* @throws CrmException
*/
public function getOpportunityById(string $crmId, array $fields): array
{
try {
$deal = $this->getNewInstance()->crm()->deals()->basicApi()->getById(
$crmId,
implode(',', $fields),
'companies,contacts'
);
} catch (DealApiException $e) {
$this->log->info('[Hubspot] Failed to fetch opportunity', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $deal instanceof DealWithAssociations) {
throw new CrmException('Deal not found');
}
return [
'id' => $deal->getId(),
'properties' => $deal->getProperties(),
'associations' => $deal->getAssociations(),
];
}
/**
* Generic batch read method for HubSpot objects
*
* @param string $objectType The object type ('deals', 'companies', 'contacts')
* @param array<string> $crmIds Array of HubSpot object IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with object data
*/
private function batchReadObjects(string $objectType, array $crmIds, array $fields): array
{
if (empty($crmIds)) {
return [];
}
$this->validateBatchSize($objectType, $crmIds);
$this->ensureValidToken();
try {
$batchConfig = $this->createBatchConfiguration($objectType);
$batchReadRequest = $this->prepareBatchRequest($batchConfig, $crmIds, $fields);
$response = $batchConfig['api']->read($batchReadRequest);
$this->validateApiResponse($response, $objectType);
$results = $this->processApiResults($response);
$this->logBatchResults($objectType, $crmIds, $results);
return $results;
} catch (\Throwable $e) {
$this->handleBatchError($e, $objectType, $crmIds);
}
}
private function validateBatchSize(string $objectType, array $crmIds): void
{
if (count($crmIds) > 100) {
throw new \InvalidArgumentException("Batch size cannot exceed 100 {$objectType}");
}
}
private function createBatchConfiguration(string $objectType): array
{
$configurations = [
'deals' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Deals\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Deals\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->deals()->batchApi(),
],
'companies' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Companies\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Companies\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->companies()->batchApi(),
],
'contacts' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Contacts\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->contacts()->batchApi(),
],
];
if (! isset($configurations[$objectType])) {
throw new \InvalidArgumentException("Unsupported object type: {$objectType}");
}
return $configurations[$objectType];
}
private function prepareBatchRequest(array $batchConfig, array $crmIds, array $fields): object
{
$batchReadRequest = $batchConfig['batchReadRequest'];
$inputClass = $batchConfig['inputClass'];
$inputs = array_map(function ($crmId) use ($inputClass) {
$input = new $inputClass();
$input->setId($crmId);
return $input;
}, $crmIds);
$batchReadRequest->setInputs($inputs);
$batchReadRequest->setProperties($fields);
return $batchReadRequest;
}
private function validateApiResponse($response, string $objectType): void
{
if (! $response) {
throw new CrmException("HubSpot API returned null response for {$objectType} batch read");
}
}
private function processApiResults($response): array
{
$results = [];
$responseResults = $response->getResults();
if ($responseResults) {
foreach ($responseResults as $object) {
if ($object && $object->getId()) {
$results[$object->getId()] = [
'id' => $object->getId(),
'properties' => $object->getProperties() ?: [],
];
}
}
}
return $results;
}
private function logBatchResults(string $objectType, array $crmIds, array $results): void
{
$this->log->info("[HubSpot] Batch fetched {$objectType}", [
'requested_count' => count($crmIds),
'returned_count' => count($results),
'crm_ids' => $crmIds,
]);
}
private function handleBatchError(\Throwable $e, string $objectType, array $crmIds): void
{
$errorMessage = $e->getMessage() ?: 'Unknown error';
$errorTrace = $e->getTraceAsString() ?: 'No trace available';
$this->log->error("[HubSpot] Failed to batch fetch {$objectType}", [
'crm_ids' => $crmIds,
'error' => $errorMessage,
'trace' => $errorTrace,
]);
throw new CrmException("Failed to batch fetch {$objectType}: " . $errorMessage);
}
/**
* Batch read multiple opportunities by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot deal IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with opportunity data
*/
public function getOpportunitiesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('deals', $crmIds, $fields);
}
/**
* Batch read multiple companies by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot company IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with company data
*/
public function getCompaniesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('companies', $crmIds, $fields);
}
/**
* Batch read multiple contacts by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot contact IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with contact data
*/
public function getContactsByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('contacts', $crmIds, $fields);
}
/**
* @throws CompanyApiException
* @throws CrmException
*/
public function getAccountById(string $crmId, array $fields): array
{
try {
$company = $this->getNewInstance()->crm()->companies()->basicApi()->getById(
$crmId,
implode(',', $fields),
);
} catch (CompanyApiException $e) {
$this->log->info('[Hubspot] Failed to fetch account', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $company instanceof CompaniesWithAssociations) {
throw new CrmException('Account not found');
}
return [
'id' => $company->getId(),
'properties' => $company->getProperties(),
];
}
/**
* @throws ContactApiException
* @throws CrmException
*/
public function getContactById(string $crmId, array $fields): array
{
try {
$contact = $this->getNewInstance()->crm()->contacts()->basicApi()->getById(
$crmId,
implode(',', $fields)
Review rate limit handli…, Editor Group 2
remote
app (Git) - JY-20725-handle-HS-search-rate-limit*, Checkout Branch/Tag...
JY-20725-handle-HS-search-rate-limit*
app (Git) - Synchronize Changes
Errors: 6, Warnings: 9, Infos: 2
6
9
2
Notifications
key, PHP extension: Premium features not active.
Sign In
Sign In
Diff editor
Clear
Review rate limit handling for HubSpot job queue
Session history
New session
Message actions
RateLimitException.php#9-9
RateLimitException.php#9-9
Reveiw the diff. Mostly
@app/Jobs/Crm/MatchActivityCrmData.php
,
@app/Exceptions/RateLimitException.php
,
@app/Jobs/Middleware/HandleHubspotRateLimit.php
,
@app/Services/Crm/Hubspot/Client.php
and
@app/Services/Crm/Hubspot/Pagination/HubspotPaginationService.php
. The issue is I am trying to make sure that instant spike of MatchActivityCrmData jobs willl handle 429 exceptions from hubspot. Revewi ti carefully and try to see potential issues and bottlenecks. Also RateLimitException was changerd from LogicException to RuntimeException. Is it ok. This exception is used by other paerts of code. Will ti break anything?
Thought for 5s
Thought for 5s
I'll review the implementation carefully. Let me first check how
RateLimitException
is used elsewhere and look at the test files and
PaginationState
.
Bash
Find all usages of RateLimitException outside the changed files
IN
grep -rn "RateLimitException" /Users/lukas/jiminny/app/app --include="*.php" | grep -v "HandleHubspotRateLimit\|MatchActivityCrmData\|Client.php\|RateLimitException.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:13:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
/Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php:17:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php:68: RateLimitException |
/Users/lukas/jiminny/app/app/Component/TranscriptionSummary/Jobs/SummarizeTranscriptionJob.php:15:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/TranscriptionSummary/Jobs/SummarizeTranscriptionJob.php:58: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
/Users/lukas/jiminny/app/app/Component/AiActivityType/Jobs/GenerateAiActivityTypeJob.php:19:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/AiActivityType/Jobs/GenerateAiActivityTypeJob.php:76: RateLimitException |
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/HubspotClientInterface.php:8:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/HubspotClientInterface.php:50: * @throws RateLimitException When rate limit is hit
/Users/lukas/jiminny/app/app/Services/Crm/Hubspot/Pagination/HubspotPaginationService.php:195: // RateLimitException and other exceptions are re-thrown as-is
Read
PaginationState.php
PaginationState.php
Read
HandleHubspotRateLimitTest.php
HandleHubspotRateLimitTest.php
Bash
Check how RateLimitException is used in GenerateActionItemsJob
IN
grep -rn "RateLimitException\|LogicException\|RuntimeException" /Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php | head -20
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:13:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php:51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
Bash
Find all catch blocks or instanceof checks for RateLimitException
IN
grep -rn "catch.*RateLimitException\|instanceof RateLimitException" /Users/lukas/jiminny/app/app --include="*.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Jobs/Middleware/HandleHubspotRateLimit.php:11: * Job middleware that catches RateLimitException from HubSpot API calls
/Users/lukas/jiminny/app/app/Jobs/Middleware/HandleHubspotRateLimit.php:24: } catch (RateLimitException $e) {
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:149: if (! $e instanceof RateLimitException) {
Bash
Find all test references to RateLimitException
IN
grep -rn "RateLimitException" /Users/lukas/jiminny/app/tests --include="*.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:8:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:13:#[CoversClass(RateLimitException::class)]
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:14:class RateLimitExceptionTest extends TestCase
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:18: $exception = new RateLimitException();
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:28: $exception = new RateLimitException('Hubspot rate limit', 30, $previous);
/Users/lukas/jiminny/app/tests/Unit/Exceptions/RateLimitExceptionTest.php:52: $exception = new RateLimitException('test', $input);
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:10:use Jiminny\Exceptions\RateLimitException;
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:49: public function testPropagatesNonRateLimitExceptions(): void
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:103: throw new RateLimitException('rate limited', $retryAfter);
/Users/lukas/jiminny/app/tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.php:150: throw new RateLimitException('rate limited', 1);
Bash
Check retry/failure handling in GenerateActionItemsJob
IN
grep -n "RateLimitException\|retryUntil\|backoff\|maxExceptions\|maxTries\|release\|failed" /Users/lukas/jiminny/app/app/Component/ActionItems/Jobs/GenerateActionItemsJob.php | head -30
Copy code to clipboard
OUT
13:use Jiminny\Exceptions\RateLimitException;
51: GuzzleException|HttpBadRequestException|JsonException|RateLimitException|UnexpectedValueException $exception
56: $this->release(30);
Bash
Check retry/failure handling in GenerateAiCallScoringJob
IN
grep -n "RateLimitException\|retryUntil\|backoff\|maxExceptions\|maxTries\|release\|failed" /Users/lukas/jiminny/app/app/Component/AiCallScoring/Jobs/GenerateAiCallScoringJob.php | head -30
Copy code to clipboard
OUT
17:use Jiminny\Exceptions\RateLimitException;
68: RateLimitException |
75: $this->release(30);
Bash
Check retry config in MatchActivityCrmData
IN
grep -n "retryAfter\|RETRY_WINDOW\|retryUntil\|maxTries" /Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php
Copy code to clipboard
OUT
34: private const int RETRY_WINDOW_MINUTES = 30;
45: public function retryUntil(): \DateTimeInterface
47: return now()->addMinutes(self::RETRY_WINDOW_MINUTES);
77: return self::RETRY_WINDOW_MINUTES * 60 + 60;
Bash
Check the cache key format
IN
grep -n "getRateLimitCacheKey\|hubspot:ratelimit" /Users/lukas/jiminny/app/app/Services/Crm/Hubspot/Client.php
Copy code to clipboard
OUT
78: $cacheKey = $this->getRateLimitCacheKey();
110: private function getRateLimitCacheKey(): string
112: return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
Bash
Find other jobs that might use the rate limit middleware
IN
grep -rn "class.*Middleware\|HandleHubspotRateLimit" /Users/lukas/jiminny/app/app/Jobs --include="*.php" | grep -v "HandleHubspotRateLimit.php"
Copy code to clipboard
OUT
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:18:use Jiminny\Jobs\Middleware\HandleHubspotRateLimit;
/Users/lukas/jiminny/app/app/Jobs/Crm/MatchActivityCrmData.php:42: return [new HandleHubspotRateLimit()];
Read
HubspotClientInterface.php
HubspotClientInterface.php
Thought for 73s
Thought for 73s
Now I have a complete picture. Here's my full analysis:
Review Summary
Review Summary
RuntimeException vs LogicException — Safe ✓
RuntimeException
vs
LogicException
— Safe ✓
The change is semantically correct and won't break anything.
LogicException
is for programmer errors (invalid arguments, contract violations). A rate limit from an external API is a runtime condition —
RuntimeException
is the right parent. All callers catch
RateLimitException
by name explicitly (union catches in
GenerateActionItemsJob
,
GenerateAiCallScoringJob
,
SummarizeTranscriptionJob
,
GenerateAiActivityTypeJob
) or check
instanceof RateLimitException
— none relies on the parent class type, so nothing breaks.
Issue 1 — Circuit breaker stores stale delay (most important bug)
Issue 1 — Circuit breaker stores stale delay (most important bug)
Client.php:94
Client.php:94
Copy code to clipboard
Redis::setex($cacheKey, $retryAfter, (string) $retryAfter);
The TTL is
$retryAfter
seconds, but the
stored value
is also the original
$retryAfter
. If a second job reads this cache 20 seconds later, it throws
RateLimitException(retryAfter=30)
and gets delayed 30 more seconds — even though only 10 remain. In a spike of 100 jobs, each subsequent job inflates its wait.
Fix:
store the absolute expiry timestamp, reconstruct the remaining delay when reading:
Copy code to clipboard
// on 429:
Redis::setex($cacheKey, $retryAfter, (string) (time() + $retryAfter));
// in the cached-read branch:
$remaining = max(1, (int) $cachedRetryAfter - time());
throw new RateLimitException('Hubspot rate limit (cached circuit-breaker)', $remaining);
Issue 2 — retryUntil() window may expire under sustained rate limiting
Issue 2 —
retryUntil()
window may expire under sustained rate limiting
MatchActivityCrmData.php:45-47
MatchActivityCrmData.php:45-47
retryUntil()
is calculated as
now() + 30 min
at
dispatch time
and stored in the job payload. With
MAX_RETRY_DELAY = 600s
, you only get ~3 rate-limit-triggered releases before the 30-minute window closes and the job is permanently failed. For a heavy 429 spike (daily limit, parsed as 600s), this can easily happen.
Consider increasing
RETRY_WINDOW_MINUTES
to 60 or more, or making it configurable. The
uniqueFor()
value should be updated to match.
Issue 3 — Only search() uses the circuit breaker, but other methods can still hit 429
Issue 3 — Only
search()
uses the circuit breaker, but other methods can still hit 429...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20028
|
|
20029
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
FieldTypeConverter.php
HubspotClientInterface.php
HubspotTokenManager.php
PayloadBuilder.php
RemoteCrmObjectManipulator.php
ResponseNormalize.php
Service.php
SyncFieldAction.php
SyncRelatedActivityManager.php
WebhookSyncBatchProcessor.php
IntegrationApp
Listeners
Metadata
Migration
Pipedrive
OpportunitySyncStrategy
ProspectSearchStrategy
ApiFields.php
OpportunitySyncStrategy
Hubspot
Crm
Services
app
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
MySQL Section
MYSQL
MYSQL
MatchActivityCrmData.php, Editor Group 1
RateLimitException.php, Editor Group 1
HandleHubspotRateLimit.php, Editor Group 1
Client.php, Editor Group 1
HubspotPaginationService.php, Editor Group 1
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm\Hubspot;
use HubSpot\Client\Crm\Deals\ApiException as DealApiException;
use HubSpot\Client\Crm\Contacts\ApiException as ContactApiException;
use HubSpot\Client\Crm\Companies\ApiException as CompanyApiException;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations as ContactsWithAssociations;
use HubSpot\Client\Crm\Companies\Model\SimplePublicObjectWithAssociations as CompaniesWithAssociations;
use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations as DealWithAssociations;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectInput;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectWithAssociations as ObjectWithAssociations;
use HubSpot\Client\Crm\Pipelines\Model\Error;
use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;
use HubSpot\Client\Crm\Properties\Model\Property;
use HubSpot\Discovery\Discovery;
use Jiminny\Exceptions\CrmException;
use Jiminny\Exceptions\RateLimitException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Jobs\Crm\NoteObject;
use Jiminny\Models\Crm\Field;
use Jiminny\Services\Crm\BaseClient;
use Jiminny\Services\Crm\Hubspot\DTO\Response\Owner;
use Jiminny\Services\SocialAccountService;
use SevenShores\Hubspot\Exceptions\BadRequest;
use SevenShores\Hubspot\Exceptions\HubspotException;
use SevenShores\Hubspot\Factory;
use SevenShores\Hubspot\Http\Response;
use Jiminny\Services\Crm\Hubspot\Pagination\HubspotPaginationService;
use Illuminate\Support\Facades\Redis;
use Throwable;
/**
* @phpstan-type CrmFieldOption array{id:string, label:string, value?:string}
*/
class Client extends BaseClient implements HubspotClientInterface
{
public const string MIN_API_VERSION = '2';
public const string BASE_URL = '[URL_WITH_CREDENTIALS] T
*
* @param callable(): T $apiCall The API call to execute
*
* @throws RateLimitException When rate limit is hit or cached rate limit is active
*
* @return T The result of the API call
*/
private function executeRequest(callable $apiCall)
{
$cacheKey = $this->getRateLimitCacheKey();
$cachedExpiresAt = Redis::get($cacheKey);
if (is_string($cachedExpiresAt) && is_numeric($cachedExpiresAt)) {
$remaining = max(1, (int) $cachedExpiresAt - time());
throw new RateLimitException(
'Hubspot rate limit (cached circuit-breaker)',
$remaining,
);
}
try {
return $apiCall();
} catch (Throwable $e) {
if ($this->isHubspotRateLimit($e)) {
$retryAfter = $this->parseRetryAfter($e);
// NX: only the first job to receive a 429 in this burst sets the key.
// Subsequent 429s in the same burst leave the TTL untouched so the
// window is not reset by every concurrent job hitting the limit.
Redis::set($cacheKey, (string) (time() + $retryAfter), ['nx', 'ex' => $retryAfter]);
$this->log->warning('[Hubspot] Received 429 from API', [
'team_id' => $this->config->team_id,
'config_id' => $this->config->getId(),
'retry_after' => $retryAfter,
'reason' => $e->getMessage(),
]);
throw new RateLimitException('Hubspot returned 429', $retryAfter, $e);
}
throw $e;
}
}
private function getRateLimitCacheKey(): string
{
return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
}
public function isHubspotRateLimit(Throwable $e): bool
{
if ($e instanceof BadRequest
|| $e instanceof DealApiException
|| $e instanceof ContactApiException
|| $e instanceof CompanyApiException
|| $e instanceof \GuzzleHttp\Exception\RequestException
) {
return (int) $e->getCode() === 429;
}
return false;
}
public function parseRetryAfter(Throwable $e): int
{
if (method_exists($e, 'getResponseHeaders')) {
$headers = $e->getResponseHeaders() ?: [];
$value = $headers['Retry-After'] ?? $headers['retry-after'] ?? null;
if (is_array($value)) {
$value = $value[0] ?? null;
}
if (is_numeric($value)) {
return (int) $value;
}
}
$message = strtolower($e->getMessage());
if (str_contains($message, 'daily')) {
return 600;
}
if (str_contains($message, 'ten secondly')) {
return 10;
}
if (str_contains($message, 'secondly')) {
return 1;
}
$this->log->warning('[Hubspot] No retry-after header or known message, using default', [
'exception_class' => get_class($e),
'message' => $message,
]);
return 10;
}
public function getMinimumApiVersion(): string
{
return self::MIN_API_VERSION;
}
public function getInstance(): Factory
{
return new Factory([
'key' => $this->accessToken,
'oauth2' => true,
'base_url' => $this->baseUrl,
]);
}
public function getNewInstance(): Discovery
{
return \HubSpot\Factory::createWithAccessToken($this->accessToken);
}
/**
* Secondly and daily limits for Hubspot API
*
* Product Tier: Free & Starter | Professional & Enterprise | API add-on (any tier)
* Burst: 100/10 seconds | 150/10 seconds | 200/10 seconds
* Daily: 250,000 | 500,000 | 1,000,000
*
* Official documentation states: The search endpoints are rate limited to five requests per second.
* Since with 5 RPS were still hitting secondly rate limits we lowered it to 4
*/
public function getPaginatedData(array $payload, string $type, int $offset = 0): array
{
$total = 0;
$lastId = null;
$rows = [];
foreach ($this->getPaginatedDataGenerator($payload, $type, $offset, $total, $lastId) as $row) {
$rows[] = $row;
}
return ['results' => $rows, 'total' => $total, 'last_record' => $lastId];
}
/**
* @throws HubspotException
* @throws SocialAccountTokenInvalidException
* @throws BadRequest
*/
public function getPaginatedDataGenerator(
array $payload,
string $type,
int $offset = 0,
int &$total = 0,
?string &$lastRecordId = null
): \Generator {
return $this->paginationService->getPaginatedDataGenerator(
$this,
$payload,
$type,
$offset,
$total,
$lastRecordId
);
}
/**
* Execute a search request against HubSpot CRM objects with rate limiting.
*
* @param string $objectType The object type ('deals', 'companies', 'contacts', 'calls')
* @param array<string, mixed> $payload The search payload with filters, sorts, properties, etc.
*
* @throws RateLimitException When rate limit is hit
* @throws HubspotException On API errors
*
* @return array The search response with 'results', 'total', 'paging' keys
*/
public function search(string $objectType, array $payload): array
{
$endpoint = self::BASE_URL . "/crm/v3/objects/{$objectType}/search";
return $this->executeRequest(function () use ($endpoint, $payload) {
$response = $this->getInstance()->getClient()->request('POST', $endpoint, ['json' => $payload]);
return $response->toArray();
});
}
/**
* @throws DealApiException
* @throws CrmException
*/
public function getOpportunityById(string $crmId, array $fields): array
{
try {
$deal = $this->getNewInstance()->crm()->deals()->basicApi()->getById(
$crmId,
implode(',', $fields),
'companies,contacts'
);
} catch (DealApiException $e) {
$this->log->info('[Hubspot] Failed to fetch opportunity', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $deal instanceof DealWithAssociations) {
throw new CrmException('Deal not found');
}
return [
'id' => $deal->getId(),
'properties' => $deal->getProperties(),
'associations' => $deal->getAssociations(),
];
}
/**
* Generic batch read method for HubSpot objects
*
* @param string $objectType The object type ('deals', 'companies', 'contacts')
* @param array<string> $crmIds Array of HubSpot object IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with object data
*/
private function batchReadObjects(string $objectType, array $crmIds, array $fields): array
{
if (empty($crmIds)) {
return [];
}
$this->validateBatchSize($objectType, $crmIds);
$this->ensureValidToken();
try {
$batchConfig = $this->createBatchConfiguration($objectType);
$batchReadRequest = $this->prepareBatchRequest($batchConfig, $crmIds, $fields);
$response = $batchConfig['api']->read($batchReadRequest);
$this->validateApiResponse($response, $objectType);
$results = $this->processApiResults($response);
$this->logBatchResults($objectType, $crmIds, $results);
return $results;
} catch (\Throwable $e) {
$this->handleBatchError($e, $objectType, $crmIds);
}
}
private function validateBatchSize(string $objectType, array $crmIds): void
{
if (count($crmIds) > 100) {
throw new \InvalidArgumentException("Batch size cannot exceed 100 {$objectType}");
}
}
private function createBatchConfiguration(string $objectType): array
{
$configurations = [
'deals' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Deals\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Deals\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->deals()->batchApi(),
],
'companies' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Companies\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Companies\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->companies()->batchApi(),
],
'contacts' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Contacts\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->contacts()->batchApi(),
],
];
if (! isset($configurations[$objectType])) {
throw new \InvalidArgumentException("Unsupported object type: {$objectType}");
}
return $configurations[$objectType];
}
private function prepareBatchRequest(array $batchConfig, array $crmIds, array $fields): object
{
$batchReadRequest = $batchConfig['batchReadRequest'];
$inputClass = $batchConfig['inputClass'];
$inputs = array_map(function ($crmId) use ($inputClass) {
$input = new $inputClass();
$input->setId($crmId);
return $input;
}, $crmIds);
$batchReadRequest->setInputs($inputs);
$batchReadRequest->setProperties($fields);
return $batchReadRequest;
}
private function validateApiResponse($response, string $objectType): void
{
if (! $response) {
throw new CrmException("HubSpot API returned null response for {$objectType} batch read");
}
}
private function processApiResults($response): array
{
$results = [];
$responseResults = $response->getResults();
if ($responseResults) {
foreach ($responseResults as $object) {
if ($object && $object->getId()) {
$results[$object->getId()] = [
'id' => $object->getId(),
'properties' => $object->getProperties() ?: [],
];
}
}
}
return $results;
}
private function logBatchResults(string $objectType, array $crmIds, array $results): void
{
$this->log->info("[HubSpot] Batch fetched {$objectType}", [
'requested_count' => count($crmIds),
'returned_count' => count($results),
'crm_ids' => $crmIds,
]);
}
private function handleBatchError(\Throwable $e, string $objectType, array $crmIds): void
{
$errorMessage = $e->getMessage() ?: 'Unknown error';
$errorTrace = $e->getTraceAsString() ?: 'No trace available';
$this->log->error("[HubSpot] Failed to batch fetch {$objectType}", [
'crm_ids' => $crmIds,
'error' => $errorMessage,
'trace' => $errorTrace,
]);
throw new CrmException("Failed to batch fetch {$objectType}: " . $errorMessage);
}
/**
* Batch read multiple opportunities by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot deal IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with opportunity data
*/
public function getOpportunitiesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('deals', $crmIds, $fields);
}
/**
* Batch read multiple companies by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot company IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with company data
*/
public function getCompaniesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('companies', $crmIds, $fields);
}
/**
* Batch read multiple contacts by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot contact IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with contact data
*/
public function getContactsByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('contacts', $crmIds, $fields);
}
/**
* @throws CompanyApiException
* @throws CrmException
*/
public function getAccountById(string $crmId, array $fields): array
{
try {
$company = $this->getNewInstance()->crm()->companies()->basicApi()->getById(
$crmId,
implode(',', $fields),
);
} catch (CompanyApiException $e) {
$this->log->info('[Hubspot] Failed to fetch account', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $company instanceof CompaniesWithAssociations) {
throw new CrmException('Account not found');
}
return [
'id' => $company->getId(),
'properties' => $company->getProperties(),
];
}
/**
* @throws ContactApiException
* @throws CrmException
*/
public function getContactById(string $crmId, array $fields): array
{
try {
$contact = $this->getNewInstance()->crm()->contacts()->basicApi()->getById(
$crmId,
implode(',', $fields)
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm\Hubspot;
use HubSpot\Client\Crm\Deals\ApiException as DealApiException;
use HubSpot\Client\Crm\Contacts\ApiException as ContactApiException;
use HubSpot\Client\Crm\Companies\ApiException as CompanyApiException;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations as ContactsWithAssociations;
use HubSpot\Client\Crm\Companies\Model\SimplePublicObjectWithAssociations as CompaniesWithAssociations;
use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectWithAssociations as DealWithAssociations;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectInput;
use HubSpot\Client\Crm\Objects\Model\SimplePublicObjectWithAssociations as ObjectWithAssociations;
use HubSpot\Client\Crm\Pipelines\Model\Error;
use HubSpot\Client\Crm\Pipelines\Model\PipelineStage;
use HubSpot\Client\Crm\Properties\Model\Property;
use HubSpot\Discovery\Discovery;
use Jiminny\Exceptions\CrmException;
use Jiminny\Exceptions\RateLimitException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Jobs\Crm\NoteObject;
use Jiminny\Models\Crm\Field;
use Jiminny\Services\Crm\BaseClient;
use Jiminny\Services\Crm\Hubspot\DTO\Response\Owner;
use Jiminny\Services\SocialAccountService;
use SevenShores\Hubspot\Exceptions\BadRequest;
use SevenShores\Hubspot\Exceptions\HubspotException;
use SevenShores\Hubspot\Factory;
use SevenShores\Hubspot\Http\Response;
use Jiminny\Services\Crm\Hubspot\Pagination\HubspotPaginationService;
use Illuminate\Support\Facades\Redis;
use Throwable;
/**
* @phpstan-type CrmFieldOption array{id:string, label:string, value?:string}
*/
class Client extends BaseClient implements HubspotClientInterface
{
public const string MIN_API_VERSION = '2';
public const string BASE_URL = '[URL_WITH_CREDENTIALS] T
*
* @param callable(): T $apiCall The API call to execute
*
* @throws RateLimitException When rate limit is hit or cached rate limit is active
*
* @return T The result of the API call
*/
private function executeRequest(callable $apiCall)
{
$cacheKey = $this->getRateLimitCacheKey();
$cachedExpiresAt = Redis::get($cacheKey);
if (is_string($cachedExpiresAt) && is_numeric($cachedExpiresAt)) {
$remaining = max(1, (int) $cachedExpiresAt - time());
throw new RateLimitException(
'Hubspot rate limit (cached circuit-breaker)',
$remaining,
);
}
try {
return $apiCall();
} catch (Throwable $e) {
if ($this->isHubspotRateLimit($e)) {
$retryAfter = $this->parseRetryAfter($e);
// NX: only the first job to receive a 429 in this burst sets the key.
// Subsequent 429s in the same burst leave the TTL untouched so the
// window is not reset by every concurrent job hitting the limit.
Redis::set($cacheKey, (string) (time() + $retryAfter), ['nx', 'ex' => $retryAfter]);
$this->log->warning('[Hubspot] Received 429 from API', [
'team_id' => $this->config->team_id,
'config_id' => $this->config->getId(),
'retry_after' => $retryAfter,
'reason' => $e->getMessage(),
]);
throw new RateLimitException('Hubspot returned 429', $retryAfter, $e);
}
throw $e;
}
}
private function getRateLimitCacheKey(): string
{
return sprintf('hubspot:ratelimit:portal:%d', $this->config->getId());
}
public function isHubspotRateLimit(Throwable $e): bool
{
if ($e instanceof BadRequest
|| $e instanceof DealApiException
|| $e instanceof ContactApiException
|| $e instanceof CompanyApiException
|| $e instanceof \GuzzleHttp\Exception\RequestException
) {
return (int) $e->getCode() === 429;
}
return false;
}
public function parseRetryAfter(Throwable $e): int
{
if (method_exists($e, 'getResponseHeaders')) {
$headers = $e->getResponseHeaders() ?: [];
$value = $headers['Retry-After'] ?? $headers['retry-after'] ?? null;
if (is_array($value)) {
$value = $value[0] ?? null;
}
if (is_numeric($value)) {
return (int) $value;
}
}
$message = strtolower($e->getMessage());
if (str_contains($message, 'daily')) {
return 600;
}
if (str_contains($message, 'ten secondly')) {
return 10;
}
if (str_contains($message, 'secondly')) {
return 1;
}
$this->log->warning('[Hubspot] No retry-after header or known message, using default', [
'exception_class' => get_class($e),
'message' => $message,
]);
return 10;
}
public function getMinimumApiVersion(): string
{
return self::MIN_API_VERSION;
}
public function getInstance(): Factory
{
return new Factory([
'key' => $this->accessToken,
'oauth2' => true,
'base_url' => $this->baseUrl,
]);
}
public function getNewInstance(): Discovery
{
return \HubSpot\Factory::createWithAccessToken($this->accessToken);
}
/**
* Secondly and daily limits for Hubspot API
*
* Product Tier: Free & Starter | Professional & Enterprise | API add-on (any tier)
* Burst: 100/10 seconds | 150/10 seconds | 200/10 seconds
* Daily: 250,000 | 500,000 | 1,000,000
*
* Official documentation states: The search endpoints are rate limited to five requests per second.
* Since with 5 RPS were still hitting secondly rate limits we lowered it to 4
*/
public function getPaginatedData(array $payload, string $type, int $offset = 0): array
{
$total = 0;
$lastId = null;
$rows = [];
foreach ($this->getPaginatedDataGenerator($payload, $type, $offset, $total, $lastId) as $row) {
$rows[] = $row;
}
return ['results' => $rows, 'total' => $total, 'last_record' => $lastId];
}
/**
* @throws HubspotException
* @throws SocialAccountTokenInvalidException
* @throws BadRequest
*/
public function getPaginatedDataGenerator(
array $payload,
string $type,
int $offset = 0,
int &$total = 0,
?string &$lastRecordId = null
): \Generator {
return $this->paginationService->getPaginatedDataGenerator(
$this,
$payload,
$type,
$offset,
$total,
$lastRecordId
);
}
/**
* Execute a search request against HubSpot CRM objects with rate limiting.
*
* @param string $objectType The object type ('deals', 'companies', 'contacts', 'calls')
* @param array<string, mixed> $payload The search payload with filters, sorts, properties, etc.
*
* @throws RateLimitException When rate limit is hit
* @throws HubspotException On API errors
*
* @return array The search response with 'results', 'total', 'paging' keys
*/
public function search(string $objectType, array $payload): array
{
$endpoint = self::BASE_URL . "/crm/v3/objects/{$objectType}/search";
return $this->executeRequest(function () use ($endpoint, $payload) {
$response = $this->getInstance()->getClient()->request('POST', $endpoint, ['json' => $payload]);
return $response->toArray();
});
}
/**
* @throws DealApiException
* @throws CrmException
*/
public function getOpportunityById(string $crmId, array $fields): array
{
try {
$deal = $this->getNewInstance()->crm()->deals()->basicApi()->getById(
$crmId,
implode(',', $fields),
'companies,contacts'
);
} catch (DealApiException $e) {
$this->log->info('[Hubspot] Failed to fetch opportunity', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $deal instanceof DealWithAssociations) {
throw new CrmException('Deal not found');
}
return [
'id' => $deal->getId(),
'properties' => $deal->getProperties(),
'associations' => $deal->getAssociations(),
];
}
/**
* Generic batch read method for HubSpot objects
*
* @param string $objectType The object type ('deals', 'companies', 'contacts')
* @param array<string> $crmIds Array of HubSpot object IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with object data
*/
private function batchReadObjects(string $objectType, array $crmIds, array $fields): array
{
if (empty($crmIds)) {
return [];
}
$this->validateBatchSize($objectType, $crmIds);
$this->ensureValidToken();
try {
$batchConfig = $this->createBatchConfiguration($objectType);
$batchReadRequest = $this->prepareBatchRequest($batchConfig, $crmIds, $fields);
$response = $batchConfig['api']->read($batchReadRequest);
$this->validateApiResponse($response, $objectType);
$results = $this->processApiResults($response);
$this->logBatchResults($objectType, $crmIds, $results);
return $results;
} catch (\Throwable $e) {
$this->handleBatchError($e, $objectType, $crmIds);
}
}
private function validateBatchSize(string $objectType, array $crmIds): void
{
if (count($crmIds) > 100) {
throw new \InvalidArgumentException("Batch size cannot exceed 100 {$objectType}");
}
}
private function createBatchConfiguration(string $objectType): array
{
$configurations = [
'deals' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Deals\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Deals\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->deals()->batchApi(),
],
'companies' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Companies\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Companies\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->companies()->batchApi(),
],
'contacts' => [
'batchReadRequest' => new \HubSpot\Client\Crm\Contacts\Model\BatchReadInputSimplePublicObjectId(),
'inputClass' => \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectId::class,
'api' => $this->getNewInstance()->crm()->contacts()->batchApi(),
],
];
if (! isset($configurations[$objectType])) {
throw new \InvalidArgumentException("Unsupported object type: {$objectType}");
}
return $configurations[$objectType];
}
private function prepareBatchRequest(array $batchConfig, array $crmIds, array $fields): object
{
$batchReadRequest = $batchConfig['batchReadRequest'];
$inputClass = $batchConfig['inputClass'];
$inputs = array_map(function ($crmId) use ($inputClass) {
$input = new $inputClass();
$input->setId($crmId);
return $input;
}, $crmIds);
$batchReadRequest->setInputs($inputs);
$batchReadRequest->setProperties($fields);
return $batchReadRequest;
}
private function validateApiResponse($response, string $objectType): void
{
if (! $response) {
throw new CrmException("HubSpot API returned null response for {$objectType} batch read");
}
}
private function processApiResults($response): array
{
$results = [];
$responseResults = $response->getResults();
if ($responseResults) {
foreach ($responseResults as $object) {
if ($object && $object->getId()) {
$results[$object->getId()] = [
'id' => $object->getId(),
'properties' => $object->getProperties() ?: [],
];
}
}
}
return $results;
}
private function logBatchResults(string $objectType, array $crmIds, array $results): void
{
$this->log->info("[HubSpot] Batch fetched {$objectType}", [
'requested_count' => count($crmIds),
'returned_count' => count($results),
'crm_ids' => $crmIds,
]);
}
private function handleBatchError(\Throwable $e, string $objectType, array $crmIds): void
{
$errorMessage = $e->getMessage() ?: 'Unknown error';
$errorTrace = $e->getTraceAsString() ?: 'No trace available';
$this->log->error("[HubSpot] Failed to batch fetch {$objectType}", [
'crm_ids' => $crmIds,
'error' => $errorMessage,
'trace' => $errorTrace,
]);
throw new CrmException("Failed to batch fetch {$objectType}: " . $errorMessage);
}
/**
* Batch read multiple opportunities by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot deal IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with opportunity data
*/
public function getOpportunitiesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('deals', $crmIds, $fields);
}
/**
* Batch read multiple companies by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot company IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with company data
*/
public function getCompaniesByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('companies', $crmIds, $fields);
}
/**
* Batch read multiple contacts by their CRM IDs
*
* @param array<string> $crmIds Array of HubSpot contact IDs (max 100)
* @param array<string> $fields Array of property names to fetch
*
* @return array<string, array> Array keyed by CRM ID with contact data
*/
public function getContactsByIds(array $crmIds, array $fields): array
{
return $this->batchReadObjects('contacts', $crmIds, $fields);
}
/**
* @throws CompanyApiException
* @throws CrmException
*/
public function getAccountById(string $crmId, array $fields): array
{
try {
$company = $this->getNewInstance()->crm()->companies()->basicApi()->getById(
$crmId,
implode(',', $fields),
);
} catch (CompanyApiException $e) {
$this->log->info('[Hubspot] Failed to fetch account', [
'crm_id' => $crmId,
'reason' => $e->getMessage(),
]);
throw $e;
}
if (! $company instanceof CompaniesWithAssociations) {
throw new CrmException('Account not found');
}
return [
'id' => $company->getId(),
'properties' => $company->getProperties(),
];
}
/**
* @throws ContactApiException
* @throws CrmException
*/
public function getContactById(string $crmId, array $fields): array
{
try {
$contact = $this->getNewInstance()->crm()->contacts()->basicApi()->getById(
$crmId,
implode(',', $fields)
Review rate limit handli…, Editor Group 2
remote
app (Git) - JY-20725-handle-HS-search-rate-limit*, Checkout Branch/Tag...
JY-20725-handle-HS-search-rate-limit*
app (Git) - Synchronize Changes
Errors: 6, Warnings: 9, Infos: 2
6
9
2
Notifications
key, PHP extension: Premium features not active.
Sign In
Sign In
Diff editor
Clear
Review rate limit handling for HubSpot job queue
Session history
New session
Message actions
RateLimitException.php#9-9
RateLimitException.php#9-9...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20029
|
|
20030
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20030
|
|
20031
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
FieldTypeConverter.php
HubspotClientInterface.php
HubspotTokenManager.php
PayloadBuilder.php
RemoteCrmObjectManipulator.php
ResponseNormalize.php
Service.php
SyncFieldAction.php
SyncRelatedActivityManager.php
WebhookSyncBatchProcessor.php
IntegrationApp
Listeners
Metadata
Migration
Pipedrive
OpportunitySyncStrategy
ProspectSearchStrategy
ApiFields.php
OpportunitySyncStrategy
Hubspot
Crm
Services
app
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20031
|
|
20032
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20032
|
|
20033
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Client.php 9 xV APPapp > Services > Crm › Hubspot › f* Client.php › °g Client › parseRetryAfter()class Client extends Baseclient 1mpLements HubspotclientiIntertacepub lic tunction 1sHubspotRateL1m1t Throwable Se : bool123134137• Hubspol~OpportunitySynestrategy..• HubsnotLastModified@nenSvncStra..# HubspotLastModifiedSyncStrategy....# HubsootSinaleSyncstrategy.onp## HubspotSyncStrategyBase.php• HubsnotWebhookBatchSyncstrateg.Wwlallawwaa# HubspotPaginationService.php# PaginationConfig.php# PaginationState.phpProspectsearchstrategy→Hoal~ Servicelraits# OpportunitySyncTrait.php• SvncCrmEntitiesTrait.phpwsuncrields.rait.ono• WriteCrmTrait.phr• Utils• WebhookBatchSvncCollector.ohoBatchSvncRedisService.ohvClient.oho* ClosedDealStagesService.oho* DealFieldsService.oho* DecorateActivitv.oho•FieldDefinitions.ohn|• FieldTvoeConverter.oho# HubspotClientinterface.php# HubspotTokenManager.phpR PayloadBuilder.php* PemoteCrmObiectManinulator.nhn«* PecnonceNormalize nhn• Service.php# SyncFieldAction.php# SyncRelatedActivityManager.php# WebhookSyncBatchProcessor.php> IntearationApp• Listeners> Metadata• MiarationV Pipedrive• OpportunitySvncStrateavProspectSearchStrateavOUTIINETIMELINGi8 JY-20725-handle-HS-search-rate-limit* ©pud L1c• tunction-parseretryArter(Tnrowable se):•1nc1t• method exists se,'getResponseMeaders"))•‹Sheaders =Se->aetResoonseHeaderso-?:-0*$value = $headers ('Retry-After')•?? Sheaders['retry-after')•?? null;$value = $value [0] •22-null;if. (1s numeric(svatue)). +Smessage = strtolower($e->getMessage));it• (sur contains(smessage, ' dally y)'1if• (str_contains(Smessage,'ten secondly")) •{return-10:if• (str_contains($message, 'secondly')) -{return-1;Sthis->loq->warning(* (Hubspot)•No retry-after header or known message, using default'.•lget_class($e),message" .= Smessage.return.10.public function getMinimumApiVersion(): stringreturn celf.-MTN ApT VERSTON.public function getInstance(): Factory= Sthis→>accesstoken,'oauth?'''base url => Sthis->baseUruoublic function aetNewinstance: Discovervreturn HubSpot\Factorv::createWithAccessToken/Sthis-saccessToken@6A902|S0 hh100% LzMon 11 May 17:21:26•2 C3→= Review rate limit handli... X*mA .•Review rate limit handling for HubSpot jo.<› Client.ohn#62-168Add coverage of new methods in Client public function search(string $objectType, array Spayload): arrayfind lopt/homebrew /usr/local -name "ohp" -tvpe f 2>/dev/null | head -5OUT (Bash completed with no output)• Bash Check phpunit shebang to find PHP pathhead -1 /Users/lukas/liminny/aoo/vendor/bin/ohounitout #!/usr/bin/env php• Bash Check Makefile for test commandscat /lsers/lukas/iiminnv/aoo/Makefile 2>/dev/null | aren -i test I head -20rest-branch: rest-backend-phounz-cached-name-statne -dilff filter Ad develonantefnen -l "Aann/ewanhn"aren ey "Aano/(Consalle/(Commandelnen -v "Aann/ModelKlnren ey "Aann/Httn/d• Bash Find Docker command pattern in Makefilecat /Users/lukas/iiminny/aoo/Makefile l aren -A3 "DOCKER COMMAND) Idocker execl lohounit" | head —30OUT DOCKER COMMAND=docker exec -it docker lamp 1helne• Bash Run new ClientTest methods inside DockerTwdocker exec. dockerlamovendor//hin/nhounilt_tests/nit//Services//dam/Hubsnot//@lientTest.nhn.=filter-ltestSearchlltestsHihsootRateEmfIltestParseRetrvAfiter"=no=coverane.2201llltafliAllow this bash command?docker exec docker lamp 1 vendor/bin/phpunitRun new ClientTest methods inside Docker11 Yes7 Yes, alllow docker eyec * for alll proiects3 NoTall Claudh what te de tnatradlEsc to cancel8 SignIn...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20033
|
|
20034
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
SlackFileEditViewGoHistoryWindowHelpAPP ()DOCKER0 *1DEV (docker)₴2APP (-zsh)-zsh* @param string SobjectType The object type('deals''companies''contacts''cal)* @param array<string, mixed›Spayload Thesearch payload with filters, sorts, prop‹* @return array The search response with'results''total'*'paging'keys* @throws RateLimitException When rate limit is hit* @throws HubspotException On API errors** @return array The search response with 'results', 'total', 'paging' keys*/public function search(string SobjectType, array Spayload): arrayend diff4) app/Console/Commands/JiminnyDebugCommand.php (statement_indentation)begin diff --/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php+++/home/jiminny/app/Console/Commands/JiminnyDebugCommand.php-359,11+359,11 @ScrmService = ScrmResolver->prepareCrmService);-//-/1for ($i = 0; si < 3; Si++) {if (Si % 250) {Sthis->info("Syncing opportunity {Si}");Sthis->info("Matching contact {$i}");-1/-1/.+++++ScrmService->syncOpportunity('374720564');if ($i % 25=0{//Sthis->info("Syncing opportunity {$i}");Sthis->info("Matching contact {$i}");////}ScrmService->syncOpportunity('374720564');$crmService->matchByName('Robot');end diffFixed 4 of 5666 files in 146.870 seconds, 60.00 MB memory usedWhat's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image →Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20725-handle-HS-search-rate-lir• 0EDHomeDMsActivityFilesLater...More→Jiminny ...# contusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...^ Direct messagesP. Aneliya Angelova®. Galya DimitrovaPetko Kashinski&. Stefka StoyanovaVasil Vasilev&. Nikolay IvanovAneliya Angelova, ...Stoyan Tanev• VesE Lukas Kovalik y... 0::: AppsS Jira CloudToast(abl100% <78• Mon 11 May 17:21:39Describe what you are looking for# releases8 226 0MessagesC Files• Bookmarkso Puonicumihailmihaylovjir]Today ~4ff69be1 - JY-17836: Handle non-botactivitiesaf953504 - Merge pull request #12067 fromjiminny/JY-17836-participant-speeches-hotfixjiminny/app Added by GitHubGitHub APP 5:10 PM13 new commits pushed to master by ilian-jiminny9353b609 - JY-20395 wipbee402b7 - JY-20395 Stop fetching ALLheaders (including file) for email importd6a0fe5a - JY-20395 lintdaa0373e - JY-20395 lint fixesaf59d609 - JY-20395 Removed no longer usedmethodsShow morejiminny/app | Added by GitHubCircleCl APP 5:11 PMDeployment Successful!Project: appWhen:05/11/202614:11:35Tag:View JobMessage #releases..•...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20034
|
|
20035
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php
PaginationState.php
ProspectSearchStrategy
Redis
ServiceTraits
OpportunitySyncTrait.php
SyncCrmEntitiesTrait.php
SyncFieldsTrait.php
WriteCrmTrait.php
Utils
Webhook
BatchSyncCollector.php
BatchSyncRedisService.php
Client.php
9
ClosedDealStagesService.php
DealFieldsService.php
DecorateActivity.php
FieldDefinitions.php
FieldTypeConverter.php
HubspotClientInterface.php
HubspotTokenManager.php
PayloadBuilder.php
RemoteCrmObjectManipulator.php
ResponseNormalize.php
Service.php
SyncFieldAction.php
SyncRelatedActivityManager.php
WebhookSyncBatchProcessor.php
IntegrationApp
Listeners
Metadata
Migration
Pipedrive
OpportunitySyncStrategy
ProspectSearchStrategy
ApiFields.php
OpportunitySyncStrategy
Hubspot
Crm...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20035
|
|
20036
|
Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧ Explorer (⇧⌘E)
Search (⇧⌘F)
Source Control (⌃⇧G) - 13 pending changes
13
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update
2
Testing
Claude Code
EXPLORER
EXPLORER
Explorer Section: app
Explorer Section: app
APP
Metadata
OpportunitySyncStrategy
Concerns
HubspotLastModifiedByProfileSyncStrategy.php
HubspotLastModifiedCreatedRecentlyOpenSyncStrategy.php
HubspotLastModifiedCreatedRecentlySyncStrategy.php
HubspotLastModifiedOpenSyncStrategy.php
HubspotLastModifiedSyncStrategy.php
HubspotSingleSyncStrategy.php
HubspotSyncStrategyBase.php
HubspotWebhookBatchSyncStrategy.php
Pagination
HubspotPaginationService.php
PaginationConfig.php...
|
Code
|
Review rate limit handli… — app
|
NULL
|
20036
|