class Beanstalk::Connection

Overview

This class encapsulates a connection to a Beanstalk instance. Note that this class is not thread safe and instances of it should not be shared.

Defined in:

beanstalk/connection.cr

Constant Summary

DEFAULT_BUFFER_SIZE = "2048"

A constant for the default buffer size to be used when reading data from the Beanstalk server (in bytes).

DEFAULT_CONNECT_TIMEOUT = "10"

Constant for the default socket connect time out setting. This value can be overridden using the BEANSTALK_CR_CONNECT_TIMEOUT environment setting.

DEFAULT_HOST = "localhost"

A constant for the default host name.

DEFAULT_READ_WAIT_TIME = "10000"

Constant for the default read wait time (in milliseconds).

LINE_ENDING = [13_u8, 10_u8]

Constant for the line ending used by Beanstalk commands.

STATS_BUFFER_SIZE = 4096

Constant for the stats job buffer size.

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.open(server : Server) : Connection #

This method creates a Connection object and attempts to connect it to a Beanstalk server instance.


[View source]

Class Method Detail

def self.buffer_size #

Returns the size of the read buffer to be used when fetching data from the server. This value is determined from an environment variable setting with a fall back to a default.


[View source]
def self.open(host : String, port = Server::DEFAULT_PORT) #

This method creates a Connection object and attempts to connect it to a Beanstalk server instance.


[View source]
def self.open #

This method creates a Connection object connecting to Beanstalk on localhost and using the default port.


[View source]

Instance Method Detail

def [](name : String) #

Retrieves a tube with a given name (i.e. a tube that is set to use and watch the named queue).


[View source]
def close #

Terminates the connection to the Beanstalk server.


[View source]
def closed? #

Used to check if the connection is closed.


[View source]
def default_tube #

Fetches the default tube for a Connection (i.e. a tube using and watching the default queue).


[View source]
def open? #

Used to check if the connection is open.


[View source]
def receive #

Attempts to retrieve data from the Beanstalk server.


[View source]
def receive_job #

Attempts to retrieve the data for a job from the Beanstalk server. This is a specialized method as retrieving job data is really the only variable fetch from the Beanstalk server.


[View source]
def receive_stats #

A method intended to fetch the response for a stats-job request.


[View source]
def send(data : Slice(UInt8) | Nil, *parameters) #

Dispatches a message to the Beanstalk server via the socket connection in the appropriate format.


[View source]
def server : Beanstalk::Server #

Fetches details of the server associated with a Connection instance.


[View source]
def socket : Socket #

Fetches the socket for a Connection object. Should generally not be accessed directly.


[View source]
def stats #

Fetches stats for the server attached to a connection.


[View source]