-
-
Save michelson/013c7c840de541255ba7 to your computer and use it in GitHub Desktop.
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
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 |
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
runner = PreyReportCli::Runner.new | |
runner.threads_num = 5 | |
runner.run_times = 5 | |
runner.caller = PreyReportCli::Report.new | |
runner.run |
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, your
Report
class may not be thread safe. I don't know what you are storing inConfig.connection
but that needs to be thread safe for this to work. If it isn't thread safe, your code isn't thread safe. I'm going to assume that it is thread safe.