forked from johnewart/gearman-ruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged / modified Colin's contribution for scheduled jobs, and an exa…
…mple of using EPOCH. This requires my modified gearmand that supports SUBMIT_JOB_EPOCH
- Loading branch information
Showing
4 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env ruby | ||
require 'rubygems' | ||
require '../lib/gearman' | ||
#Gearman::Util.debug = true | ||
|
||
# Connect to the local server (at the default port 7003) | ||
client = Gearman::Client.new('localhost') | ||
taskset = Gearman::TaskSet.new(client) | ||
|
||
# Get something to echo | ||
puts '[client] Type a string to reverse:' | ||
input = gets.chomp | ||
|
||
puts '[client] File to write to:' | ||
outfile = gets.chomp | ||
|
||
# Set scheduled time to 90 seconds from now | ||
time = Time.now() + 30 | ||
puts "Time as seconds: #{time.to_i}" | ||
data = [input, outfile].join("\0") | ||
task = Gearman::Task.new("reverse_to_file", data) | ||
task.schedule(time) | ||
|
||
# Sending the task to the server | ||
puts "[client] Sending task: #{task.inspect}, to the 'reverse_to_file' worker" | ||
taskset.add_task(task) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'rubygems' | ||
#require 'gearman' | ||
require '../lib/gearman' | ||
|
||
servers = ['localhost:4730'] | ||
w = Gearman::Worker.new(servers) | ||
|
||
# Add a handler for a "sleep" function that takes a single argument, the | ||
# number of seconds to sleep before reporting success. | ||
w.add_ability('reverse_to_file') do |data,job| | ||
puts "Data: #{data.inspect}" | ||
word, file = data.split("\0") | ||
puts "Word: #{word}" | ||
puts "File: #{file}" | ||
# Report success. | ||
true | ||
end | ||
loop { w.work } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters