Skip to content

Commit

Permalink
namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
mrHe committed Jun 18, 2021
1 parent 3ef2357 commit a65a611
Show file tree
Hide file tree
Showing 45 changed files with 749 additions and 846 deletions.
20 changes: 20 additions & 0 deletions bin/push.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env php
<?php

require dirname(__DIR__) . '/vendor/autoload.php';

use he\queue\demo\PHPJob;
use he\queue\Resque;

$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
$REDIS_BACKEND = getenv('REDIS_BACKEND');
if (!empty($REDIS_BACKEND)) {
if (empty($REDIS_BACKEND_DB))
Resque::setBackend($REDIS_BACKEND);
else
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
}

Resque::enqueue('PHPJob', PHPJob::class, ['h1']);
Resque::enqueue('PHPJob', PHPJob::class, ['h2']);
Resque::enqueue('PHPJob', PHPJob::class, ['h3']);
198 changes: 93 additions & 105 deletions bin/resque
Original file line number Diff line number Diff line change
@@ -1,129 +1,117 @@
#!/usr/bin/env php
<?php
require dirname(__DIR__) . '/vendor/autoload.php';

// Find and initialize Composer
$files = array(
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../../../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
);

$found = false;
foreach ($files as $file) {
if (file_exists($file)) {
require_once $file;
break;
use he\queue\Resque;
use he\queue\tool\Log;
use he\queue\tool\worker;

function r_exec()
{
$QUEUE = getenv('QUEUE');
if (empty($QUEUE)) {
die("Set QUEUE env var containing the list of queues to work.\n");
}
}

if (!class_exists('Composer\Autoload\ClassLoader', false)) {
die(
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
}

$QUEUE = getenv('QUEUE');
if(empty($QUEUE)) {
die("Set QUEUE env var containing the list of queues to work.\n");
}

/**
* REDIS_BACKEND can have simple 'host:port' format or use a DSN-style format like this:
* - redis://user:pass@host:port
*
* Note: the 'user' part of the DSN URI is required but is not used.
*/
$REDIS_BACKEND = getenv('REDIS_BACKEND');
/**
* REDIS_BACKEND can have simple 'host:port' format or use a DSN-style format like this:
* - redis://user:pass@host:port
*
* Note: the 'user' part of the DSN URI is required but is not used.
*/
$REDIS_BACKEND = getenv('REDIS_BACKEND');

// A redis database number
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
if(!empty($REDIS_BACKEND)) {
if (empty($REDIS_BACKEND_DB))
Resque::setBackend($REDIS_BACKEND);
else
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
}

$logLevel = false;
$LOGGING = getenv('LOGGING');
$VERBOSE = getenv('VERBOSE');
$VVERBOSE = getenv('VVERBOSE');
if(!empty($LOGGING) || !empty($VERBOSE)) {
$logLevel = true;
}
else if(!empty($VVERBOSE)) {
$logLevel = true;
}
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
if (!empty($REDIS_BACKEND)) {
if (empty($REDIS_BACKEND_DB))
Resque::setBackend($REDIS_BACKEND);
else
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
}

$APP_INCLUDE = getenv('APP_INCLUDE');
if($APP_INCLUDE) {
if(!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
$logLevel = false;
$LOGGING = getenv('LOGGING');
$VERBOSE = getenv('VERBOSE');
$VVERBOSE = getenv('VVERBOSE');
if (!empty($LOGGING) || !empty($VERBOSE)) {
$logLevel = true;
} else if (!empty($VVERBOSE)) {
$logLevel = true;
}

require_once $APP_INCLUDE;
}
$APP_INCLUDE = getenv('APP_INCLUDE');
if ($APP_INCLUDE) {
if (!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE (' . $APP_INCLUDE . ") does not exist.\n");
}

require_once $APP_INCLUDE;
}

// See if the APP_INCLUDE containes a logger object,
// If none exists, fallback to internal logger
if (!isset($logger) || !is_object($logger)) {
$logger = new Resque_Log($logLevel);
}
if (!isset($logger) || !is_object($logger)) {
$logger = new Log($logLevel);
}

$BLOCKING = getenv('BLOCKING') !== FALSE;
if (!empty(getenv('BLOCKING'))) {
$BLOCKING = getenv('BLOCKING') !== FALSE;
} else {
$BLOCKING = false;
}

$interval = 5;
$INTERVAL = getenv('INTERVAL');
if(!empty($INTERVAL)) {
$interval = $INTERVAL;
}
$interval = 5;
$INTERVAL = getenv('INTERVAL');
if (!empty($INTERVAL)) {
$interval = $INTERVAL;
}

$count = 1;
$COUNT = getenv('COUNT');
if(!empty($COUNT) && $COUNT > 1) {
$count = $COUNT;
}
$count = 1;
$COUNT = getenv('COUNT');
if (!empty($COUNT) && $COUNT > 1) {
$count = $COUNT;
}

$PREFIX = getenv('PREFIX');
if(!empty($PREFIX)) {
$logger->log(Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', array('prefix' => $PREFIX));
Resque_Redis::prefix($PREFIX);
}

if($count > 1) {
for($i = 0; $i < $count; ++$i) {
$pid = Resque::fork();
if($pid === false || $pid === -1) {
$logger->log(Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', array('count' => $i));
die();
$PREFIX = getenv('PREFIX');
if (!empty($PREFIX)) {
$logger->log(Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', array('prefix' => $PREFIX));
Redis::prefix($PREFIX);
}

if ($count > 1) {
for ($i = 0; $i < $count; ++$i) {
$pid = Resque::fork();
if ($pid === false || $pid === -1) {
$logger->log(Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', array('count' => $i));
die();
} // Child, start the worker
else if (!$pid) {
$queues = explode(',', $QUEUE);
$worker = new Worker($queues);
$worker->setLogger($logger);
$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
$worker->work($interval, $BLOCKING);
break;
}
}
// Child, start the worker
else if(!$pid) {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->setLogger($logger);
$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
$worker->work($interval, $BLOCKING);
break;
} // Start a single worker
else {
$queues = explode(',', $QUEUE);
$worker = new Worker($queues);
$worker->setLogger($logger);

$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
file_put_contents($PIDFILE, getmypid()) or
die('Could not write PID information to ' . $PIDFILE);
}

$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
$worker->work($interval, $BLOCKING);
}
}
// Start a single worker
else {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->setLogger($logger);

$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
file_put_contents($PIDFILE, getmypid()) or
die('Could not write PID information to ' . $PIDFILE);
}

$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
$worker->work($interval, $BLOCKING);
}
?>
r_exec();
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
}
],
"require": {
"php": ">=5.6.0",
"php": ">=7.1.0",
"ext-pcntl": "*",
"ext-redis": "*",
"ext-json": "*",
"psr/log": "~1.0"
},
"suggest": {
"ext-proctitle": "Allows php-resque to rename the title of UNIX processes to show the status of a worker.",
"ext-redis": "Native PHP extension for Redis connectivity. Credis will automatically utilize when available."
"ext-proctitle": "Allows php-resque to rename the title of UNIX processes to show the status of a worker."
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
Expand All @@ -33,8 +33,8 @@
"bin/resque"
],
"autoload": {
"psr-0": {
"Resque": "lib"
"psr-4": {
"he\\queue\\": "./src"
}
}
}
8 changes: 0 additions & 8 deletions demo/bad_job.php

This file was deleted.

25 changes: 0 additions & 25 deletions demo/init.php

This file was deleted.

8 changes: 0 additions & 8 deletions demo/long_job.php

This file was deleted.

8 changes: 0 additions & 8 deletions demo/php_error_job.php

This file was deleted.

26 changes: 0 additions & 26 deletions demo/queue.php

This file was deleted.

7 changes: 0 additions & 7 deletions demo/resque.php

This file was deleted.

16 changes: 9 additions & 7 deletions extras/sample-plugin.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
// Somewhere in our application, we need to register:
Resque_Event::listen('afterEnqueue', array('My_Resque_Plugin', 'afterEnqueue'));
Resque_Event::listen('beforeFirstFork', array('My_Resque_Plugin', 'beforeFirstFork'));
Resque_Event::listen('beforeFork', array('My_Resque_Plugin', 'beforeFork'));
Resque_Event::listen('afterFork', array('My_Resque_Plugin', 'afterFork'));
Resque_Event::listen('beforePerform', array('My_Resque_Plugin', 'beforePerform'));
Resque_Event::listen('afterPerform', array('My_Resque_Plugin', 'afterPerform'));
Resque_Event::listen('onFailure', array('My_Resque_Plugin', 'onFailure'));
use he\queue\tool\Event;

Event::listen('afterEnqueue', array('My_Resque_Plugin', 'afterEnqueue'));
Event::listen('beforeFirstFork', array('My_Resque_Plugin', 'beforeFirstFork'));
Event::listen('beforeFork', array('My_Resque_Plugin', 'beforeFork'));
Event::listen('afterFork', array('My_Resque_Plugin', 'afterFork'));
Event::listen('beforePerform', array('My_Resque_Plugin', 'beforePerform'));
Event::listen('afterPerform', array('My_Resque_Plugin', 'afterPerform'));
Event::listen('onFailure', array('My_Resque_Plugin', 'onFailure'));

class My_Resque_Plugin
{
Expand Down
Loading

0 comments on commit a65a611

Please sign in to comment.