1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace WyriHaximus\Travis\Resource\Async; |
5
|
|
|
|
6
|
|
|
use ApiClients\Client\Pusher\CommandBus\Command\SharedAppClientCommand; |
7
|
|
|
use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateCommand; |
8
|
|
|
use ApiClients\Foundation\Transport\CommandBus\Command\SimpleRequestCommand; |
9
|
|
|
use React\Promise\PromiseInterface; |
10
|
|
|
use Rx\Observable; |
11
|
|
|
use Rx\ObservableInterface; |
12
|
|
|
use Rx\Observer\CallbackObserver; |
13
|
|
|
use Rx\ObserverInterface; |
14
|
|
|
use Rx\React\Promise; |
15
|
|
|
use Rx\SchedulerInterface; |
16
|
|
|
use WyriHaximus\Travis\ApiSettings; |
17
|
|
|
use WyriHaximus\Travis\Resource\Job as BaseJob; |
18
|
|
|
use function React\Promise\resolve; |
19
|
|
|
|
20
|
|
|
class Job extends BaseJob |
21
|
|
|
{ |
22
|
|
|
public function log(): ObservableInterface |
23
|
|
|
{ |
24
|
|
|
return Observable::create(function ( |
25
|
|
|
ObserverInterface $observer, |
26
|
|
|
SchedulerInterface $scheduler |
|
|
|
|
27
|
|
|
) { |
28
|
|
|
$this->handleCommand( |
29
|
|
|
new SharedAppClientCommand(ApiSettings::PUSHER_KEY) |
30
|
|
|
)->then(function ($pusher) use ($observer) { |
31
|
|
|
$pusher->channel('job-' . $this->id)->filter(function ($message) { |
32
|
|
|
return $message->event == 'job:log'; |
33
|
|
|
})->map(function ($message) { |
34
|
|
|
return json_decode($message->data, true); |
35
|
|
|
})->flatMap(function (array $json) { |
36
|
|
|
return Promise::toObservable($this->handleCommand(new HydrateCommand('LogLine', $json))); |
37
|
|
|
})->subscribe(new CallbackObserver(function ($repository) use ($observer) { |
38
|
|
|
$observer->onNext($repository); |
39
|
|
|
})); |
40
|
|
|
}); |
41
|
|
|
}); |
42
|
|
|
} |
43
|
|
|
/** |
44
|
|
|
* @return ObservableInterface |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public function annotations(): ObservableInterface |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
return Promise::toObservable( |
49
|
|
|
$this->handleCommand(new SimpleRequestCommand('jobs/' . $this->id() . '/annotations')) |
50
|
|
|
)->flatMap(function ($response) { |
51
|
|
|
return Observable::fromArray($response['annotations']); |
52
|
|
|
})->flatMap(function ($annotation) { |
53
|
|
|
return Promise::toObservable($this->handleCommand(new HydrateCommand('Annotation', $annotation))); |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return PromiseInterface |
59
|
|
|
*/ |
60
|
|
|
public function refresh(): PromiseInterface |
61
|
|
|
{ |
62
|
|
|
return $this->handleCommand(new SimpleRequestCommand('jobs/' . $this->id))->then(function ($json) { |
63
|
|
|
return resolve($this->handleCommand(new HydrateCommand('Job', $json['job']))); |
64
|
|
|
}); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.