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

Retrying Commerce Integration Creation on Falure. #1078

Conversation

message-dimke
Copy link
Contributor

@message-dimke message-dimke commented Oct 22, 2024

Changes proposed in this Pull Request:

This PR introduces the initial create Commerce Integration call retry procedure. It may happen that the Create Integration API will fail. We have to retry its creation since the integration data is crucial for assigning customers to a proper Pinterest advertisement platform on the Pinterest side.

The code will try three times: in a minute after the initial failure; in an hour; in a day.

Detailed test instructions:

  1. Add a filter to make the APIV5::create_commerce_integration call fail.
add_filter(
	'pre_http_request',
	function ( $response, $parsed_args, $url ) {
		if (
			'https://api.pinterest.com/v5/integrations/commerce' === $url &&
			'POST' === $parsed_args['method']
		) {
			return array(
				'headers' => array(
					'content-type' => 'application/json',
				),
				'body' => json_encode(
					array(
						'code'    => 911,
						'message' => 'Oops! Something went wrong!',
					)
				),
				'response' => array(
					'code'    => 500,
					'message' => 'Unexpected error',
				),
				'cookies'  => array(),
				'filename' => '',
			);
		}

		return $response;
	},
	10,
	3
);

public static function create_commerce_integration( array $integration_data ): array {
return self::make_request(
'integrations/commerce',
'POST',
$integration_data
);
}

  1. If you are connected to Pinterest - disconnect. Otherwise, connect to your Pinterest account using the extension.
  2. During the connection procedure, the commerce integration call will fail. Look into Pending Scheduled Actions for a retry scheduled to run within a minute of the connection time.
WooCommerce_status_‹_WordPress_Pinterest_—_WordPress-2

It should also have an attempt number parameter set to 1, meaning this is the first attempt of a retry.

  1. Look into pinterest-for-woocommerce log for a message about the failure and the retry procedure.
WooCommerce_status_‹_WordPress_Pinterest_—_WordPress-3
  1. Wait until the action triggers itself or force-run it. Since we still have a code to make the endpoint fail, we should see another retry attempt scheduled and the log message.
WooCommerce_status_‹_WordPress_Pinterest_—_WordPress-4
  1. Do not wait an hour 🤡 to pass and force-run the action.
  2. Look for the last, third attempt to get scheduled.
WooCommerce_status_‹_WordPress_Pinterest_—_WordPress-5
  1. Force-run it and check no more actions scheduled and the last attempt log message written.
WooCommerce_status_‹_WordPress_Pinterest_—_WordPress-7

Changelog entry

Add - Failed Create Commerce Integration API call retries procedure.

…ep where they belong;

- Introducing Commerce Integration controller class;
- Adjusting unit tests;
- Adding commerce integration retry action registration;
- Adding commerce integration retry actions cleanup on disconnect;
@message-dimke message-dimke added the changelog: add A new feature, function, or functionality was added. label Oct 22, 2024
@message-dimke message-dimke self-assigned this Oct 22, 2024
@github-actions github-actions bot added the type: enhancement The issue is a request for an enhancement. label Oct 22, 2024
@message-dimke message-dimke marked this pull request as ready for review October 22, 2024 16:55
Copy link
Collaborator

@budzanowski budzanowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

message-dimke and others added 3 commits October 23, 2024 09:05
…be changed in the future without paying attention to set a proper time frame for it.
…ration-sync

Synchronising Commerce Integration `partner_metadata` weekly.
@message-dimke message-dimke merged commit 7866462 into update/revise-integration-data-usage Oct 23, 2024
4 checks passed
@message-dimke message-dimke deleted the add/create-commerce-integration-retry branch October 23, 2024 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants