Class: Beanstalk::RawConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/beanstalk-client/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr, jptr = self) ⇒ RawConnection

Returns a new instance of RawConnection.



30
31
32
33
34
# File 'lib/beanstalk-client/connection.rb', line 30

def initialize(addr, jptr=self)
  @addr = addr
  @jptr = jptr
  connect
end

Instance Attribute Details

#addrObject (readonly)

Returns the value of attribute addr.



28
29
30
# File 'lib/beanstalk-client/connection.rb', line 28

def addr
  @addr
end

Instance Method Details

#bury(id, pri) ⇒ Object



89
90
91
92
93
# File 'lib/beanstalk-client/connection.rb', line 89

def bury(id, pri)
  @socket.write("bury #{id} #{pri}\r\n")
  check_resp('BURIED')
  :ok
end

#closeObject



44
45
46
47
# File 'lib/beanstalk-client/connection.rb', line 44

def close
  @socket.close
  @socket = nil
end

#connectObject



36
37
38
39
40
41
42
# File 'lib/beanstalk-client/connection.rb', line 36

def connect
  host, port = addr.split(':')
  @socket = TCPSocket.new(host, port.to_i)

  # Don't leak fds when we exec.
  @socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
end

#delete(id) ⇒ Object



77
78
79
80
81
# File 'lib/beanstalk-client/connection.rb', line 77

def delete(id)
  @socket.write("delete #{id}\r\n")
  check_resp('DELETED')
  :ok
end

#ignore(tube) ⇒ Object



105
106
107
108
# File 'lib/beanstalk-client/connection.rb', line 105

def ignore(tube)
  @socket.write("ignore #{tube}\r\n")
  check_resp('WATCHING')[0]
end

#job_stats(id) ⇒ Object



115
116
117
118
# File 'lib/beanstalk-client/connection.rb', line 115

def job_stats(id)
  @socket.write("stats-job #{id}\r\n")
  read_yaml('OK')
end

#list_tube_usedObject



130
131
132
133
# File 'lib/beanstalk-client/connection.rb', line 130

def list_tube_used()
  @socket.write("list-tube-used\r\n")
  check_resp('USING')[0]
end

#list_tubesObject



125
126
127
128
# File 'lib/beanstalk-client/connection.rb', line 125

def list_tubes()
  @socket.write("list-tubes\r\n")
  read_yaml('OK')
end

#list_tubes_watchedObject



135
136
137
138
# File 'lib/beanstalk-client/connection.rb', line 135

def list_tubes_watched()
  @socket.write("list-tubes-watched\r\n")
  read_yaml('OK')
end

#peekObject



58
59
60
61
62
63
64
65
# File 'lib/beanstalk-client/connection.rb', line 58

def peek()
  @socket.write("peek\r\n")
  begin
    Job.new(@jptr, *read_job('FOUND'))
  rescue UnexpectedResponse
    nil
  end
end

#peek_job(id) ⇒ Object



67
68
69
70
# File 'lib/beanstalk-client/connection.rb', line 67

def peek_job(id)
  @socket.write("peek #{id}\r\n")
  Job.new(@jptr, *read_job('FOUND'))
end

#put(body, pri = 65536, delay = 0, ttr = 120) ⇒ Object



49
50
51
52
# File 'lib/beanstalk-client/connection.rb', line 49

def put(body, pri=65536, delay=0, ttr=120)
  @socket.write("put #{pri} #{delay} #{ttr} #{body.size}\r\n#{body}\r\n")
  check_resp('INSERTED', 'BURIED')[0].to_i
end

#release(id, pri, delay) ⇒ Object



83
84
85
86
87
# File 'lib/beanstalk-client/connection.rb', line 83

def release(id, pri, delay)
  @socket.write("release #{id} #{pri} #{delay}\r\n")
  check_resp('RELEASED')
  :ok
end

#reserveObject



72
73
74
75
# File 'lib/beanstalk-client/connection.rb', line 72

def reserve()
  @socket.write("reserve\r\n")
  Job.new(@jptr, *read_job('RESERVED'))
end

#statsObject



110
111
112
113
# File 'lib/beanstalk-client/connection.rb', line 110

def stats()
  @socket.write("stats\r\n")
  read_yaml('OK')
end

#stats_tube(tube) ⇒ Object



120
121
122
123
# File 'lib/beanstalk-client/connection.rb', line 120

def stats_tube(tube)
  @socket.write("stats-tube #{tube}\r\n")
  read_yaml('OK')
end

#use(tube) ⇒ Object



95
96
97
98
# File 'lib/beanstalk-client/connection.rb', line 95

def use(tube)
  @socket.write("use #{tube}\r\n")
  check_resp('USING')[0]
end

#watch(tube) ⇒ Object



100
101
102
103
# File 'lib/beanstalk-client/connection.rb', line 100

def watch(tube)
  @socket.write("watch #{tube}\r\n")
  check_resp('WATCHING')[0]
end

#yput(obj, pri = 65536, delay = 0, ttr = 120) ⇒ Object



54
55
56
# File 'lib/beanstalk-client/connection.rb', line 54

def yput(obj, pri=65536, delay=0, ttr=120)
  put(YAML.dump(obj), pri, delay, ttr)
end