Sha256: ac60d5701aaa7b3ac3fa096dfb7c9f3373e7c5c2e9ba864891f02c5d75a3fa7f
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
# # bundle exec ruby examples/async_sum.rb client # bundle exec ruby examples/async_sum.rb server # require "tennis" require "tennis/backend/redis" logger = Logger.new(STDOUT) logger.level = Logger::DEBUG redis_url = "redis://localhost:6379" Tennis.configure do |config| config.backend = Tennis::Backend::Redis.new(logger: logger, url: redis_url) config.logger = logger end class Job include Tennis::Job def sum(*numbers) sleep 0.4 total = numbers.inject(&:+) puts "Sum #{numbers} => #{total}" end def job_dump nil end def self.job_load(_) new end end if ARGV[0] == "server" require "tennis/launcher" # Start Tennis. launcher = Tennis::Launcher.new(concurrency: 2, job_classes: [Job]) launcher.async.start begin sleep 5 while true rescue Interrupt puts "Stopping the server..." ensure launcher.async.stop end else # Instanciate a job and add the sum to the job to do. numbers = (1..9).to_a 10.times do Job.new.async.sum(*numbers.sample(3)) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tennis-jobs-redis-0.4.0 | examples/async_sum.rb |