• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prooph / event-store-client / 9555551525

17 Jun 2024 10:16PM UTC coverage: 70.262% (-1.1%) from 71.395%
9555551525

push

github

prolic
update coveralls repo token

3466 of 4933 relevant lines covered (70.26%)

67.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Projections/QueryManager.php
1
<?php
2

3
/**
4
 * This file is part of `prooph/event-store-client`.
5
 * (c) 2018-2024 Alexander Miertsch <kontakt@codeliner.ws>
6
 * (c) 2018-2024 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Prooph\EventStoreClient\Projections;
15

16
use function Amp\async;
17
use function Amp\delay;
18

19
use Amp\TimeoutCancellation;
20
use Prooph\EventStore\EndPoint;
21
use Prooph\EventStore\Projections\ProjectionDetails;
22
use Prooph\EventStore\Projections\QueryManager as QueryManagerInterface;
23
use Prooph\EventStore\Projections\State;
24
use Prooph\EventStore\UserCredentials;
25

26
/**
27
 * API for executing queries in the Event Store through PHP code.
28
 * Communicates with the Event Store over the RESTful API.
29
 */
30
class QueryManager implements QueryManagerInterface
31
{
32
    private readonly ProjectionsManager $projectionsManager;
33

34
    public function __construct(
35
        EndPoint $httpEndPoint,
36
        int $projectionOperationTimeout,
37
        private readonly int $queryTimeout,
38
        bool $tlsTerminatedEndpoint = false,
39
        bool $verifyPeer = true,
40
        private readonly ?UserCredentials $defaultUserCredentials = null
41
    ) {
42
        $this->projectionsManager = new ProjectionsManager(
×
43
            $httpEndPoint,
×
44
            $projectionOperationTimeout,
×
45
            $tlsTerminatedEndpoint,
×
46
            $verifyPeer,
×
47
        );
×
48
    }
49

50
    public function execute(
51
        string $name,
52
        string $query,
53
        int $initialPollingDelay,
54
        int $maximumPollingDelay,
55
        string $type = 'JS',
56
        ?UserCredentials $userCredentials = null
57
    ): State {
58
        return async(function () use ($name, $query, $type, $initialPollingDelay, $maximumPollingDelay, $userCredentials): State {
×
59
            $this->projectionsManager->createTransient(
×
60
                $name,
×
61
                $query,
×
62
                $type,
×
63
                $userCredentials ?? $this->defaultUserCredentials
×
64
            );
×
65

66
            $this->waitForCompleted(
×
67
                $name,
×
68
                $initialPollingDelay,
×
69
                $maximumPollingDelay,
×
70
                $userCredentials ?? $this->defaultUserCredentials
×
71
            );
×
72

73
            return $this->projectionsManager->getState(
×
74
                $name,
×
75
                $userCredentials ?? $this->defaultUserCredentials
×
76
            );
×
77
        })->await(new TimeoutCancellation($this->queryTimeout));
×
78
    }
79

80
    private function waitForCompleted(
81
        string $name,
82
        int $initialPollingDelay,
83
        int $maximumPollingDelay,
84
        ?UserCredentials $userCredentials
85
    ): void {
86
        $attempts = 0;
×
87
        $status = $this->getStatus($name, $userCredentials);
×
88

89
        while (! \str_contains($status->status(), 'Completed')) {
×
90
            $attempts++;
×
91

92
            delay((int) \min(
×
93
                $initialPollingDelay * (2 ** $attempts - 1),
×
94
                $maximumPollingDelay
×
95
            ));
×
96

97
            $status = $this->getStatus($name, $userCredentials);
×
98
        }
99
    }
100

101
    private function getStatus(string $name, ?UserCredentials $userCredentials): ProjectionDetails
102
    {
103
        return $this->projectionsManager->getStatus($name, $userCredentials);
×
104
    }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc