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

RFC add retry attribute (WP-828) #483

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 25 additions & 1 deletion inc/Smartling/ApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,28 @@ private function getAuthProvider(ConfigurationProfileEntity $profile): AuthToken
return $authProvider;
}

#[Retry]
public function acquireLock(ConfigurationProfileEntity $profile, string $key, int $ttlSeconds): \DateTime
{
return DistributedLockServiceApi::create($this->getAuthProvider($profile), $profile->getProjectId(), new NullLogger())
->acquireLock("{$profile->getProjectId()}-$key", $ttlSeconds);
}

#[Retry]
public function renewLock(ConfigurationProfileEntity $profile, string $key, int $ttlSeconds): \DateTime
{
return DistributedLockServiceApi::create($this->getAuthProvider($profile), $profile->getProjectId(), $this->getLogger())
->renewLock("{$profile->getProjectId()}-$key", $ttlSeconds);
}

#[Retry]
public function releaseLock(ConfigurationProfileEntity $profile, string $key): void
{
DistributedLockServiceApi::create($this->getAuthProvider($profile), $profile->getProjectId(), $this->getLogger())
->releaseLock("{$profile->getProjectId()}-$key");
}

#[Retry]
public function createAuditLogRecord(ConfigurationProfileEntity $profile, string $actionType, string $description, array $clientData, ?JobEntityWithBatchUid $jobInfo = null, ?bool $isAuthorize = null): void
{
$record = new CreateRecordParameters();
Expand All @@ -141,6 +145,7 @@ public function createAuditLogRecord(ConfigurationProfileEntity $profile, string
/**
* @throws SmartlingFileDownloadException
*/
#[Retry]
public function downloadFile(SubmissionEntity $entity): string
{
try {
Expand Down Expand Up @@ -188,6 +193,7 @@ private function setTranslationStatusToEntity(SubmissionEntity $entity, int $com
return $entity;
}

#[Retry]
public function getStatus(SubmissionEntity $entity): SubmissionEntity
{
try {
Expand Down Expand Up @@ -230,6 +236,7 @@ private function getSmartlingLocaleBySubmission(SubmissionEntity $entity): strin
return $this->settings->getSmartlingLocaleBySubmission($entity);
}

#[Retry]
public function uploadContent(SubmissionEntity $entity, string $xmlString = '', string $filename = '', array $smartlingLocaleList = []): bool
{
$this->getLogger()
Expand Down Expand Up @@ -279,6 +286,7 @@ public function uploadContent(SubmissionEntity $entity, string $xmlString = '',
}
}

#[Retry]
public function getSupportedLocales(ConfigurationProfileEntity $profile): array
{
$supportedLocales = [];
Expand All @@ -302,6 +310,7 @@ public function getSupportedLocales(ConfigurationProfileEntity $profile): array
return $supportedLocales;
}

#[Retry]
public function getAccountUid(ConfigurationProfileEntity $profile): string
{
try {
Expand All @@ -321,6 +330,7 @@ public function getAccountUid(ConfigurationProfileEntity $profile): string
}
}

#[Retry]
public function lastModified(SubmissionEntity $submission): array
{
$output = [];
Expand All @@ -337,6 +347,7 @@ public function lastModified(SubmissionEntity $submission): array
return $output;
}

#[Retry]
public function getStatusForAllLocales(array $submissions): array
{
$submission = ArrayHelper::first($submissions);
Expand Down Expand Up @@ -397,6 +408,7 @@ public function getStatusForAllLocales(array $submissions): array
}
}

#[Retry]
public function deleteFile(SubmissionEntity $submission): void
{
try {
Expand All @@ -418,6 +430,7 @@ private function getBatchApi(ConfigurationProfileEntity $profile): BatchApi
return BatchApi::create($this->getAuthProvider($profile), $profile->getProjectId(), $this->getLogger());
}

#[Retry]
public function listJobs(ConfigurationProfileEntity $profile, ?string $name = null, array $statuses = []): array
{
$params = new ListJobsParameters();
Expand All @@ -433,6 +446,7 @@ public function listJobs(ConfigurationProfileEntity $profile, ?string $name = nu
return $this->getJobsApi($profile)->listJobs($params);
}

#[Retry]
public function createJob(ConfigurationProfileEntity $profile, array $params): array
{
$param = new CreateJobParameters();
Expand All @@ -456,6 +470,7 @@ public function createJob(ConfigurationProfileEntity $profile, array $params): a
return $this->getJobsApi($profile)->createJob($param);
}

#[Retry]
public function updateJob(ConfigurationProfileEntity $profile, string $jobId, string $name, ?string $description = null, ?DateTime $dueDate = null): array
{
$params = new UpdateJobParameters();
Expand All @@ -472,6 +487,7 @@ public function updateJob(ConfigurationProfileEntity $profile, string $jobId, st
return $this->getJobsApi($profile)->updateJob($jobId, $params);
}

#[Retry]
public function createBatch(ConfigurationProfileEntity $profile, string $jobUid, bool $authorize = false): array
{
$createBatchParameters = new CreateBatchParameters();
Expand All @@ -481,10 +497,13 @@ public function createBatch(ConfigurationProfileEntity $profile, string $jobUid,
return $this->getBatchApi($profile)->createBatch($createBatchParameters);
}

#[Retry]
public function executeBatch(ConfigurationProfileEntity $profile, string $batchUid): void
{
$this->getBatchApi($profile)->executeBatch($batchUid);
}

#[Retry]
public function retrieveBatch(ConfigurationProfileEntity $profile, string $jobId, bool $authorize = true, array $updateJob = []): string
{
if ($authorize) {
Expand Down Expand Up @@ -552,6 +571,7 @@ private function getBaseNameForDailyBucketJob(string $suffix = ''): string
return ApiWrapperInterface::DAILY_BUCKET_JOB_NAME_PREFIX . " $date$suffix";
}

#[Retry]
public function findLastJobByFileUri(ConfigurationProfileEntity $profile, string $fileUri): ?JobEntityWithStatus
{
$parameters = new SearchJobsParameters();
Expand All @@ -569,6 +589,7 @@ public function findLastJobByFileUri(ConfigurationProfileEntity $profile, string
return new JobEntityWithStatus($result['jobStatus'], $result['jobName'], $result['translationJobUid'], $profile->getProjectId());
}

#[Retry]
public function retrieveJobInfoForDailyBucketJob(ConfigurationProfileEntity $profile, bool $authorize): JobEntityWithBatchUid
{
$jobName = $this->getBaseNameForDailyBucketJob();
Expand All @@ -589,7 +610,7 @@ public function retrieveJobInfoForDailyBucketJob(ConfigurationProfileEntity $pro
'name' => $jobName,
'description' => 'Bucket job: contains updated content.',
]);
} catch (SmartlingApiException $e) {
} catch (SmartlingApiException) {
// If there is a CLOSED bucket job then we have to
// come up with new job name in order to avoid
// "Job name is already taken" error.
Expand Down Expand Up @@ -620,6 +641,7 @@ public function retrieveJobInfoForDailyBucketJob(ConfigurationProfileEntity $pro
}
}

#[Retry]
public function getProgressToken(ConfigurationProfileEntity $profile): array
{
try {
Expand Down Expand Up @@ -649,6 +671,7 @@ public function getProgressToken(ConfigurationProfileEntity $profile): array
}
}

#[Retry]
public function deleteNotificationRecord(ConfigurationProfileEntity $profile, string $space, string $object, string $record): void
{
try {
Expand All @@ -675,6 +698,7 @@ public function deleteNotificationRecord(ConfigurationProfileEntity $profile, st
}
}

#[Retry]
public function setNotificationRecord(ConfigurationProfileEntity $profile, string $space, string $object, string $record, array $data = [], int $ttl = 30): void
{
try {
Expand Down
Loading