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

FOUR-17278 Remove temporal files from failing script tasks #7281

Merged
merged 2 commits into from
Sep 10, 2024
Merged
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
4 changes: 3 additions & 1 deletion ProcessMaker/Models/ScriptDockerBindingFilesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ProcessMaker\Models;

use Log;
use Illuminate\Support\Facades\Log;
use ProcessMaker\Exception\ScriptException;
use ProcessMaker\Exception\ScriptTimeoutException;
use ProcessMaker\Facades\Docker;
Expand Down Expand Up @@ -75,6 +75,7 @@ private function runContainer($image, $command, $parameters, $bindings, $timeout
if ($returnCode) {
if ($returnCode == 137 || $returnCode == 9) {
Log::error('Script timed out');
$this->removeTemporalFiles();
throw new ScriptTimeoutException(
__('Script took too long to complete. Consider increasing the timeout.')
. "\n"
Expand All @@ -88,6 +89,7 @@ private function runContainer($image, $command, $parameters, $bindings, $timeout
$message = implode("\n", $output);
$message .= "\n\nProcessMaker Stack:\n";
$message .= (new \Exception)->getTraceAsString();
$this->removeTemporalFiles();
throw new ScriptException($message);
}
$outputs = $this->getOutputFilesContent();
Expand Down
46 changes: 46 additions & 0 deletions upgrades/2024_08_26_220829_remove_old_script_files.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

use ProcessMaker\Upgrades\UpgradeMigration as Upgrade;

class RemoveOldScriptFiles extends Upgrade
{
/**
* Run the upgrade migration.
*
* @return void
*/
public function up()
{
// Remove old script input files (with prefix `put`)
$path = config('app.processmaker_scripts_home');
$files = glob($path . '/put*');
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
}
}

// Remove old script files with prefix `get`
$path = config('app.processmaker_scripts_home');
$files = glob($path . '/get*');
$timeNow = time();

foreach ($files as $file) {
// Verify if the file was created 1 hour ago or more
if (filemtime($file) <= ($timeNow - 3600)) {
unlink($file);
}
}
}

/**
* Reverse the upgrade migration.
*
* @return void
*/
public function down()
{
//
}
}

Loading