Skip to content

Commit

Permalink
Merge pull request #2 from neighborhoods/v1-edge-rounding
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
rhift committed May 23, 2018
2 parents 05a1f41 + a212df0 commit a15854f
Show file tree
Hide file tree
Showing 147 changed files with 1,818 additions and 2,015 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM neighborhoods/php-fpm-phalcon:php7.1_phalcon3.2
ARG PROJECT_NAME=jobs
ARG PROJECT_NAME=kojo

# COMPOSER_TOKEN can also be passed via the COMPOSER_GITHUB_TOKEN file
ARG COMPOSER_TOKEN=placeholder_token_you_must_replace_via_args_in_compose_file
Expand All @@ -26,4 +26,4 @@ RUN bash docker/build.sh \

#CMD ["php-fpm"]

EXPOSE 9000
EXPOSE 9000
7 changes: 6 additions & 1 deletion example/Environment/Parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ parameters:
neighborhoods.kojo.environment.parameters.database_password: '%env(DATABASE_PASSWORD)%'
neighborhoods.kojo.environment.parameters.database_adapter: '%env(DATABASE_ADAPTER)%'
neighborhoods.kojo.environment.parameters.database_host: '%env(DATABASE_HOST)%'
neighborhoods.kojo.environment.parameters.database_name: '%env(DATABASE_NAME)%'
neighborhoods.kojo.environment.parameters.database_name: '%env(DATABASE_NAME)%'
# neighborhoods.kojo.environment.parameters.database_user_name: 'nhds'
# neighborhoods.kojo.environment.parameters.database_password: 'nhds2016'
# neighborhoods.kojo.environment.parameters.database_adapter: 'pgsql'
# neighborhoods.kojo.environment.parameters.database_host: 'pgsql'
# neighborhoods.kojo.environment.parameters.database_name: 'kojo'
47 changes: 40 additions & 7 deletions example/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,53 @@
use Neighborhoods\Kojo\Api;
use Neighborhoods\Pylon\Data\Property;

class Worker
class Worker implements WorkerInterface
{
use Worker\Delegate\Repository\AwareTrait;
use Api\V1\Worker\Service\AwareTrait;
use Property\Defensive\AwareTrait;
use Worker\Queue\AwareTrait;
public const JOB_TYPE_CODE = 'type_code_1';

public function work()
public function work(): WorkerInterface
{
// $newJobScheduler = $this->_getApiV1WorkerService()->getNewJobScheduler();
// $newJobScheduler->setJobTypeCode('type_code_1')
// ->setWorkAtDateTime(new \DateTime('now'))
// ->save()
// ->getJobId();
// // Poll for first message.
// $this->_getWorkerQueue()->waitForNextMessage();

// Schedule another job of the same type.
// $this->_scheduleNextJob();

// Delegate the work for the first message.
// $this->_delegateWork();
//
// // Delegate the work until the observed Queue is empty.
// while ($this->_getWorkerQueue()->hasNextMessage()) {
// $this->_delegateWork();
// }
//
// Tell Kōjō that we are done and all is well.
$this->_getApiV1WorkerService()->requestCompleteSuccess()->applyRequest();

// Fluent interfaces for the love of Pete.
return $this;
}

protected function _delegateWork(): WorkerInterface
{
$workerDelegate = $this->_getWorkerDelegateRepository()->getNewWorkerDelegate();
$workerDelegate->setWorkerQueueMessage($this->_getWorkerQueue()->getNextMessage());
$workerDelegate->businessLogic();

return $this;
}

protected function _scheduleNextJob(): WorkerInterface
{
$newJobScheduler = $this->_getApiV1WorkerService()->getNewJobScheduler();
$newJobScheduler->setJobTypeCode(self::JOB_TYPE_CODE)
->setWorkAtDateTime(new \DateTime('now'))
->save();

return $this;
}
}
19 changes: 0 additions & 19 deletions example/Worker/Bootstrap.php

This file was deleted.

9 changes: 0 additions & 9 deletions example/Worker/Bootstrap.yml

This file was deleted.

18 changes: 18 additions & 0 deletions example/Worker/Delegate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker;

use Neighborhoods\Kojo\Example\Worker;
use Neighborhoods\Pylon\Data;

class Delegate implements DelegateInterface
{
use Data\Property\Defensive\AwareTrait;
use Worker\Queue\Message\AwareTrait;

public function businessLogic(): DelegateInterface
{
return $this;
}
}
38 changes: 38 additions & 0 deletions example/Worker/Delegate/AwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker\Delegate;

use Neighborhoods\Kojo\Example\Worker\DelegateInterface;

