Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
phpunit.xml
vendor/

composer.lock
34 changes: 26 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
language: php

sudo: false

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

php:
- 5.5
- 5.6
- 5.5
- 5.6
- 7.0

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev
matrix:
include:
- php: 7.0
env: SYMFONY_VERSION="2.3.*"
- php: 7.0
env: SYMFONY_VERSION="2.7.*"
- php: 7.0
env: SYMFONY_VERSION="2.8.*"
- php: 7.0
env: SYMFONY_VERSION="3.0.*"

script: phpunit --coverage-clover clover
before_install:
- composer self-update
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/symfony:${SYMFONY_VERSION}; fi

after_success:
- curl -sL https://bit.ly/artifact-uploader | php
install: composer update

script: phpunit --coverage-clover clover

after_success: curl -sL https://bit.ly/artifact-uploader | php
19 changes: 18 additions & 1 deletion Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use JMS\JobQueueBundle\Exception\LogicException;
use JMS\JobQueueBundle\Exception\InvalidArgumentException;
use JMS\JobQueueBundle\Event\NewOutputEvent;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\Process;
use JMS\JobQueueBundle\Entity\Job;
Expand Down Expand Up @@ -428,9 +429,25 @@ private function getCommandProcessBuilder()
$pb->add('exec');
}

// Localize the `console` command
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we detect the console command based on how this command itself was started?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you do that?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you check the content of $_SERVER, there should be everything you need.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much more complicated as the user can use either php console or console so we would have to parse the input.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realpath($_SERVER['SCRIPT_FILENAME'])
// or
realpath($_SERVER['argv'][0])

should do the trick, whether the php executable is mentioned or not.

This looks safer than expecting to find a single file called console somewhere under the root dir - which is a convention that not all projects might follow.

Copy link
Author

@GuilhemN GuilhemN Jul 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nclavaud could you send a PR on my repo ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nclavaud i don't think it will work when using phpunit :/

$finder = new Finder();
$finder
->files()
->name('console')
->depth('< 2')
->in(dirname($this->getContainer()->getParameter('kernel.root_dir')));

if (!count($finder)) {
throw new \RuntimeException('JMSJobQueueBundle wasn\'t able to find your `console` command.');
}
foreach ($finder as $file) {
$console = $file->getRealPath();
break;
}

$pb
->add('php')
->add($this->getContainer()->getParameter('kernel.root_dir').'/console')
->add($console)
->add('--env='.$this->env)
;

Expand Down
5 changes: 3 additions & 2 deletions Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpKernel\Exception\FlattenException as LegacyFlattenException;
use Symfony\Component\HttpKernel\KernelInterface;

/**
Expand Down Expand Up @@ -89,7 +90,7 @@ private function saveDebugInformation(\Exception $ex = null)
'id' => $jobId,
'memoryUsage' => memory_get_peak_usage(),
'memoryUsageReal' => memory_get_peak_usage(true),
'trace' => serialize($ex ? FlattenException::create($ex) : null),
'trace' => serialize($ex ? (class_exists(FlattenException::class) ? FlattenException::create($ex) : LegacyFlattenException::create($ex)) : null),
),
array(
'id' => \PDO::PARAM_INT,
Expand Down
10 changes: 4 additions & 6 deletions Controller/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;

class JobController
{
/** @DI\Inject("doctrine") */
private $registry;

/** @DI\Inject */
private $request;

/** @DI\Inject */
private $router;

Expand All @@ -31,7 +29,7 @@ class JobController
* @Route("/", name = "jms_jobs_overview")
* @Template("JMSJobQueueBundle:Job:overview.html.twig")
*/
public function overviewAction()
public function overviewAction(Request $request)
{
$lastJobsWithError = $this->getRepo()->findLastJobsWithError(5);

Expand All @@ -46,8 +44,8 @@ public function overviewAction()
}

$pager = new Pagerfanta(new DoctrineORMAdapter($qb));
$pager->setCurrentPage(max(1, (integer) $this->request->query->get('page', 1)));
$pager->setMaxPerPage(max(5, min(50, (integer) $this->request->query->get('per_page', 20))));
$pager->setCurrentPage(max(1, (integer) $request->query->get('page', 1)));
$pager->setMaxPerPage(max(5, min(50, (integer) $request->query->get('per_page', 20))));

$pagerView = new TwitterBootstrapView();
$router = $this->router;
Expand Down
8 changes: 6 additions & 2 deletions Entity/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
use Doctrine\ORM\Mapping as ORM;
use JMS\JobQueueBundle\Exception\InvalidStateTransitionException;
use JMS\JobQueueBundle\Exception\LogicException;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpKernel\Exception\FlattenException as LegacyFlattenException;

