Class: AllQ::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/allq/client.rb

Overview

Represents the client singleton

Constant Summary collapse

URL =
ENV['ALLQ_CLIENT_URL'] || '127.0.0.1:7766'

Instance Method Summary collapse

Constructor Details

#initialize(url = nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
# File 'lib/allq/client.rb', line 8

def initialize(url = nil)
  @url = url.nil? ? URL : url
  @connection = nil
  reload!
end

Instance Method Details

#add_server(server_url) ⇒ Object



28
29
30
# File 'lib/allq/client.rb', line 28

def add_server(server_url)
  @add_server_action.snd(server_url: server_url)
end

#bury(job) ⇒ Object



52
53
54
55
# File 'lib/allq/client.rb', line 52

def bury(job)
  raise "Can't 'bury' a Job that is nil. Please check for Nil job before burying." unless job
  @bury_action.snd(job_id: job.id)
end

#clear(cache_type = "cache_type", value = "all") ⇒ Object



40
41
42
# File 'lib/allq/client.rb', line 40

def clear(cache_type = "cache_type", value = "all")
  @clear_action.snd(cache_type: :all)
end

#closeObject



102
103
104
# File 'lib/allq/client.rb', line 102

def close
   @connection.close
end

#delete(job) ⇒ Object



73
74
75
76
# File 'lib/allq/client.rb', line 73

def delete(job)
  raise "Can't delete a Nil job" unless job
  @delete_action.snd(job_id: job.id)
end

#done(job) ⇒ Object



78
79
80
81
# File 'lib/allq/client.rb', line 78

def done(job)
  raise "Can't set 'done' on a Job that is nil. Please check for Nil job before setting done." unless job
  @done_action.snd(job_id: job.id)
end

#drain(server_id) ⇒ Object



32
33
34
# File 'lib/allq/client.rb', line 32

def drain(server_id)
  @drain_action.snd(server_id: server_id)
end

#get(tube_name) ⇒ Object



57
58
59
# File 'lib/allq/client.rb', line 57

def get(tube_name)
  @get_action.snd(tube_name)
end

#kick(job) ⇒ Object



36
37
38
# File 'lib/allq/client.rb', line 36

def kick(job)
  @kick_action.snd(job: job)
end

#parent_job(tube, body, ttl: 3600, delay: 0, parent_id: nil, priority: 5, limit: nil, noop: false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/allq/client.rb', line 14

def parent_job(tube, body, ttl: 3600, delay: 0, parent_id: nil, priority: 5, limit: nil, noop: false)
  data = {
    'body' => body,
    'tube' => tube,
    'delay' => delay,
    'ttl' => ttl,
    'priority' => priority,
    'parent_id' => parent_id,
    'limit' => limit,
    'noop' => noop
  }
  @parent_job_action.snd(data)
end

#peek(tube_name) ⇒ Object



44
45
46
# File 'lib/allq/client.rb', line 44

def peek(tube_name)
  @peek_action.snd(tube: tube_name, buried: false)
end

#peek_buried(tube_name) ⇒ Object



48
49
50
# File 'lib/allq/client.rb', line 48

def peek_buried(tube_name)
  @peek_action.snd(tube: tube_name, buried: true)
end

#put(tube, body, ttl: 3600, delay: 0, parent_id: nil, priority: 5) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/allq/client.rb', line 61

def put(tube, body, ttl: 3600, delay: 0, parent_id: nil, priority: 5)
  data = {
    'body' => body,
    'tube' => tube,
    'delay' => delay,
    'ttl' => ttl,
    'priority' => priority,
    'parent_id' => parent_id
  }
  @put_action.snd(data)
end

#release(job, delay) ⇒ Object



92
93
94
95
96
# File 'lib/allq/client.rb', line 92

def release(job, delay)
  raise "Can't 'release' a Job that is nil." unless job
  raise "Delay must be a int" unless delay.is_a?(Integer)
  @release_action.snd(job_id: job.id, delay: delay)
end

#reload!Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/allq/client.rb', line 106

def reload!
  @connection.close if @connection
  puts "AllQ Connection Started --#{@url}"
  @connection = AllQ::Connection.new(@url)
  @get_action = AllQ::Get.new(@connection, self)
  @drain_action = AllQ::Drain.new(@connection, self)
  @add_server_action = AllQ::AddServer.new(@connection, self)
  @put_action = AllQ::Put.new(@connection, self)
  @done_action = AllQ::Done.new(@connection, self)
  @stats_action = AllQ::Stats.new(@connection, self)
  @release_action = AllQ::Release.new(@connection, self)
  @touch_action = AllQ::Touch.new(@connection, self)
  @kick_action = AllQ::Kick.new(@connection, self)
  @bury_action = AllQ::Bury.new(@connection, self)
  @clear_action = AllQ::Clear.new(@connection, self)
  @peek_action = AllQ::Peek.new(@connection, self)
  @delete_action = AllQ::Delete.new(@connection, self)
  @parent_job_action = AllQ::ParentJob.new(@connection, self)
  @throttle_action = AllQ::Throttle.new(@connection, self)
end

#stats(breakout = false) ⇒ Object



88
89
90
# File 'lib/allq/client.rb', line 88

def stats(breakout = false)
  v = @stats_action.snd(breakout: breakout)
end

#throttle(tube, tps) ⇒ Object



98
99
100
# File 'lib/allq/client.rb', line 98

def throttle(tube, tps)
  @throttle_action.snd(name: tube, tps: tps)
end

#touch(job) ⇒ Object



83
84
85
86
# File 'lib/allq/client.rb', line 83

def touch(job)
  raise "Can't 'touch' a Job that is nil. Please check for Nil job before 'touch'." unless job
  @touch_action.snd(job_id: job.id)
end