trait AwareTrait
{
public function setWorkerDelegate(DelegateInterface $workerDelegate): self
{
$this->_create(DelegateInterface::class, $workerDelegate);

return $this;
}

protected function _getWorkerDelegate(): DelegateInterface
{
return $this->_read(DelegateInterface::class);
}

protected function _getWorkerDelegateClone(): DelegateInterface
{
return clone $this->_getWorkerDelegate();
}

protected function _hasWorkerDelegate(): bool
{
return $this->_exists(DelegateInterface::class);
}

protected function _unsetWorkerDelegate(): self
{
$this->_delete(DelegateInterface::class);

return $this;
}
}
18 changes: 18 additions & 0 deletions example/Worker/Delegate/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker\Delegate;

use Neighborhoods\Kojo\Example\Worker\DelegateInterface;

class Factory implements FactoryInterface
{
use AwareTrait;

public function create(): DelegateInterface
{
$workerDelegate = $this->_getWorkerDelegateClone();

return $workerDelegate;
}
}
38 changes: 38 additions & 0 deletions example/Worker/Delegate/Factory/AwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker\Delegate\Factory;

use Neighborhoods\Kojo\Example\Worker\Delegate\FactoryInterface;

trait AwareTrait
{
public function setWorkerDelegateFactory(FactoryInterface $workerDelegateFactory): self
{
$this->_create(FactoryInterface::class, $workerDelegateFactory);

return $this;
}

protected function _getWorkerDelegateFactory(): FactoryInterface
{
return $this->_read(FactoryInterface::class);
}

protected function _getWorkerDelegateFactoryClone(): FactoryInterface
{
return clone $this->_getWorkerDelegateFactory();
}

protected function _hasWorkerDelegateFactory(): bool
{
return $this->_exists(FactoryInterface::class);
}

protected function _unsetWorkerDelegateFactory(): self
{
$this->_delete(FactoryInterface::class);

return $this;
}
}
11 changes: 11 additions & 0 deletions example/Worker/Delegate/FactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker\Delegate;

use Neighborhoods\Kojo\Example\Worker\DelegateInterface;

interface FactoryInterface
{
public function create(): DelegateInterface;
}
17 changes: 17 additions & 0 deletions example/Worker/Delegate/Repository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker\Delegate;

use Neighborhoods\Kojo\Example\Worker\DelegateInterface;
use Neighborhoods\Kojo\Example\Worker;

class Repository implements RepositoryInterface
{
use Worker\Delegate\Factory\AwareTrait;

public function getNewWorkerDelegate(): DelegateInterface
{
return $this->_getWorkerDelegateFactory()->create();
}
}
38 changes: 38 additions & 0 deletions example/Worker/Delegate/Repository/AwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker\Delegate\Repository;

use Neighborhoods\Kojo\Example\Worker\Delegate\RepositoryInterface;

trait AwareTrait
{
public function setWorkerDelegateRepository(RepositoryInterface $workerDelegateRepository): self
{
$this->_create(RepositoryInterface::class, $workerDelegateRepository);

return $this;
}

protected function _getWorkerDelegateRepository(): RepositoryInterface
{
return $this->_read(RepositoryInterface::class);
}

protected function _getWorkerDelegateRepositoryClone(): RepositoryInterface
{
return clone $this->_getWorkerDelegateRepository();
}

protected function _hasWorkerDelegateRepository(): bool
{
return $this->_exists(RepositoryInterface::class);
}

protected function _unsetWorkerDelegateRepository(): self
{
$this->_delete(RepositoryInterface::class);

return $this;
}
}
11 changes: 11 additions & 0 deletions example/Worker/Delegate/RepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker\Delegate;

use Neighborhoods\Kojo\Example\Worker\DelegateInterface;

interface RepositoryInterface
{
public function getNewWorkerDelegate(): DelegateInterface;
}
13 changes: 13 additions & 0 deletions example/Worker/DelegateInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker;

use Neighborhoods\Kojo\Example\Worker\Queue\MessageInterface;

interface DelegateInterface
{
public function setWorkerQueueMessage(MessageInterface $workerQueueMessage);

public function businessLogic(): DelegateInterface;
}
29 changes: 29 additions & 0 deletions example/Worker/Queue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\Example\Worker;

use Neighborhoods\Kojo\Example\Worker;
use Neighborhoods\Kojo\Example\Worker\Queue\MessageInterface;

class Queue implements QueueInterface
{
use Worker\Queue\Message\AwareTrait;

public function getNextMessage(): MessageInterface
{
return $this->_getWorkerQueueMessageClone();
}

public function waitForNextMessage(): QueueInterface
{
sleep(random_int(0, 10));

return $this;
}

public function hasNextMessage(): bool
{
return (random_int(0, 5) === 5);
}
}
Loading

0 comments on commit a15854f

Please sign in to comment.