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

Symfony process #5

Merged
merged 61 commits into from
Dec 24, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
1a74660
WUP
brendt Dec 16, 2017
6499529
WIP
brendt Dec 16, 2017
8a4d5c7
Add basic Exception handling
brendt Dec 16, 2017
7a6fc9b
WIP
brendt Dec 18, 2017
1ee671c
Exception handling in child runtime
brendt Dec 18, 2017
02c935f
Move to signal handlers - WIP
brendt Dec 21, 2017
cbec958
Correctly handle exit codes
brendt Dec 21, 2017
d9de981
Code cleanup
brendt Dec 21, 2017
a9edf74
Add timeout support
brendt Dec 21, 2017
fe089ac
Code cleanup
brendt Dec 21, 2017
8ed5c5b
Code cleanup
brendt Dec 21, 2017
b8bcfbb
Remove Guzzle dependency
brendt Dec 21, 2017
efb8551
WIP
brendt Dec 22, 2017
ccc6b60
Fix output
brendt Dec 22, 2017
569a33c
code cleanup
brendt Dec 22, 2017
b281bae
Add class usage test
brendt Dec 22, 2017
de87987
Improce Class test
brendt Dec 22, 2017
a567636
Code cleanup
brendt Dec 22, 2017
d8891a4
Add return of `await`
brendt Dec 22, 2017
9017550
Handle timeout in a -hopefully- better way
brendt Dec 22, 2017
4c8a7ef
Code cleanup
brendt Dec 22, 2017
fad9208
Apply fixes from StyleCI
brendt Dec 22, 2017
d9b6198
Merge pull request #6 from spatie/analysis-XVxLRK
brendt Dec 22, 2017
b9432da
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
brendt Dec 22, 2017
158142b
Apply fixes from StyleCI
brendt Dec 22, 2017
41aee11
Merge pull request #7 from spatie/analysis-zdrG27
brendt Dec 22, 2017
0aaab53
Improve concurrency test
brendt Dec 22, 2017
153bb55
Add configurable autoloader
brendt Dec 23, 2017
7d14f26
Add extra null checks
brendt Dec 23, 2017
4ecd86d
Code cleanup
brendt Dec 23, 2017
835f5d8
Apply fixes from StyleCI
brendt Dec 23, 2017
cb509b7
Merge pull request #8 from spatie/analysis-zD0Job
brendt Dec 23, 2017
e9828a7
Update README
brendt Dec 24, 2017
95cb2e7
import namespace
freekmurze Dec 24, 2017
2ccfc37
nitpicks
freekmurze Dec 24, 2017
405d3a3
nitpick
freekmurze Dec 24, 2017
6e19f8b
nitpicks
freekmurze Dec 24, 2017
c00aedc
nitpicks
freekmurze Dec 24, 2017
4ac6ebe
nitpick
freekmurze Dec 24, 2017
b8f9657
Update README
brendt Dec 24, 2017
31b65c7
Add docs
brendt Dec 24, 2017
b559759
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
brendt Dec 24, 2017
f951d1c
Update README
brendt Dec 24, 2017
f599592
Code cleanup
brendt Dec 24, 2017
1a5234a
improve readability
freekmurze Dec 24, 2017
173a219
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
freekmurze Dec 24, 2017
b7d7dc7
Add docblock
brendt Dec 24, 2017
f6fa1ce
make loop more readable
freekmurze Dec 24, 2017
c99bd1f
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
brendt Dec 24, 2017
1dc4903
Merge branch 'master' into symfony-process
brendt Dec 24, 2017
a99b048
Add docblock
brendt Dec 24, 2017
3952533
Add sleepTime
brendt Dec 24, 2017
992333c
Update README
brendt Dec 24, 2017
db07233
Apply fixes from StyleCI
brendt Dec 24, 2017
5da7c8b
Merge pull request #9 from spatie/analysis-8KAd9e
brendt Dec 24, 2017
1f5194a
Add vendor autoload support
brendt Dec 24, 2017
b23f9ca
Merge branch 'symfony-process' of github.com:spatie/async into symfon…
brendt Dec 24, 2017
a8bc816
Add ParallelError
brendt Dec 24, 2017
8d470c0
Update README
brendt Dec 24, 2017
ee37706
Apply fixes from StyleCI
brendt Dec 24, 2017
e3593ee
Merge pull request #10 from spatie/analysis-qx4vbb
brendt Dec 24, 2017
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
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
}
],
"require": {
"php": "^7.1"
"php": "^7.1",
"jeremeamia/superclosure": "^2.3",
"symfony/process": "^4.0"
},
"require-dev": {
"larapack/dd": "^1.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very handy!

"phpunit/phpunit": "^6.0"
},
"autoload": {
Expand Down
Empty file removed config/.gitkeep
Empty file.
18 changes: 0 additions & 18 deletions src/CallableProcess.php

This file was deleted.

39 changes: 0 additions & 39 deletions src/Output/ErrorProcessOutput.php

This file was deleted.

47 changes: 0 additions & 47 deletions src/Output/ProcessOutput.php

This file was deleted.

27 changes: 27 additions & 0 deletions src/Output/SerializableException.php
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;
}
}
138 changes: 138 additions & 0 deletions src/ParallelProcess.php
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, []);
}
}
}
Loading