Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove queue based on the condition #76

Merged
merged 38 commits into from
Jul 10, 2024
Merged
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
eb5395a
remove queue only if there is no error
ramyakrishnai Jun 7, 2024
037af8e
linting fixes
ramyakrishnai Jun 7, 2024
5ded7d6
Added retry limit to 3
ramyakrishnai Jun 10, 2024
8ae7ca8
changes
ramyakrishnai Jun 10, 2024
414f918
changes
ramyakrishnai Jun 10, 2024
9ef95fc
linting fixes
ramyakrishnai Jun 12, 2024
3731711
added delay of 15 sec to push to the queue again
ramyakrishnai Jun 13, 2024
0143f62
added 5 sec
ramyakrishnai Jun 13, 2024
63e5ac0
added retry
ramyakrishnai Jun 13, 2024
8d080fe
linting issues
ramyakrishnai Jun 17, 2024
7e861c8
Merge branch 'main' into removeQueue
BrianHenryIE Jun 19, 2024
74a4130
Add tests for `EventMananager::init()`
BrianHenryIE Jun 19, 2024
c78de68
Add tests for `EventManager::init()`
BrianHenryIE Jun 19, 2024
7b4562d
Delete rough-work test
BrianHenryIE Jun 19, 2024
9849c34
Do not remove events from BatchQueue if sending them to Hiive fails
BrianHenryIE Jun 19, 2024
c786076
`EventManager::shutdown()` should `BatchQueue::push()` when fails to …
BrianHenryIE Jun 19, 2024
a420021
Correctly return `WP_Error` in test
BrianHenryIE Jun 19, 2024
cc90c94
lint / comment / typehint
BrianHenryIE Jun 19, 2024
c2f719c
Merge branch 'main' into removeQueue
BrianHenryIE Jun 19, 2024
b97add5
Use `assertConditionsMet` not `expectNotToPerformAssertions`
BrianHenryIE Jun 19, 2024
4a23a7a
lint / use Mockery to skip some paths
BrianHenryIE Jun 19, 2024
b4d9523
Add `@hooked nfd_data_sync_cron` comment to `EventManager::send_batch()`
BrianHenryIE Jun 19, 2024
ccd5f1a
lint
BrianHenryIE Jun 19, 2024
eb13b46
Fix: `HiiveConnection::notify()` when `WP_Error` returned in request
BrianHenryIE Jun 20, 2024
f36013f
Do not preserve events after non-blocking requests
BrianHenryIE Jun 20, 2024
dd5fdaf
Add test for `HiiveConnection::notify()` non-blocking behavior
BrianHenryIE Jun 20, 2024
1f037a3
Merge branch 'main' into removeQueue
BrianHenryIE Jun 21, 2024
c1071a5
Extract and test `Data::delete_token_on_401_response()`, hooked `http…
BrianHenryIE Jul 8, 2024
fb72ba7
Add `forceWpMockStrictModeOn()`/`forceWpMockStrictModeOff()`
BrianHenryIE Jul 8, 2024
b43d7e4
Saved queued events on failure
BrianHenryIE Jul 9, 2024
af2865b
Add `Hiive_Connection::hiive_request`, use `::notify` for v2 events, …
BrianHenryIE Jul 9, 2024
233e71f
Update `newfold-data/v1/events` to expect notifications from `Hiive_C…
BrianHenryIE Jul 9, 2024
5f79f55
Correct order of error message / code
BrianHenryIE Jul 9, 2024
f56b6f1
Remove duplicate line
BrianHenryIE Jul 9, 2024
f6e5274
Allow 200, 201 status codes
BrianHenryIE Jul 9, 2024
a193a43
Assert WP_Error is returned
BrianHenryIE Jul 9, 2024
1f17404
lint / rename / type annotate
BrianHenryIE Jul 9, 2024
e180489
Use explicit HTTP 500 on error
BrianHenryIE Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion includes/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class EventManager {
*/
private $queue = array();

/**
* The error of events logged in the current request
*
* @var array
*/
private $error = array(
'retryCount' => 0,
);

/**
* Initialize the Event Manager
*
Expand Down Expand Up @@ -205,7 +214,16 @@ public function push( Event $event ) {
*/
public function send( $events ) {
foreach ( $this->get_subscribers() as $subscriber ) {
$subscriber->notify( $events );
$response = $subscriber->notify( $events );
if ( is_wp_error( $response ) ) {
$this->error = array(
'retryCount' => $this->error['retryCount'] + 1,
);
} else {
$this->error = array(
'retryCount' => 0,
);
}
}
}

Expand All @@ -232,5 +250,10 @@ public function send_batch() {
$this->send( $events );

$queue->remove( $ids );

if ( $this->error['retryCount'] >= 1 ) {
\sleep( 15 );
BrianHenryIE marked this conversation as resolved.
Show resolved Hide resolved
$queue->push( $events );
}
}
}
Loading