Playlist upload delay ?

2 views
Skip to first unread message

Aurélien Malisart

unread,
Mar 4, 2013, 4:56:12 AM3/4/13
to ruby-...@googlegroups.com
Hi,

I'm having strange issues with a playlist creation job.

Here is my code where I create a playlist in the container and "upload" it :

-----

        spotify_playlist = container.add("#{playlist_project.name}", true)

        tracks = [ ... a list of spotify_ids ... ]

        spotify_playlist.insert(0, tracks)
        container.move(container.size - 1, folder.end)
        spotify_playlist.upload(3600)

        playlist_project.update_attribute(:spotify_id, spotify_playlist.to_link.to_uri)
        playlist_project.update_attribute(:status, 'released')

        session.logout!

-----

Just after the "upload", I'd like to save the resulting URI and update my local playlist to a "released" status.  The problem is that in most cases it doesn't reach those two lines.  But the playlist is there on Spotify !

So maybe I'm misusing the lib ?  Am I supposed to do those two operations inside of some kind of callback ?  What do you think ?

Thanks in advance,

Aurels

Aurélien Malisart

unread,
Mar 6, 2013, 4:59:33 PM3/6/13
to ruby-...@googlegroups.com
Do you think I need to use a callback like you're talking it this thread :


Thanks in advance, I'm stuck :-p

Kim Burgestrand

unread,
Mar 7, 2013, 12:21:13 AM3/7/13
to Hallon on behalf of Aurélien Malisart

This is exactly what upload does. It waits until the playlist_update_in_progress callback
fires, with the `done` parameter set to true, and nothing else:


There is no Hallon-specific magic there.

Unfortunately, it’s also the only way I know of to wait for playlist sync progress. Initially
the #upload-call used #pending? on playlists, but that call was bugged and unreliable (and
as far as I know, still is). Callbacks not firing have always been an interesting problem in
Hallon, which is why I try to avoid callbacks as much as possible and just do polling.

My guess (!) would be that the callback is sometimes missed, for some weird reason. But
I’ve also had cases where the upload takes 30 seconds, even though the changes are really
reflected on the Spotify client after just a few seconds, so that’s just as likely.

You could always write your own handler for playlist_update_in_progress, and see if you
could figure out what is going wrong.

playlist.on(:playlist_update_in_progress) do |done|
  # something that uses done and shows you information to help debugging
end

libspotify was not really written with this use-case in mind (add changes to playlist, wait until
they have been acknowledged by backend), so #upload is a bit of a hack to try and get it to
work at all.

— Kim

Aurélien Malisart

unread,
Mar 7, 2013, 3:20:15 AM3/7/13
to ruby-...@googlegroups.com
Kim,

Thanks for your explanations.  It's very clear.  If it is what upload does, it is indeed problematic :-p
I'll try to inspect that as you suggest.

Maybe another solution for me would be to do an upload with a reasonable timeout (like 60s or so) and check if everything is OK just after.  I mean counting the number of tracks or stuffs like that.  If it's not complete, il delete the playlist and do it again.  Kind of a hack...

Aurels

Kim Burgestrand

unread,
Mar 7, 2013, 5:26:49 AM3/7/13
to Hallon on behalf of Aurélien Malisart
Keep in mind that libspotify will cache just about everything, so even
if you restart your application you may still have the changes if you
read the playlist from code, even though the Spotify client have not
updated itself. The only way to know if the changes have been
persisted to a 100% is to quit your application, clear the cache, load
the playlist (which will now, since there is no cache, load it
directly from their servers) and look again at the current state!

--
Kim Burgestrand


On Thu, Mar 7, 2013 at 9:20 AM, Aurélien Malisart via Hallon
<ruby-hallon+noreply-APn2wQffbsp_...@googlegroups.com>
wrote:

Aurélien Malisart

unread,
Mar 7, 2013, 5:42:43 AM3/7/13
to ruby-...@googlegroups.com
OK !  As I'm performing actions in a Sidekiq worker, starting a new session in the new job with another cache directory would be equivalent to quitting the application ?

Kim Burgestrand

unread,
Mar 7, 2013, 5:59:53 AM3/7/13
to Hallon on behalf of Aurélien Malisart
On Thu, Mar 7, 2013 at 11:42 AM, Aurélien Malisart via Hallon
<ruby-hallon+noreply-APn2wQffbsp_...@googlegroups.com>
wrote:
> OK ! As I'm performing actions in a Sidekiq worker, starting a new session
> in the new job with another cache directory would be equivalent to quitting
> the application ?

I’m afraid not.

Sidekiq is threaded, which means that every new job runs in the same
process as all other jobs.

libspotify can only ever create one session per process
(http://developer.spotify.com/technologies/libspotify/docs/12.1.45/#restr_sec),
and attempting to create more than one session in a single process is
very likely to just hang. Since you can’t change your session, you are
stuck with the session you create when you start sidekiq.

However, you could also disable the cache
(http://developer.spotify.com/technologies/libspotify/docs/12.1.45/structsp__session__config.html#ad1cb5e3670451d8cee3d8c9766b523fc)
— you do this by setting the cache_location to an empty string
(http://rdoc.info/github/Burgestrand/Hallon/master/Hallon/Session#initialize-instance_method).
I don’t know if you can disable settings cache
(http://developer.spotify.com/technologies/libspotify/docs/12.1.45/structsp__session__config.html#a342532432040d476aaaf73f10893d23b),
which is probably the cache you are most interested in clearing.
However, you could possibly log out, remove the cache directory
manually from within your sidekiq job, and then log in again. I am
unsure how libspotify behaves if you remove the settings directory
while you have a session (even if it is logged out), but it could be
interesting to try it out and see how it behaves.

— Kim Burgestrand

Aurélien Malisart

unread,
Mar 7, 2013, 8:55:58 AM3/7/13
to Hallon on behalf of Kim Burgestrand
Ok, I'll try probably tomorrow if I have time.  I'll of course update this thread if I have a solution !



--
You received this message because you are subscribed to the Hallon ruby gem mailing list.

- To view this group online, visit https://groups.google.com/d/forum/ruby-hallon
- To post to this group, send email to ruby-...@googlegroups.com
- To unsubscribe from this group, send email to ruby-hallon...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Hallon" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-hallon...@googlegroups.com.



--
Aurélien Malisart

aurelien...@gmail.com
http://aurelien.malisart.be

Aurélien Malisart

unread,
Mar 15, 2013, 5:30:05 AM3/15/13
to ruby-...@googlegroups.com
Hi,

I get back to you. Unfortunately, I couldn't make it work better.  Il try this project https://github.com/liesen/spotify-api-server because we are totally stuck !

Thanks for your help,

Aurels
Reply all
Reply to author
Forward
0 new messages