Question

i have a applications running on Rails 3.2.13 and ruby 1.9.3 MRI.The application allows users to upload multiple videos/songs/images and uses S3 for data storage.i am looking for a concept where for an upload of 100 videos(any n uploads),my registered user should get only one mail saying the count of uploads for videos/images/songs:-for example

Hi mike,Please check for latest updates:- - n+ videos uploaded. - more than 50 songs uploaded .....etc

so ..i dont want to spam my users inbox with every notification mail.Right now i can send email for every video/song/image uploaded using observers but what if there are thousands of uploads,so how i can get this thing working.

I thought about it that i can write a logic to count an average of recent(daily/weekly/montly) uploads and then send that count in just one email instead of every update.is it the correct way or is there any better way to notify user with some other logic...(i was wondering how Youtube notifies its users if it want to for every uploads..???)

Was it helpful?

Solution

You can think about using filters / callbacks with if clause in model Upload, for example:

after_commit :send_notification, on: :create, 
           if: ->{ (Upload.count % 100) == 0) && self.status.was_not_sent?  }
# self is model instance variable here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top