GithubHelp home page GithubHelp logo

Comments (9)

michaelfreund avatar michaelfreund commented on May 29, 2024 2

Having reconnect functionality after the beanstalkd server is gone away was also crucial for our infrastructure.

As we tried to implement a reconnect logic around fivebeans, we ran into multiple issues. One of them was that if we call worker.watch() inside our worker.on('close') callback function, fivebeans would also add the client listeners (on('connect'), on('error'), etc.) again, which of course would lead to an event emitter memory leak during the reconnection attempts.

Just calling worker.client.connect() during the reconnection attempts fixed the listener issue. However after the beanstalkd server was up again, all new jobs added to the queue had a mysterious hang followed by a DEADLINE_SOON after they were processed. At this point, the handler was already done, but it took a couple of seconds until the job was properly deleted.

So not sure if a reconnection behavior should be part of fivebeans, but one possible solution could be to write a simple wrapper which uses a separate connection to just check the availability of the beanstalkd server and reinitializes the worker if it was able to reconnect.

The following seems to work

const Beanworker = require('fivebeans').worker;
const Reconnect = require('net-socket-reconnect')

var beanHost = "127.0.0.1";
var beanPort = 11300;

var beanServer = Reconnect({
    host: beanHost,
    port: beanPort,
    reconnectInterval: 5000
});

var worker, options = {
    id: 'worker-test-01',
    host: beanHost,
    port: beanPort,
    handlers: {
        test: require('./handler/test')()
    },
    ignoreDefault: true
}

beanServer.on('connect', function () {
    worker = new Beanworker(options);
    worker.start(['test_tube']);
});

beanServer.on('close', function () {
    if (worker) {
        worker = null;
        delete worker;
    }
});

What do you think?

from fivebeans.

ceejbot avatar ceejbot commented on May 29, 2024

Or this is straightforward to roll by hand if necessary. Good bug.

from fivebeans.

rjrodger avatar rjrodger commented on May 29, 2024

I tried rolling it by hand, but I couldn’t get it working and then my brain hurt :)

Any pointers on how to approach this?

On 2 Jul 2014, at 18:18, C J Silverio [email protected] wrote:

Or this is straightforward to roll by hand if necessary. Good bug.


Reply to this email directly or view it on GitHub.

from fivebeans.

JoshWillik avatar JoshWillik commented on May 29, 2024

+1 I have rolled this by hand, and it makes the code a lot more confusing.

@ceejbot Do you have plans to add this to fivebeans, or is this something you'd prefer to see implimented in a wrapper library? If it's the later, I can throw something together no problem.

from fivebeans.

siddo420 avatar siddo420 commented on May 29, 2024

+1

need this behaviour as part of the library itself including reconnect and retry strategies

from fivebeans.

gtamas avatar gtamas commented on May 29, 2024

+1 I need this too

from fivebeans.

wltsmrz avatar wltsmrz commented on May 29, 2024

This thing has automatic reconnects and automatically re-uses / re-watches tubes on reconnect. It doesn't have anything advanced like an exponential backoff etc., but seems to work. Would be nice to get more mileage on it

from fivebeans.

ceejbot avatar ceejbot commented on May 29, 2024

Okay, this is pretty clearly something the module needs to do. Give me a little bit to reacquaint myself with what the heck I was thinking when I wrote it (my first node module ever, if you want to be scared) and make it reconnect. I like the server approach above.

from fivebeans.

michaelfreund avatar michaelfreund commented on May 29, 2024

@ceejbot did you reacquaint with your first baby? 😁 meanwhile our solution runs in production without any problems.

from fivebeans.

Related Issues (20)

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.