Class: Gearman::Worker::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/gearman/worker/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, handle) ⇒ Job

Returns a new instance of Job.



12
13
14
15
# File 'lib/gearman/worker/job.rb', line 12

def initialize(connection, handle)
  @connection = connection
  @handle = handle
end

Instance Attribute Details

#handleObject (readonly)

Create a new Job.

Parameters:

  • sock

    Socket connected to job server

  • handle

    job server-supplied job handle



10
11
12
# File 'lib/gearman/worker/job.rb', line 10

def handle
  @handle
end

Instance Method Details

#report_status(numerator, denominator) ⇒ Object

Report our status to the job server.



19
20
21
22
23
# File 'lib/gearman/worker/job.rb', line 19

def report_status(numerator, denominator)
  req = Packet.pack_request(:work_status, "#{@handle}\0#{numerator}\0#{denominator}")
  @connection.send_update(req)
  self
end

#report_warning(warning) ⇒ Object

Send a warning explicitly



35
36
37
38
39
# File 'lib/gearman/worker/job.rb', line 35

def report_warning(warning)
  req = Packet.pack_request(:work_warning, "#{@handle}\0#{warning}")
  @connection.send_update(req)
  self
end

#send_data(data) ⇒ Object

Send data before job completes



27
28
29
30
31
# File 'lib/gearman/worker/job.rb', line 27

def send_data(data)
  req = Packet.pack_request(:work_data, "#{@handle}\0#{data}")
  @connection.send_update(req)
  self
end