-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
Symfony process #5
Merged
Merged
Changes from 12 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
1a74660
WUP
brendt 6499529
WIP
brendt 8a4d5c7
Add basic Exception handling
brendt 7a6fc9b
WIP
brendt 1ee671c
Exception handling in child runtime
brendt 02c935f
Move to signal handlers - WIP
brendt cbec958
Correctly handle exit codes
brendt d9de981
Code cleanup
brendt a9edf74
Add timeout support
brendt fe089ac
Code cleanup
brendt 8ed5c5b
Code cleanup
brendt b8bcfbb
Remove Guzzle dependency
brendt efb8551
WIP
brendt ccc6b60
Fix output
brendt 569a33c
code cleanup
brendt b281bae
Add class usage test
brendt de87987
Improce Class test
brendt a567636
Code cleanup
brendt d8891a4
Add return of `await`
brendt 9017550
Handle timeout in a -hopefully- better way
brendt 4c8a7ef
Code cleanup
brendt fad9208
Apply fixes from StyleCI
brendt d9b6198
Merge pull request #6 from spatie/analysis-XVxLRK
brendt b9432da
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
brendt 158142b
Apply fixes from StyleCI
brendt 41aee11
Merge pull request #7 from spatie/analysis-zdrG27
brendt 0aaab53
Improve concurrency test
brendt 153bb55
Add configurable autoloader
brendt 7d14f26
Add extra null checks
brendt 4ecd86d
Code cleanup
brendt 835f5d8
Apply fixes from StyleCI
brendt cb509b7
Merge pull request #8 from spatie/analysis-zD0Job
brendt e9828a7
Update README
brendt 95cb2e7
import namespace
freekmurze 2ccfc37
nitpicks
freekmurze 405d3a3
nitpick
freekmurze 6e19f8b
nitpicks
freekmurze c00aedc
nitpicks
freekmurze 4ac6ebe
nitpick
freekmurze b8f9657
Update README
brendt 31b65c7
Add docs
brendt b559759
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
brendt f951d1c
Update README
brendt f599592
Code cleanup
brendt 1a5234a
improve readability
freekmurze 173a219
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
freekmurze b7d7dc7
Add docblock
brendt f6fa1ce
make loop more readable
freekmurze c99bd1f
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
brendt 1dc4903
Merge branch 'master' into symfony-process
brendt a99b048
Add docblock
brendt 3952533
Add sleepTime
brendt 992333c
Update README
brendt db07233
Apply fixes from StyleCI
brendt 5da7c8b
Merge pull request #9 from spatie/analysis-8KAd9e
brendt 1f5194a
Add vendor autoload support
brendt b23f9ca
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
brendt a8bc816
Add ParallelError
brendt 8d470c0
Update README
brendt ee37706
Apply fixes from StyleCI
brendt e3593ee
Merge pull request #10 from spatie/analysis-qx4vbb
brendt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Spatie\Async\Output; | ||
|
||
use Throwable; | ||
|
||
class SerializableException | ||
{ | ||
protected $class; | ||
protected $message; | ||
protected $trace; | ||
|
||
public function __construct(Throwable $e) | ||
{ | ||
$this->class = get_class($e); | ||
$this->message = $e->getMessage(); | ||
$this->trace = $e->getTraceAsString(); | ||
} | ||
|
||
public function asThrowable(): Throwable | ||
{ | ||
/** @var Throwable $throwable */ | ||
$throwable = new $this->class($this->message); | ||
|
||
return $throwable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
|
||
namespace Spatie\Async; | ||
|
||
use Spatie\Async\Output\SerializableException; | ||
use Symfony\Component\Process\Process; | ||
|
||
class ParallelProcess | ||
{ | ||
protected $process; | ||
protected $id; | ||
protected $pid; | ||
|
||
protected $successCallbacks = []; | ||
protected $errorCallbacks = []; | ||
protected $timeoutCallbacks = []; | ||
|
||
protected $output; | ||
protected $errorOutput; | ||
|
||
public function __construct(Process $process) | ||
{ | ||
$this->process = $process; | ||
$this->id = uniqid(getmypid()); | ||
} | ||
|
||
public static function create(Process $process): self | ||
{ | ||
return new self($process); | ||
} | ||
|
||
public function then(callable $callback): self | ||
{ | ||
$this->successCallbacks[] = $callback; | ||
|
||
return $this; | ||
} | ||
|
||
public function catch(callable $callback): self | ||
{ | ||
$this->errorCallbacks[] = $callback; | ||
|
||
return $this; | ||
} | ||
|
||
public function timeout(callable $callback): self | ||
{ | ||
$this->timeoutCallbacks[] = $callback; | ||
|
||
return $this; | ||
} | ||
|
||
public function start(): self | ||
{ | ||
$this->process->start(); | ||
|
||
$this->pid = $this->process->getPid(); | ||
|
||
return $this; | ||
} | ||
|
||
public function isRunning(): bool | ||
{ | ||
return $this->process->isRunning(); | ||
} | ||
|
||
public function isSuccessful(): bool | ||
{ | ||
return $this->process->isSuccessful(); | ||
} | ||
|
||
public function isTerminated(): bool | ||
{ | ||
return $this->process->isTerminated(); | ||
} | ||
|
||
public function output() | ||
{ | ||
if (!$this->output) { | ||
$this->output = unserialize($this->process->getOutput()); | ||
} | ||
|
||
return $this->output; | ||
} | ||
|
||
public function errorOutput() | ||
{ | ||
if (!$this->errorOutput) { | ||
$this->errorOutput = unserialize($this->process->getErrorOutput()); | ||
} | ||
|
||
return $this->errorOutput; | ||
} | ||
|
||
public function process(): Process | ||
{ | ||
return $this->process; | ||
} | ||
|
||
public function id(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function pid(): ?string | ||
{ | ||
return $this->pid; | ||
} | ||
|
||
public function triggerSuccess() | ||
{ | ||
$output = $this->output(); | ||
|
||
foreach ($this->successCallbacks as $callback) { | ||
call_user_func_array($callback, [$output]); | ||
} | ||
} | ||
|
||
public function triggerError() | ||
{ | ||
$output = $this->errorOutput(); | ||
|
||
if ($output instanceof SerializableException) { | ||
$output = $output->asThrowable(); | ||
} | ||
|
||
foreach ($this->errorCallbacks as $callback) { | ||
call_user_func_array($callback, [$output]); | ||
} | ||
} | ||
|
||
public function triggerTimeout() | ||
{ | ||
foreach ($this->timeoutCallbacks as $callback) { | ||
call_user_func_array($callback, []); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very handy!