Git Product home page Git Product logo

Comments (2)

stravid avatar stravid commented on June 27, 2024

I came up with another solution but stumbled into something like a deadlock. What am I doing wrong @nesquena ?

When I send a SIGTERM to the worker it tries to stop but the tube.put "-" somehow causes a deadlock? The output is "hi", "step 1", "step 2" but never reaches the next puts since it somehow hangs when it puts the job.

#!/usr/bin/env ruby

require "rubygems"
require "bundler/setup"
require "beaneater"

BEANSTALKD_URL = "localhost:11300"
CONTROL_TUBE_NAME = "control-#{1}"
DEFAULT_TUBE_NAME = "test"

class Worker
  def process!
    beanstalk = Beaneater.new BEANSTALKD_URL

    beanstalk.jobs.register DEFAULT_TUBE_NAME do |job|
      10.times do |n|
        sleep 1
        puts n
      end
    end

    beanstalk.jobs.register CONTROL_TUBE_NAME do |job|
      puts "stop"
      stop
    end

    beanstalk.jobs.process!
    beanstalk.close
  end

  def stop!
    puts "hi"
    beanstalk = Beaneater.new BEANSTALKD_URL
    puts "step 1"
    tube = beanstalk.tubes[CONTROL_TUBE_NAME]
    puts "step 2"
    tube.put "-"
    puts "step 3"

    beanstalk.close
    puts "bye"
  end

  private
  def stop
    raise Beaneater::AbortProcessingError
  end
end

worker = Worker.new

Signal.trap "INT"  do
  worker.stop!
end

Signal.trap "TERM" do
  worker.stop!
end

worker.process!

puts "good night"

from beaneater.

stravid avatar stravid commented on June 27, 2024

I would still appreciate advice but can under stand that there is no time for that.

from beaneater.

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.