-
Notifications
You must be signed in to change notification settings - Fork 0
Implement retries #4
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
Conversation
public function up(): void | ||
{ | ||
Schema::table('magento_bulk_requests', function (Blueprint $table): void { | ||
$table->unsignedBigInteger('retry_of')->after('id')->nullable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if you could add a foreign key constraint that will set the value to NULL if the relation has been removed.
src/Actions/RetryBulkRequest.php
Outdated
} | ||
|
||
$payload[] = $request; | ||
if ($operation->subject !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are always adding the subject, even if it's null, so this check should not be needed. Does this not cause any unwanted side effects with e.g. events?
|
||
class RetryBulkRequestCommand extends Command | ||
{ | ||
protected $signature = 'magento:async:retry-bulk-request {id} {--only-failed}'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most cases, the --only-failed
is preferable. Perhaps rename it to --all
which would by false
without any options? This way, you could only retry the failed transactions by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I'd prefer to default it to true (which the Nova implementation does too), the action isn't called RetryFailed
. This is just an optional filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair! In that case, it can remain what it is
src/Actions/RetryBulkRequest.php
Outdated
'POST' => $pendingRequest->postBulk($bulkRequest->path, $payload), | ||
'PUT' => $pendingRequest->putBulk($bulkRequest->path, $payload), | ||
'DELETE' => $pendingRequest->deleteBulk($bulkRequest->path, $payload), | ||
default => null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd personally prefer an exception if an unsupported method would be used
src/Actions/RetryBulkRequest.php
Outdated
}; | ||
|
||
if ($retry !== null) { | ||
$retry->update([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should be able use your relation for this.
$bulkRequest->retries()->save($retry);
]), | ||
])->preventStrayRequests(); | ||
|
||
foreach (['POST', 'PUT', 'DELETE'] as $method) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to see a data provider for this
/** @var RetryBulkRequest $action */ | ||
$action = app(RetryBulkRequest::class); | ||
|
||
$action->retry($request, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could additionally check if the returned value is NULL
/** @var RetryBulkRequest $action */ | ||
$action = app(RetryBulkRequest::class); | ||
|
||
$action->retry($request, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes here
'--only-failed' => true, | ||
]); | ||
|
||
$this->assertFalse(is_int($result)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend to use doc blocks instead:
/** @var PendingCommand $artisan */
$artisan = $this->artisan(RetryBulkRequestCommand::class, [
'id' => $request->id,
'--only-failed' => true,
]);
No description provided.