Skip to content

Commit

Permalink
first committ
Browse files Browse the repository at this point in the history
  • Loading branch information
Webonaute committed Jun 25, 2019
0 parents commit 06d058c
Show file tree
Hide file tree
Showing 12 changed files with 634 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
composer.lock
composer.phar
vendor
bin
.idea
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: php

php:
- 7.4
- 7.3
- 7.2
- 7.1
- 7.0

sudo: false

cache:
directories:
- $HOME/.composer/cache

env:
global:
- SYMFONY_DEPRECATIONS_HELPER="weak"

before_install:
- phpenv config-rm xdebug.ini || true
- phpenv rehash;
- composer self-update

install: composer install --no-interaction --no-progress

before_script: mkdir Webonaute && ln -s ../ Webonaute/WebonauteDoctrineDataLockingBundle
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) Mathieu Delisle <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Doctrine DataLocking Bundle #

[![Latest Stable Version](https://poser.pugx.org/webonaute/doctrine-datalocking-bundle/v/stable.svg)](https://packagist.org/packages/webonaute/doctrine-datalocking-bundle) [![Total Downloads](https://poser.pugx.org/webonaute/doctrine-datalocking-bundle/downloads.svg)](https://packagist.org/packages/webonaute/doctrine-datalocking-bundle) [![Latest Unstable Version](https://poser.pugx.org/webonaute/doctrine-datalocking-bundle/v/unstable.svg)](https://packagist.org/packages/webonaute/doctrine-datalocking-bundle) [![License](https://poser.pugx.org/webonaute/doctrine-datalocking-bundle/license.svg)](https://packagist.org/packages/webonaute/doctrine-datalocking-bundle)

<!--ts-->
* [Doctrine DataLocking Bundle](#doctrine-datalocking-bundle)
* [About](#about)
* [Branches](#branches)
* [Installation](#installation)
* [Documentation](#documentation)
* [Configure Entity](#configure-entity)
* [Lock data who are due.](#lock-data-who-are-due)
* [Get objects related to one lock ID.](#get-objects-related-to-one-lock-id)
* [Unlock object after usage.](#unlock-object-after-usage)
* [Consume object after usage with deleteLocked](#consume-object-after-usage-with-deletelocked)
* [License](#license)

<!-- Added by: mdelisle, at: Tue 25 Jun 2019 14:12:44 EDT -->

<!--te-->

## About ##

Lock a list of object of the same entity to be executed by a single processor. When the lock is aquire, the lock ID generated can be use by a processor to execute action on that locked list.

## Branches ##

* Use version `1.0-dev` for Symfony 4.0+. [![build status](https://travis-ci.org/webonaute/DoctrineDataLockingBundle.svg?branch=master)](https://travis-ci.org/webonaute/DoctrineDataLockingBundle)

## Installation ##

This bundle is available via [composer](https://github.com/composer/composer), find it on [packagist](https://packagist.org/packages/webonaute/doctrine-datalocking-bundle).

Run :
```composer require webonaute/doctrine-datalocking-bundle 1.0-dev```

## Documentation ##

### Configure Entity
Add this snipped code to your entity.

```
use Webonaute\DoctrineDataLockingBundle\Entity\ProcessLock;
...
/**
* @var ProcessLock
*
* @ORM\Embedded(class=ProcessLock::class)
*/
private $processLock;
...
public function __construct()
{
...
$this->processLock = new ProcessLock();
}
/**
* @return ProcessLock
*/
public function getProcessLock(): ProcessLock
{
return $this->processLock;
}
```

### Lock data who are due.
```
while (null !== $lockId = $dataLockerService->lock(Entity::class, 500, $extraWhere, $lockAt)) {
$this->queue->push($lockId);
}
```

### Get objects related to one lock ID.
```
$lockedEntities = $dataLockerService->findLocked(Entity::class, $lockId);
```

### Unlock object after usage.
This will simply unlock the object. To consume the entity object, use deleteLocked method.
```
$lockedEntities = $dataLockerService->unlock(Entity::class, $lockId);
```

### Consume object after usage with deleteLocked
This method will consume the entity object by deleting it from the database.
```
$lockedEntities = $dataLockerService->deleteLocked(Entity::class, $lockId);
```

## License ##

See [LICENSE](LICENSE).
63 changes: 63 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "webonaute/doctrine-datalocking-bundle",
"type": "symfony-bundle",
"description": "Lock a list of object of the same entity to be executed by a single processor. When the lock is aquire, the lock ID generated can be use by a processor to execute action on that locked list.",
"keywords": [
"data",
"doctrine",
"symfony",
"bundle",
"symfony4",
"doctrine",
"locking",
"lock",
"process",
"performance",
"database",
"queue"
],
"homepage": "https://github.com/Webonaute/DoctrineDataLockingBundle",
"license": "MIT",
"authors": [
{
"name": "Mathieu Delisle",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.2",
"symfony/framework-bundle": "^3.4|^4.1",
"symfony/config": "^3.4|^4.1",
"symfony/console": "^3.4|^4.1",
"symfony/dependency-injection": "^3.4|^4.1",
"doctrine/doctrine-bundle": "^1.8"
},
"require-dev": {
"symfony/monolog-bundle": "^3.0",
"symfony/console": "^4.1",
"symfony/phpunit-bridge": "^4.1",
"symfony/browser-kit": "^4.1",
"symfony/profiler-pack": "^1.0",
"symfony/twig-bundle": "^4.1",
"phpunit/phpunit": "^6.0|^7.0"
},
"autoload": {
"psr-4": {
"Webonaute\\DoctrineDataLockingBundle\\": "./src"
}
},
"config": {
"bin-dir": "bin/",
"sort-packages": true
},
"support": {
"email": "[email protected]",
"issue": "https://github.com/Webonaute/DoctrineDataLockingBundle/issues",
"source": "https://github.com/Webonaute/DoctrineDataLockingBundle"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}
24 changes: 24 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true" processIsolation="false" stopOnFailure="false" bootstrap="./src/Tests/autoload.php.dist">
<php>
<ini name="error_reporting" value="-1" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
</php>
<testsuites>
<testsuite name="RedisBundle Test Suite">
<directory>./src/Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
<exclude>
<directory>./src/Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
30 changes: 30 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Webonaute\DoctrineDataLockingBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{

/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
30 changes: 30 additions & 0 deletions src/DependencyInjection/DoctrineDataLockingBundleExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Webonaute\DoctrineDataLockingBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class DoctrineDataLockingBundleExtension extends Extension
{

/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config')
);
$loader->load('services.yaml');
}
}
Loading

0 comments on commit 06d058c

Please sign in to comment.