Skip to content

Commit

Permalink
minor cleanup; more debugging output
Browse files Browse the repository at this point in the history
git-svn-id: http://code.sixapart.com/svn/gearman/trunk/api/ruby@261 011c6a6d-750f-0410-a5f6-93fdcd050bc4
  • Loading branch information
derat committed May 6, 2007
1 parent 269bf2b commit b57cf18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/gearman/taskset.rb
Expand Up @@ -32,6 +32,7 @@ def add_task(*args)
# creation fails (see how the server reports this to us), or ... # creation fails (see how the server reports this to us), or ...
hostport = @client.get_job_server hostport = @client.get_job_server
sock = (@sockets[hostport] or @client.get_socket(hostport)) sock = (@sockets[hostport] or @client.get_socket(hostport))
Util.log "Using socket #{sock.inspect}"
Util.send_request(sock, req) Util.send_request(sock, req)
read_packet(sock) while @tasks_waiting_for_handle.size > 0 read_packet(sock) while @tasks_waiting_for_handle.size > 0


Expand Down Expand Up @@ -65,7 +66,7 @@ def handle_job_created(hostport, data)
def handle_work_complete(hostport, data) def handle_work_complete(hostport, data)
handle, data = data.split("\0") handle, data = data.split("\0")
Util.log "Got work_complete with handle #{handle} and " + Util.log "Got work_complete with handle #{handle} and " +
"#{data} byte(s) of data from #{hostport}" "#{data ? data.size : '0'} byte(s) of data from #{hostport}"
js_handle = Util.handle_to_str(hostport, handle) js_handle = Util.handle_to_str(hostport, handle)
tasks = @tasks_in_progress.delete(js_handle) tasks = @tasks_in_progress.delete(js_handle)
if not tasks if not tasks
Expand Down Expand Up @@ -177,7 +178,12 @@ def wait(timeout=1)
end end
@sockets.values.each {|s| @client.return_socket(s) } @sockets.values.each {|s| @client.return_socket(s) }
@sockets = {} @sockets = {}
@finished_tasks.each {|t| return false if not t.successful } @finished_tasks.each do |t|
if not t.successful
Util.log "Taskset failed"
return false
end
end
true true
end end
end end
Expand Down
6 changes: 4 additions & 2 deletions lib/gearman/worker.rb
Expand Up @@ -152,7 +152,9 @@ def announce_ability(sock, func, timeout=nil)
# #
# The passed-in block of code will be executed for jobs of this function # The passed-in block of code will be executed for jobs of this function
# type. It'll receive two arguments, the data supplied by the client and # type. It'll receive two arguments, the data supplied by the client and
# a Job object. # a Job object. If it returns nil or false, the server will be informed
# that the job has failed; otherwise the return value of the block will
# be passed back to the client in String form.
# #
# @param func function name (without prefix) # @param func function name (without prefix)
# @param timeout the server will give up on us if we don't finish # @param timeout the server will give up on us if we don't finish
Expand Down Expand Up @@ -196,10 +198,10 @@ def handle_job_assign(data, sock)
end end


ret = ability.run(data, Job.new(sock, handle)) ret = ability.run(data, Job.new(sock, handle))
ret = ret.to_s


cmd = nil cmd = nil
if ret if ret
ret = ret.to_s
Util.log "Sending work_complete for #{handle} with #{ret.size} byte(s)" Util.log "Sending work_complete for #{handle} with #{ret.size} byte(s)"
cmd = Util.pack_request(:work_complete, "#{handle}\0#{ret}") cmd = Util.pack_request(:work_complete, "#{handle}\0#{ret}")
else else
Expand Down

0 comments on commit b57cf18

Please sign in to comment.