ApplyFiltersTrait.php
3 months ago
ArrayableTrait.php
8 months ago
BatchSizeCalculateTrait.php
8 months ago
BearerTokenTrait.php
6 months ago
BenchmarkTrait.php
3 years ago
BooleanTransientTrait.php
5 years ago
DatabaseSearchReplaceTrait.php
1 month ago
DbRowsGeneratorTrait.php
4 years ago
DebugLogTrait.php
1 year ago
DeveloperTimerTrait.php
10 months ago
EndOfLinePlaceholderTrait.php
1 year ago
EventLoggerTrait.php
2 months ago
FileScanToCacheTrait.php
2 weeks ago
FormatTrait.php
1 year ago
HttpRequestTrait.php
10 months ago
HydrateTrait.php
1 year ago
I18nTrait.php
1 year ago
IpResolverTrait.php
11 months ago
JobResponseTrait.php
4 days ago
MaintenanceTrait.php
6 months ago
MemoryExhaustTrait.php
2 years ago
MySQLRowsGeneratorTrait.php
8 months ago
NoticesTrait.php
2 weeks ago
PropertyConstructor.php
5 years ago
RenameTmpDirectoryTrait.php
6 months ago
ResourceTrait.php
6 months ago
RestRequestTrait.php
5 months ago
RestoreFileExclusionTrait.php
1 year ago
SafeFileInfoTrait.php
2 weeks ago
SerializeTrait.php
4 days ago
SetTimeLimitTrait.php
2 months ago
SlashTrait.php
1 year ago
SqlCommentTrait.php
5 months ago
TablePrefixValidator.php
5 months ago
UrlTrait.php
1 year ago
ValueGetterTrait.php
2 years ago
WindowsOsTrait.php
1 year ago
JobResponseTrait.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Traits; |
| 4 | |
| 5 | use WPStaging\Framework\Job\AbstractJob; |
| 6 | use WPStaging\Framework\Job\Exception\ProcessLockedException; |
| 7 | |
| 8 | /** |
| 9 | * Answers an HTTP request with the outcome of one job step, including the case where another |
| 10 | * request already owns the job. |
| 11 | */ |
| 12 | trait JobResponseTrait |
| 13 | { |
| 14 | /** |
| 15 | * Run one step of a job for the current HTTP request and answer it with JSON. |
| 16 | * |
| 17 | * Turning process lock contention into an HTTP status belongs at the HTTP boundary and nowhere |
| 18 | * else: a background worker has no client to answer and must see the ProcessLockedException |
| 19 | * itself, so it can re-queue its action and let the worker that won the lock carry the job on. |
| 20 | * |
| 21 | * @param AbstractJob $job |
| 22 | * @return void |
| 23 | */ |
| 24 | protected function sendJobResponse(AbstractJob $job) |
| 25 | { |
| 26 | try { |
| 27 | $response = $job->prepareAndExecute(); |
| 28 | } catch (ProcessLockedException $e) { |
| 29 | wp_send_json_error($e->getMessage(), $e->getCode()); |
| 30 | |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | wp_send_json($response); |
| 35 | } |
| 36 | } |
| 37 |