# apollo-new-music-friday-tracks-job  

A job to update NMF (new music friday) playlists tracklists and ranks.  

This job do:  
1. Get NMF playlists from SpotifyNewMusicFridayPlaylist.  
2. Get these playlists tracks from Delphi via DSP API.
3. Check what should be updated using added_at and previous/current NMF tracklist.  
4. Update tracklists in SpotifyNewMusicFridayPlaylistTrackHistory.  
5. Update last_date (as current friday) and last_added (as max playlist's track added_at timestamp) in SpotifyNewMusicFridayPlaylist.  
6. Check if ranks should be updated.  
7. Get ranks as order by last 28 days streams sums from SpotifyAnalyticsAccountStreamInfo, for missing ranks are calculated alphabetically from some int.  
8. Set ranks to SpotifyNewMusicFridayPlaylist.  
9. Set last rank update ts and last job run ts to ApolloKeyValueStorage.  

Main environment variables:  
REDIS_HOST - IP/URL of redis instance to get lock  
MYSQL_DATABASE - MySQL database name  
MYSQL_USER - MySQL user name  
MYSQL_PASSWORD - MySQL password  
MYSQL_HOST - MySQL host URI  
DSPAPI_HOSTNAME - DSP API host name
DSPAPI_APPKEY - DSP API app key
ENVIRONMENT - ENV name  

Run unit tests:  
docker-compose -f ./docker-compose.test.yml run job pytest -vv  
