public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
class Song < ActiveRecord::Base
attr_accessible :artist, :artwork, :category, :credits, :title, :track, :year
belongs_to :user
validates_presence_of :user_id
validates_presence_of :title
mount_uploader :track, TrackUploader
after_save :enqueue_track
 
def track_name
File.basename(track.path || track.filename) if track
end
 
def enqueue_track
TrackWorker.perform_async(id, key) if key.present?
end
 
class TrackWorker
include Sidekiq::Worker
 
def perform(id, key)
song = Song.find(id)
song.key = key
song.remote_track_url = song.track.direct_fog_url(with_path: true)
song.save!
song.update_column(:track_processed, true)
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.