Skip to content

Commit

Permalink
Merge pull request #98 from musa11971/process-timeout
Browse files Browse the repository at this point in the history
Added processTimeout option
  • Loading branch information
driftingly authored Mar 17, 2023
2 parents f1a4e94 + 1cd317e commit 47e8168
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ The key is the name of the command (used with the `--using` flag), and the value
"lint": {
"phpstan": ["./vendor/bin/phpstan", "analyse"]
}
}
},
"processTimeout": 120
}
```

Duster will pick these up automatically when running either `lint` or `fix`.
Duster will pick these up automatically when running either `lint` or `fix`.
By default, additional scripts timeout after 60 seconds. You can overwrite this setting using the `processTimeout` key.

To customize which tools Duster runs, or the order in which they are executed you can use the `--using` flag and supply a comma-separated list of commands:

Expand Down
14 changes: 12 additions & 2 deletions app/Support/UserScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Support;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Process;

class UserScript extends Tool
Expand Down Expand Up @@ -33,11 +34,20 @@ public function fix(): int

private function process(): int
{
$dusterConfig = DusterConfig::loadLocal();

$process = new Process($this->command);
$process->setTimeout($dusterConfig['processTimeout'] ?? 60);
$output = app()->get(OutputInterface::class);

$process->run(fn ($type, $buffer) => $output->write($buffer));
try {
$process->run(fn ($type, $buffer) => $output->write($buffer));

return $process->getExitCode();
} catch(ProcessTimedOutException $e) {
$this->failure($e->getMessage() . '<br />You can overwrite this timeout with the processTimeout key in your duster.json file.');

return $process->getExitCode();
return 1;
}
}
}

0 comments on commit 47e8168

Please sign in to comment.