Added delayed jobs
This commit is contained in:
@@ -5,14 +5,23 @@ class ArtistController < ApplicationController
|
||||
data = {}
|
||||
name = params[:name].gsub('%20', ' ').gsub('+', ' ')
|
||||
artist = Artist.find_by_name(name)
|
||||
if artist and artist.status == 0
|
||||
render :json => {status: 'loading'}
|
||||
return
|
||||
end
|
||||
unless artist
|
||||
results = ArtistController.musicBrainzExactSearch(name)
|
||||
if results.empty?
|
||||
render :json => {status: 'not founds'}
|
||||
render :json => {status: 'not found'}
|
||||
return
|
||||
elsif results[0][:name] == name
|
||||
ImportController.importArtist(name)
|
||||
render :json => {status: 'loaded'}
|
||||
# Saving artist and queueing job
|
||||
artist = Artist.new
|
||||
artist.name = name
|
||||
artist.status = 0
|
||||
artist.save
|
||||
Delayed::Job.enqueue LoadArtistJob.new(name)
|
||||
render :json => {status: 'loading_started'}
|
||||
return
|
||||
elsif results[0][:name].downcase == name.downcase or results[0][:name].downcase == 'the '+ name.downcase
|
||||
render :json => {status: 'corrected', page: results[0][:name]}
|
||||
|
||||
@@ -19,8 +19,8 @@ class ImportController < ApplicationController
|
||||
end
|
||||
|
||||
# Save artist
|
||||
artist = Artist.new
|
||||
artist.name = artist_mb_data[:name]
|
||||
artist = Artist.find_by_name(name)
|
||||
#artist.name = artist_mb_data[:name]
|
||||
artist.desc = artist_desc
|
||||
artist.pic_url = artist_pic
|
||||
artist.artist_type = artist_mb_data[:type]
|
||||
@@ -133,6 +133,9 @@ class ImportController < ApplicationController
|
||||
|
||||
end # mb_albums.each do |mb_album|
|
||||
|
||||
artist.status = 1
|
||||
artist.save
|
||||
|
||||
end # def self.importArtist name
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user