Git Product home page Git Product logo

beanstalk's People

Contributors

arraysnl avatar bilge avatar eislambey avatar ekhvalov avatar hskrasek avatar kelunik avatar kyl0b1te avatar markkimsal avatar mmenozzi avatar weysan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beanstalk's Issues

make send protected (send is private)

I'm trying to subclass the client to add my own method (statsJob to get stats) but I cannot call $this->send from a subclass because it's private and not protected.

Yield expression can only be used inside a function

Hi

I get this error: "PHP Fatal error: The "yield" expression can only be used inside a function" when I run this code:

// Autoload classes
require_once realpath(__DIR__) . '/vendor/autoload.php';

$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

// This step not required if you included a tube query parameter when creating the client
$beanstalk->use('testtube');

while([$jobId, $jobData] = yield $beanstalk->reserve()) {
   print_r($jobId);
}

Steps to reproduce:

  1. Run: "composer require amphp/beanstalk"
  2. Create script with code from above
  3. Run: "php -f client.php"

Which yields the aforementioned error.

Setup:
Debian Jessie

php -v
PHP 7.2.3

uname -a
4.9.0-6-amd64

What is the problem here?

Wrong return types

Hi,
I think that the send callbacks of the following BeanstalkClient methods have the wrong return type:

  • \Amp\Beanstalk\BeanstalkClient::delete: return type hint is int but it returns bool (anyway this doesn't raise an error)
  • \Amp\Beanstalk\BeanstalkClient::bury: return type hint is int but it returns bool (anyway this doesn't raise an error)
  • \Amp\Beanstalk\BeanstalkClient::touch: return type hint is int but it returns bool (anyway this doesn't raise an error)
  • \Amp\Beanstalk\BeanstalkClient::release: return type hint is int but it returns string (this raises a fatal error)

What do you think?

With big payload reserved job is not the same as the put one

It seems that for jobs with a big payload (for example a 64k payload) the reserve function doesn't return the entire payload which was put. Given the following script:

<?php
declare(strict_types=1);

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

\Amp\Loop::run(function () {
    $client = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");
    yield $client->put(str_repeat('*', 65535));
    yield $client->watch('default');
    list($jobId, $job) = yield $client->reserve();
    echo "Job $jobId, length " . strlen($job) . PHP_EOL;
//    yield $client->bury($jobId);
    $client->quit();
    \Amp\Loop::stop();
});

The output is:

Job 1, length 65518

But it should be:

Job 1, length 65535

It seems a weird buffering issue because if you try to uncomment the bury function call the output become:

Job 1, length 65518
PHP Fatal error:  Uncaught Amp\Beanstalk\BeanstalkException: Unknown response: ***************** in /tmp/vendor/amphp/beanstalk/src/BeanstalkClient.php:203
Stack trace:
#0 /tmp/vendor/amphp/beanstalk/src/BeanstalkClient.php(74): Amp\Beanstalk\BeanstalkClient->Amp\Beanstalk\{closure}(Array)
#1 [internal function]: Amp\Beanstalk\BeanstalkClient->Amp\Beanstalk\{closure}()
#2 /tmp/vendor/amphp/amp/lib/Coroutine.php(76): Generator->send(Array)
#3 /tmp/vendor/amphp/amp/lib/Internal/Placeholder.php(130): Amp\Coroutine->Amp\{closure}(NULL, Array)
#4 /tmp/vendor/amphp/amp/lib/Deferred.php(45): class@anonymous->resolve(Array)
#5 /tmp/vendor/amphp/beanstalk/src/BeanstalkClient.php(38): Amp\Deferred->resolve(Array)
#6 /tmp/vendor/amphp/beanstalk/src/Connection.php(44): Amp\Beanstalk\BeanstalkClient->Amp\Beanstal in /tmp/vendor/amphp/beanstalk/src/BeanstalkClient.php on line 203

I think this happens because the remaining part of the job payload is then treated as the response of the bury command.

I pushed the reserved-not-as-put-fix branch with a failing test about this issue.

Fix return types in next major version

Methods to fix:

  • \Amp\Beanstalk\BeanstalkClient::delete: return type hint is int but it returns bool (anyway this doesn't raise an error)
  • \Amp\Beanstalk\BeanstalkClient::bury: return type hint is int but it returns bool (anyway this doesn't raise an error)
  • \Amp\Beanstalk\BeanstalkClient::touch: return type hint is int but it returns bool (anyway this doesn't raise an error)

See #11.

Call to a member function resolve on null

Hi,
I use the AMP's beanstalk client with https://github.com/webgriffe/esb.
Sometimes (but I never found the cause) the ESB application crashes with the following error:

PHP Fatal error:  Uncaught Error: Call to a member function resolve() on null in vendor/amphp/beanstalk/src/BeanstalkClient.php:38

That resolve is the one inside the response event callback of the client:

        $this->connection->addEventHandler("response", function ($response) {
            /** @var Deferred $deferred */
            $deferred = array_shift($this->deferreds);
            if ($response instanceof Throwable) {
                $deferred->fail($response);
            } else {
                $deferred->resolve($response);
            }
        });

And this is strange because only Deferred instances are added to the BeanstalkClient::$deferreds array.

array_unshift($this->deferreds, new Deferred);

$this->deferreds[] = $deferred = new Deferred;

So it seems that, sometimes, the response event is fired when the BeanstalkClient::$deferreds array is empty. Indeed, array_shift returns null if the array is empty (http://php.net/manual/en/function.array-shift.php).

I don't know how this could happen but happens...

Maybe we can prevent such error with a simple check:

        $this->connection->addEventHandler("response", function ($response) {
            if (empty($this->deferreds)) {
                return;
            }
            /** @var Deferred $deferred */
            $deferred = array_shift($this->deferreds);
            if ($response instanceof Throwable) {
                $deferred->fail($response);
            } else {
                $deferred->resolve($response);
            }
        });

But I don't know if the right thing to do.
@kelunik what do you think?

Unexpected connection close

Hello. First of all thank you for your work.
We faced a problem that happens when beanstalk close connection after daemon reboot for example. When connection is closed reserve promise does not received any answer and stuck.

CONTACT FORM ERROR..DON'T KNOW WHY THIS IS COMING

Please, Sir, resolve my problem by providing proper solutions. My contact us page is not working while it used with amp plugin. But after deactivating the amp plugin the form is working properly.
So please find the issue coming in the screenshot below.
Screenshot (22)

Add documentation

There's already a stub available in ./docs. The README should contain a small example. All further docs should be in ./docs, so they're available on the website.

Stream continues to be open even though nothing can be fetched

Hi

I use this code to fetch jobs:

// Autoload classes
require_once realpath(__DIR__) . '/vendor/autoload.php';

$client = new Amp\Beanstalk\BeanstalkClient('tcp://127.0.0.1:11300');
$client->watch('testtube');
$client->ignore('default');

Amp\Loop::run(function() use ($client)
{
	Amp\Loop::repeat($msInterval = 1, function() use ($client)
	{
		$client->reserve(0)->onResolve(function($error, $result) use ($client)
		{
			$id = (int) $result['0'];

			if ($id <= 0)
				return;

			echo "Handle job: " . $id . "\n";

			$client->delete($id)->onResolve(function($error, $result) use ($client, $id)
			{
				echo "Delete job: " . $id . "\n";
			});
		});
	});
});

I use stunnel4 (guide: https://www.digitalocean.com/community/tutorials/how-to-encrypt-traffic-to-redis-with-stunnel-on-ubuntu-16-04) to create a tunnel between machine1 (running Beanstalk) and machine2 (consumer).

When using stunnel4 it will keep the port: 11300 on 127.0.0.1 open all the time, even though the remote port has closed due to either restart or the process stops.

However amphp/beanstalk doesn't timeout the connection as it sees the connection as still alive because the local port doesn't close - so the stream doesn't close.

If I add $stats = yield $client->getSystemStats(); right after repeat, it will close the connection and fail with: PHP Fatal error: Uncaught Amp\ByteStream\StreamException: The stream was closed by the peer.

Is it however not that great to continuously send a command to request data, because it will waste ressources, and may slow down reserving jobs.

TLDR: amphp/beanstalk doesn't recognize stream closed when reserving.

Missing methods for kick and kick-job

As the title says, there are methods for either kicking jobs up to N boundary, or kicking a job by id. Typically would be used to kick buried jobs back into the ready portion of a tube.

Add examples

We should have a few examples, a producer and a consumer at least.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.