more debugging
parent
2b1ddcf8c8
commit
881b65f6a5
|
@ -13,6 +13,8 @@ class LoadUserActivitiesJob < ApplicationJob
|
||||||
client = SpotifyClient.new(login)
|
client = SpotifyClient.new(login)
|
||||||
last_spotify_activity_at = latest_activity_iso(login.platform)
|
last_spotify_activity_at = latest_activity_iso(login.platform)
|
||||||
new_activities = client.load_since(last_spotify_activity_at)
|
new_activities = client.load_since(last_spotify_activity_at)
|
||||||
|
# log some info about the response with status and parts of the body
|
||||||
|
Rails.logger.info("Response: #{new_activities}")
|
||||||
create_action = CreateSpotifyActivity.new(user, new_activities)
|
create_action = CreateSpotifyActivity.new(user, new_activities)
|
||||||
create_action.perform
|
create_action.perform
|
||||||
logger.info("Loading for #{user.id} finished with #{new_activities.size} new activities")
|
logger.info("Loading for #{user.id} finished with #{new_activities.size} new activities")
|
||||||
|
|
|
@ -8,21 +8,27 @@ class CreateSpotifyActivity
|
||||||
|
|
||||||
# rubocop:disable Metrics/AbcSize
|
# rubocop:disable Metrics/AbcSize
|
||||||
def perform
|
def perform
|
||||||
# log some info about the response with status and parts of the body
|
begin
|
||||||
Rails.logger.info("Response status: #{response["status"]}")
|
# log some info about the response with status and parts of the body
|
||||||
Rails.logger.info("Response body: #{response["body"]}")
|
Rails.logger.info("Response status: #{response["status"]}")
|
||||||
counts = response["items"].size
|
Rails.logger.info("Response body: #{response["body"]}")
|
||||||
Rails.logger.info("Saving #{counts} activities")
|
counts = response["items"].size
|
||||||
response["items"].reverse.each do |play|
|
Rails.logger.info("Saving #{counts} activities")
|
||||||
activity = new_activity
|
response["items"].reverse.each do |play|
|
||||||
activity.item_ref = play["track"]["id"]
|
activity = new_activity
|
||||||
artist_names = play["track"]["artists"].map { |a| a["name"] }
|
activity.item_ref = play["track"]["id"]
|
||||||
artists = artist_names.join(", ")
|
artist_names = play["track"]["artists"].map { |a| a["name"] }
|
||||||
title = "#{artists} - #{play['track']['name']}"
|
artists = artist_names.join(", ")
|
||||||
activity.item_title = title
|
title = "#{artists} - #{play['track']['name']}"
|
||||||
activity.item_length = play["track"]["duration"].to_s
|
activity.item_title = title
|
||||||
activity.started_at = DateTime.parse(play["played_at"])
|
activity.item_length = play["track"]["duration"].to_s
|
||||||
activity.save!
|
activity.started_at = DateTime.parse(play["played_at"])
|
||||||
|
activity.save!
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.error("[CreateSpotifyActivity] Error: #{e.message}\n#{e.backtrace.join("\n")}")
|
||||||
|
Rails.logger.error("[CreateSpotifyActivity] Response object: #{response.inspect}")
|
||||||
|
raise e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/AbcSize
|
# rubocop:enable Metrics/AbcSize
|
||||||
|
|
Loading…
Reference in New Issue