Class: Faktory::Client
- Inherits:
-
Object
- Object
- Faktory::Client
- Defined in:
- lib/faktory/client.rb
Constant Summary collapse
- @@random_process_wid =
SecureRandom.hex(8)
Instance Attribute Summary collapse
-
#middleware ⇒ Object
Returns the value of attribute middleware.
Instance Method Summary collapse
- #ack(jid) ⇒ Object
-
#beat ⇒ Object
Sends a heartbeat to the server, in order to prove this worker process is still alive.
- #close ⇒ Object
- #fail(jid, ex) ⇒ Object
- #fetch(*queues) ⇒ Object
-
#flush ⇒ Object
Warning: this clears all job data in Faktory.
- #info ⇒ Object
-
#initialize(url: 'tcp://localhost:7419', debug: false) ⇒ Client
constructor
Best practice is to rely on the localhost default for development and configure the environment variables for non-development environments.
- #push(job) ⇒ Object
Constructor Details
#initialize(url: 'tcp://localhost:7419', debug: false) ⇒ Client
Best practice is to rely on the localhost default for development and configure the environment variables for non-development environments.
FAKTORY_PROVIDER=MY_FAKTORY_URL MY_FAKTORY_URL=tcp://:[email protected]:7419
Note above, the URL can contain the password for secure installations.
22 23 24 25 26 |
# File 'lib/faktory/client.rb', line 22 def initialize(url: 'tcp://localhost:7419', debug: false) @debug = debug @location = uri_from_env || URI(url) open end |
Instance Attribute Details
#middleware ⇒ Object
Returns the value of attribute middleware.
13 14 15 |
# File 'lib/faktory/client.rb', line 13 def middleware @middleware end |
Instance Method Details
#ack(jid) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/faktory/client.rb', line 60 def ack(jid) transaction do command("ACK", %Q[{"jid":"#{jid}"}]) ok! end end |
#beat ⇒ Object
Sends a heartbeat to the server, in order to prove this worker process is still alive.
Return a string signal to process, legal values are “quiet” or “terminate”. The quiet signal is informative: the server won’t allow this process to FETCH any more jobs anyways.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/faktory/client.rb', line 83 def beat transaction do command("BEAT", %Q[{"wid":"#{@@random_process_wid}"}]) str = result if str == "OK" str else hash = JSON.parse(str) hash["signal"] end end end |
#close ⇒ Object
28 29 30 31 32 33 |
# File 'lib/faktory/client.rb', line 28 def close return unless @sock command "END" @sock.close @sock = nil end |
#fail(jid, ex) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/faktory/client.rb', line 67 def fail(jid, ex) transaction do command("FAIL", JSON.dump({ message: ex.[0...1000], errtype: ex.class.name, jid: jid, backtrace: ex.backtrace})) ok! end end |
#fetch(*queues) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/faktory/client.rb', line 51 def fetch(*queues) job = nil transaction do command("FETCH", *queues) job = result end JSON.parse(job) if job end |
#flush ⇒ Object
Warning: this clears all job data in Faktory
36 37 38 39 40 41 |
# File 'lib/faktory/client.rb', line 36 def flush transaction do command "FLUSH" ok! end end |
#info ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/faktory/client.rb', line 96 def info transaction do command("INFO") str = result JSON.parse(str) if str end end |
#push(job) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/faktory/client.rb', line 43 def push(job) transaction do command "PUSH", JSON.generate(job) ok! job["jid"] end end |