~pixelinc/gmod-checker.cr

ce097d925d3a407b901fa56208eaea9b30783072 — PixeL 5 months ago 409ad39
Remove module name from log strings
2 files changed, 6 insertions(+), 6 deletions(-)

M src/job_controller.cr
M src/steam.cr
M src/job_controller.cr => src/job_controller.cr +3 -3
@@ 14,7 14,7 @@ module JobController

  def create(size : Int32, &block : Job ->) : Nonce
    nonce = generate_nonce
    @@logger.try &.info { "[JobController : CREATE] #{nonce} (size: #{size})" }
    @@logger.try &.info { "[CREATE] #{nonce} (size: #{size})" }
    job = Job.new(size)
    @@jobs[nonce] = job
    spawn do


@@ 30,7 30,7 @@ module JobController
  def cleanup(nonce)
    sleep TIMEOUT
    @@jobs.delete(nonce)
    @@logger.try &.info { "[JobController : DELETE] #{nonce}" }
    @@logger.try &.info { "[DELETE] #{nonce}" }
  end

  # TODO: Blocking access to jobs with mutex?


@@ 39,7 39,7 @@ module JobController

  def dispatch(nonce : Nonce, &block : Job::PlayerResult | Job::BatchPlayers | Job::Error ->)
    job = @@jobs[nonce]
    @@logger.try &.info { "[JobController : DISPATCH] #{nonce} (size: #{job.size})" }
    @@logger.try &.info { "[DISPATCH] #{nonce} (size: #{job.size})" }
    job.each_result { |r| block.call(r) }
    # TODO: Move into create in its own fiber
    cleanup(nonce)

M src/steam.cr => src/steam.cr +3 -3
@@ 20,10 20,10 @@ class Steam::Client
  end

  def request(endpoint : String)
    @logger.try &.info { "[Steam : HTTP OUT] #{endpoint}" }
    @logger.try &.info { "[HTTP OUT] #{endpoint}" }
    # TODO: Implement some sort of ratelimiter here or something.
    response = HTTP::Client.get "#{BASE_URL}#{endpoint}&key=#{@api_key}"
    @logger.try &.info { "[Steam : HTTP IN] #{response.status_code} #{response.status_message}" }
    @logger.try &.info { "[HTTP IN] #{response.status_code} #{response.status_message}" }
    raise "Steam API request failed: #{response.inspect}" unless response.success?
    @logger.try { |l| l.debug { "[HTTP IN] #{response.body}" } if l.level == Log::Severity::Debug }
    response.body


@@ 42,7 42,7 @@ class Steam::Client

  def get_players(player_ids : Array(ID)) : Array(Player)
    query = HTTP::Params.build do |form|
      form.add "steamids", player_ids.map { |id| id.to_u64 }.join(',')
      form.add "steamids", player_ids.map(&.to_u64).join(',')
    end
    response = request("/ISteamUser/GetPlayerSummaries/v0002?#{query}")
    parse(Array(Player), from: response, in: "players")