/**
* @ORM\Entity(repositoryClass = "JMS\JobQueueBundle\Entity\Repository\JobRepository")
Expand Down Expand Up @@ -569,8 +570,11 @@ public function getCheckedAt()
return $this->checkedAt;
}

public function setStackTrace(FlattenException $ex)
public function setStackTrace($ex)
{
if(!$ex instanceof FlattenException && !$ex instanceof LegacyFlattenException) {
throw new \InvalidArgumentException(sprintf('Parameter of %s must be an instance of %s or %s.', __METHOD__, FlattenException::class, LegacyFlattenException::class));
}
$this->stackTrace = $ex;
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/Functional/ConcurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testHighConcurrency()
unlink($filename);

for ($i=0; $i<5; $i++) {
$this->assertSame(2, substr_count($logOutput, 'Job-'.$i));
$this->assertSame(2, substr_count($logOutput, 'Job-'.$i), sprintf('"%s" has not been found twice in "%s"', 'Job-'.$i, $logOutput));
}

$workers = array();
Expand Down Expand Up @@ -116,7 +116,7 @@ private function waitUntilJobsProcessed($maxRuntime)

private function startWorker($name)
{
$proc = new Process('exec '.PHP_BINARY.' '.escapeshellarg(__DIR__.'/console').' jms-job-queue:run --worker-name='.$name, null, array(
$proc = new Process('exec '.PHP_BINARY.' '.escapeshellarg(__DIR__.'/../consolefolder/console').' jms-job-queue:run --worker-name='.$name, null, array(
'SYMFONY_CONFIG' => $this->configFile,
));
$proc->start();
Expand All @@ -133,4 +133,4 @@ private function startWorker($name)

$this->processes[] = $proc;
}
}
}
4 changes: 2 additions & 2 deletions Tests/Functional/SignalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testControlledExit()
$this->markTestSkipped('PCNTL extension is not loaded.');
}

$proc = new Process('exec '.PHP_BINARY.' '.escapeshellarg(__DIR__.'/console').' jms-job-queue:run --worker-name=test --verbose --max-runtime=999999');
$proc = new Process('exec '.PHP_BINARY.' '.escapeshellarg(__DIR__.'/../consolefolder/console').' jms-job-queue:run --worker-name=test --verbose --max-runtime=999999');
$proc->start();

usleep(5E5);
Expand Down Expand Up @@ -65,4 +65,4 @@ private function assertTrueWithin($seconds, callable $block, callable $failureHa
usleep(2E5);
}
}
}
}
12 changes: 0 additions & 12 deletions Tests/bootstrap.php

This file was deleted.

4 changes: 2 additions & 2 deletions Tests/Functional/console → Tests/consolefolder/console
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once __DIR__.'/AppKernel.php';
require_once __DIR__.'/../Functional/AppKernel.php';

use JMS\JobQueueBundle\Console\Application;
use JMS\JobQueueBundle\Tests\Functional\AppKernel;
Expand All @@ -9,4 +9,4 @@ $kernel = new AppKernel(getenv('SYMFONY_CONFIG') ?: 'persistent_db.yml');
$kernel->boot();

$app = new Application($kernel);
$app->run();
$app->run();
41 changes: 20 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,37 @@
}
],
"require": {
"php": "^5.5.0 || ^7.0",
"symfony/framework-bundle": ">=2.1,<3.0-dev",
"doctrine/common": ">=2.3,<3.0",
"jms/di-extra-bundle": ">=1.1,<2.0"
"php": "^5.5|^7.0",
"symfony/framework-bundle": "^2.1|^3.0",
"symfony/dependency-injection": "^2.3|^3.0",
"symfony/process": "^2.3|^3.0",
"symfony/finder": "^2.1|^3.0",
"doctrine/common": "^2.3",
"jms/di-extra-bundle": "^1.1"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "*",
"sensio/framework-extra-bundle": "*",
"symfony/class-loader": "*",
"symfony/yaml": "*",
"symfony/browser-kit": "*",
"symfony/finder": "*",
"symfony/css-selector": "*",
"symfony/process": "*",
"doctrine/doctrine-bundle": "*",
"doctrine/orm": "*",
"symfony/twig-bundle": "*",
"symfony/form": "*",
"symfony/validator": "*",
"pagerfanta/pagerfanta": "dev-master",
"phpunit/phpunit": "^5.2"
"sensio/framework-extra-bundle": "^2.0|^3.0",
"symfony/class-loader": "^2.1|^3.0",
"symfony/yaml": "^2.1|^3.0",
"symfony/browser-kit": "^2.1|^3.0",
"symfony/css-selector": "^2.1|^3.0",
"symfony/twig-bundle": "^2.1|^3.0",
"symfony/form": "^2.1|^3.0",
"symfony/validator": "^2.1|^3.0",
"doctrine/doctrine-bundle": "^1.5@dev",
"doctrine/orm": "^2.3",
"pagerfanta/pagerfanta": "^1.0@dev",
"symfony/phpunit-bridge": "^3.0"
},
"suggest": {
"pagerfanta/pagerfanta": "Required when using the webinterface.",
"sensio/framework-extra-bundle": "Required when using the webinterface.",
"symfony/twig-bundle": "Required when using the webinterface."
},
"minimum-stability": "dev",
"autoload": {
"psr-0": { "JMS\\JobQueueBundle": "" }
"psr-4": { "JMS\\JobQueueBundle\\": "" }
},
"target-dir": "JMS/JobQueueBundle",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
Expand Down
Loading