Skip to content

Commit

Permalink
Refactoring: replace tube with flow (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianaromagnoli committed Mar 2, 2020
1 parent e1ad60d commit bed3f06
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @internal
*/
class TubeController extends AbstractController
class FlowController extends AbstractController
{
/**
* @var Client
Expand All @@ -35,11 +35,11 @@ public function __construct(
$this->elasticSearchClient = $elasticSearchClient;
}

public function __invoke(Request $request, string $tube): Promise
public function __invoke(Request $request, string $flow): Promise
{
return call(function () use ($request, $tube) {
return call(function () use ($request, $flow) {
/** @var Tube $tube */
$tube = yield $this->getBeanstalkClient()->getTubeStats($tube);
$tube = yield $this->getBeanstalkClient()->getTubeStats($flow);
$queryParams = [];
parse_str($request->getUri()->getQuery(), $queryParams);
$foundJobs = [];
Expand All @@ -52,8 +52,9 @@ public function __invoke(Request $request, string $tube): Promise
Status::OK,
[],
$this->getTwig()->render(
'tube.html.twig',
'flow.html.twig',
[
'flow' => $flow,
'tube' => $tube,
'foundJobs' => $foundJobs,
'query' => $query,
Expand Down
11 changes: 7 additions & 4 deletions src/Console/Controller/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ public function __construct(Environment $twig, BeanstalkClient $beanstalkClient,
}


public function __invoke(Request $request, string $jobId)
public function __invoke(Request $request, string $flow, string $jobId)
{
return call(function () use ($jobId) {
$result = yield $this->elasticSearchClient->search(['term' => ['uuid.keyword' => ['value' => $jobId]]]);
return call(function () use ($jobId, $flow) {
$result = yield $this->elasticSearchClient->search(
['term' => ['uuid.keyword' => ['value' => $jobId]]],
$flow
);
$document = $result['hits']['hits'][0];
$job = $document['_source'];

return new Response(
Status::OK,
[],
$this->getTwig()->render('job.html.twig', ['job' => $job])
$this->getTwig()->render('job.html.twig', ['flow' => $flow, 'job' => $job])
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Resources/config/controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ services:
parent: console.controller.abstract
class: '\Webgriffe\Esb\Console\Controller\IndexController'

console.controller.tube:
console.controller.flow:
parent: console.controller.abstract
class: '\Webgriffe\Esb\Console\Controller\TubeController'
class: '\Webgriffe\Esb\Console\Controller\FlowController'
arguments:
- '@Webgriffe\AmpElasticsearch\Client'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<hr />

<h4>Search</h4>
<form action="/tube/{{ tube.name }}" method="get">
<form action="/flow/{{ tube.name }}" method="get">
<div class="form-group">
<input type="search" class="form-control form-control-lg" id="query" aria-describedby="queryHelp"
placeholder="Enter a query" name="query" value="{{ query }}">
Expand Down Expand Up @@ -86,7 +86,7 @@
<td><pre>{{ job.lastEvent.type }}</pre></td>
<td>
<div class="btn-group btn-group-sm" role="group" aria-label="Actions">
<a class="btn btn-secondary" href="/job/{{ job.uuid }}">
<a class="btn btn-secondary" href="/flow/{{ flow }}/job/{{ job.uuid }}">
<span class="oi oi-eye"></span>
View
</a>
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Resources/views/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<tbody>
{% for tube in tubes %}
<tr>
<th scope="row"><a href="/tube/{{ tube.name }}">{{ tube.name }}</a></th>
<th scope="row"><a href="/flow/{{ tube.name }}">{{ tube.name }}</a></th>
<td>{{ tube.currentJobsUrgent }}</td>
<td>{{ tube.currentJobsReady }}</td>
<td>{{ tube.currentJobsReserved }}</td>
Expand Down
5 changes: 4 additions & 1 deletion src/Console/Resources/views/job.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{% extends '_layout.html.twig' %}

{% block content %}
<h2 class="my-4">Job <small class="text-muted">{{ job.uuid }}</small></h2>
<h2 class="my-4">
Job <small class="text-muted">{{ job.uuid }}</small>
<a class="btn btn-secondary btn-sm float-right" role="button" href="/flow/{{ flow }}">&laquo; Back</a>
</h2>

<div class="row">
<div class="col-xs-12">
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Webgriffe\Esb\Console\Controller\IndexController;
use Webgriffe\Esb\Console\Controller\JobController;
use Webgriffe\Esb\Console\Controller\KickController;
use Webgriffe\Esb\Console\Controller\TubeController;
use Webgriffe\Esb\Console\Controller\FlowController;
use function Amp\call;

/**
Expand Down Expand Up @@ -142,10 +142,10 @@ private function getDispatcher(Request $request): Dispatcher
function (RouteCollector $r) use ($request) {
$this->container->set('console.controller.request', $request);
$r->addRoute('GET', '/', $this->container->get('console.controller.index'));
$r->addRoute('GET', '/tube/{tube}', $this->container->get('console.controller.tube'));
$r->addRoute('GET', '/flow/{flow}', $this->container->get('console.controller.flow'));
$r->addRoute('GET', '/kick/{jobId}', $this->container->get('console.controller.kick'));
$r->addRoute('GET', '/delete/{jobId}', $this->container->get('console.controller.delete'));
$r->addRoute('GET', '/job/{jobId}', $this->container->get('console.controller.job'));
$r->addRoute('GET', '/flow/{flow}/job/{jobId}', $this->container->get('console.controller.job'));
}
);
}
Expand Down

0 comments on commit bed3f06

Please sign in to comment.