Skip to content

Conversation

VincentBean
Copy link
Member

No description provided.

public function up(): void
{
Schema::table('magento_bulk_requests', function (Blueprint $table): void {
$table->unsignedBigInteger('retry_of')->after('id')->nullable();
Copy link
Member

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.

}

$payload[] = $request;
if ($operation->subject !== null) {
Copy link
Member

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}';
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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

'POST' => $pendingRequest->postBulk($bulkRequest->path, $payload),
'PUT' => $pendingRequest->putBulk($bulkRequest->path, $payload),
'DELETE' => $pendingRequest->deleteBulk($bulkRequest->path, $payload),
default => null,
Copy link
Member

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

};

if ($retry !== null) {
$retry->update([
Copy link
Member

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) {
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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));
Copy link
Member

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,
]);

@VincentBean VincentBean merged commit e8ddae8 into main Sep 19, 2024
12 checks passed
@VincentBean VincentBean deleted the feature/retry branch September 19, 2024 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants