Skip to content

Instantly share code, notes, and snippets.

@michelson

michelson/cli.rb Secret

Last active March 18, 2016 03:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michelson/013c7c840de541255ba7 to your computer and use it in GitHub Desktop.
Save michelson/013c7c840de541255ba7 to your computer and use it in GitHub Desktop.
module ReportCli
class Runner
include Concurrent::Async
attr_accessor :threads_num, :run_times, :caller
def initialize
@conn = Config.connection
end
# TODO use TPoolexecutor to limit queue ,
# http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadPoolExecutor.html
def run
pool = Concurrent::FixedThreadPool.new(self.threads_num)
@instance = self
pool.post{
@instance.run_times.times{
@instance.caller.exec
}
}
pool.wait_for_termination
end
def call
puts "sending reports"
self.caller.send_report
end
end
end
runner = PreyReportCli::Runner.new
runner.threads_num = 5
runner.run_times = 5
runner.caller = PreyReportCli::Report.new
runner.run
module ReportCli
class Report
def initialize
@conn = Config.connection
end
def end_point
"/api/v2/devices/#{Config.device_key}/reports.json"
end
def exec
payload = {}
payload[:screenshot] = Faraday::UploadIO.new("./#{shuffled_images}.jpg", 'image/jpeg')
@conn.post end_point, payload
end
def shuffled_images
["mat","pic","van"].shuffle.first
end
end
end
@jdantonio
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment