Skip to content

Commit

Permalink
PLT-299 Remove Resque event listeners from JobBase constructor (#147)
Browse files Browse the repository at this point in the history
* PLT-299 Remove Resque event listeners from JobBase constructor
* Improve how tests run in CI
* Define job property, self-injected by Resque_Job
* Update requirements in README
  • Loading branch information
mrliptontea authored Jan 22, 2024
1 parent 9d4f000 commit d89fdc0
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 38 deletions.
7 changes: 5 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ jobs:
steps:
- checkout
- run: composer install
- run: ./vendor/bin/phpunit test/unit
- run: ./vendor/bin/phpunit test/performance
- run: composer test -- --log-junit test-results/junit.xml
- store_test_results:
path: test-results/junit.xml
- store_artifacts:
path: test-results/junit.xml

workflows:
build_and_test:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tags
atlassian-ide-plugin.xml

composer.lock
test-results

test/performance/rest-interface/.vagrant/
test/performance/rest-interface/config/tripod-config-*.json
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Quickstart
```php
require_once("tripod.inc.php");

// Queue worker must register these event listeners
Resque_Event::listen('beforePerform', [\Tripod\Mongo\Jobs\JobBase::class, 'beforePerform']);
Resque_Event::listen('onFailure', [\Tripod\Mongo\Jobs\JobBase::class, 'onFailure']);

\Tripod\Config::setConfig($conf); // set the config, usually read in as JSON from a file

$tripod = new Driver(
Expand Down Expand Up @@ -79,9 +83,9 @@ $tripod->saveChanges(
Requirements
----

PHP >= 5.4.x
PHP >= 5.5

Mongo 2.6.x and up.
Mongo 3.2.x and up.

MongoDB PHP driver version. http://mongodb.github.io/mongo-php-driver/#installation

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
},
"autoload": {
"classmap": ["src/"]
},
"scripts": {
"test": "phpunit"
}
}
15 changes: 15 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./test/bootstrap.php">
<php>
<ini name="memory_limit" value="512M" />
</php>

<testsuites>
<testsuite name="Tripod_Performance_Tests">
<directory>test/performance</directory>
</testsuite>
<testsuite name="Tripod_Unit_Tests">
<directory>test/unit</directory>
</testsuite>
</testsuites>
</phpunit>
24 changes: 18 additions & 6 deletions src/mongo/base/JobBase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
*/
abstract class JobBase extends \Tripod\Mongo\DriverBase
{
/**
* Resque Job arguments, set by Resque_Job_Factory
* @var array
*/
public $args;

/**
* Resque Job queue, set by Resque_Job_Factory
* @var string
*/
public $queue;

/**
* Resque Job
* @var \Resque_Job
*/
public $job;

private $tripod;
const TRIPOD_CONFIG_KEY = 'tripodConfig';
const TRIPOD_CONFIG_GENERATOR = 'tripodConfigGenerator';
Expand All @@ -29,12 +47,6 @@ abstract class JobBase extends \Tripod\Mongo\DriverBase
/** @var \Tripod\Timer */
protected $timer;

public function __construct()
{
\Resque_Event::listen('beforePerform', [self::class, 'beforePerform']);
\Resque_Event::listen('onFailure', [self::class, 'onFailure']);
}

/**
* The main method of the job
*
Expand Down
7 changes: 7 additions & 0 deletions test/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

// Queue worker must register these event listeners
Resque_Event::listen('beforePerform', [\Tripod\Mongo\Jobs\JobBase::class, 'beforePerform']);
Resque_Event::listen('onFailure', [\Tripod\Mongo\Jobs\JobBase::class, 'onFailure']);
7 changes: 0 additions & 7 deletions test/performance/phpunit.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use \MongoDB\Client;
use \MongoDB\Driver\Exception\ConnectionTimeoutException;

class MongoTripodConfigTest extends MongoTripodTestBase
class MongoTripodConfigUnitTest extends MongoTripodTestBase
{
/**
* @var \Tripod\Mongo\Config
Expand Down
20 changes: 0 additions & 20 deletions test/unit/phpunit.xml

This file was deleted.

0 comments on commit d89fdc0

Please sign in to comment.