feat: implement Change resource with CRUD functionality and migration
update image tags to v0.0.8 in build scripts and docker-compose files
This commit is contained in:
parent
64a7d1d2f4
commit
5b0e55c4b2
20 changed files with 408 additions and 88 deletions
79
app/Services/ProcessUpdateService.php
Normal file
79
app/Services/ProcessUpdateService.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
|
||||
class ProcessUpdateService
|
||||
{
|
||||
public function processUpdate(int $entryId, string $action, string $type = 'entry_update_'): void
|
||||
{
|
||||
$subject = env('NATS_SUBJECT', 'entry_update');
|
||||
$appUrl = env('APP_URL', 'http://localhost');
|
||||
|
||||
$incoming = [
|
||||
'id' => $entryId,
|
||||
'action' => $action,
|
||||
'subject' => $subject,
|
||||
'app_url' => $appUrl,
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
$jsonData = json_encode($incoming, JSON_THROW_ON_ERROR);
|
||||
$tempFile = tempnam(sys_get_temp_dir(), $type);
|
||||
file_put_contents($tempFile, $jsonData);
|
||||
|
||||
$scriptPath = env('HANDLE_ENTRY_UPDATES_SCRIPT', base_path('cmd/handle_cms_updates.sh'));
|
||||
|
||||
try {
|
||||
// Log what we're about to execute
|
||||
Log::info("Executing script: {$scriptPath} with action: {$action}", [
|
||||
'entry_id' => $entryId,
|
||||
'temp_file' => $tempFile,
|
||||
'script_exists' => file_exists($scriptPath),
|
||||
'script_executable' => is_executable($scriptPath),
|
||||
]);
|
||||
|
||||
$result = Process::run([
|
||||
'bash',
|
||||
$scriptPath,
|
||||
$action,
|
||||
$tempFile,
|
||||
]);
|
||||
|
||||
if ($result->failed()) {
|
||||
$errorDetails = [
|
||||
'exit_code' => $result->exitCode(),
|
||||
'stdout' => $result->output(),
|
||||
'stderr' => $result->errorOutput(),
|
||||
'command' => ['bash', $scriptPath, $action, $tempFile],
|
||||
'script_path' => $scriptPath,
|
||||
'script_exists' => file_exists($scriptPath),
|
||||
'temp_file_exists' => file_exists($tempFile),
|
||||
'temp_file_contents' => file_exists($tempFile) ? file_get_contents($tempFile) : 'N/A',
|
||||
];
|
||||
|
||||
Log::error('Script execution failed', $errorDetails);
|
||||
|
||||
throw new RuntimeException(
|
||||
"Script execution failed with exit code {$result->exitCode()}. " .
|
||||
'STDOUT: ' . ($result->output() ?: 'empty') . ' ' .
|
||||
'STDERR: ' . ($result->errorOutput() ?: 'empty')
|
||||
);
|
||||
}
|
||||
|
||||
Log::info('Script executed successfully', [
|
||||
'stdout' => $result->output(),
|
||||
'entry_id' => $entryId,
|
||||
'action' => $action,
|
||||
]);
|
||||
} finally {
|
||||
// Clean up temp file
|
||||
if (file_exists($tempFile)) {
|
||||
unlink($tempFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue