Search code examples
ruby-on-railspostgresqlasynchronousredissidekiq

How to use sidekiq with rails app to generate daily report?


I have built a rails app for storing events. I want to generate a report to find the number of events happened in a day. I want to do it asynchronously. I am new to sidekiq and Redis. Can anyone suggest a good resource to study?


Solution

  • My suggestion for this would be to do this in a rake task that would be run on the server once a day.

    You can find good resources on how to create rake tasks online and then use this simple gem to make sure the rake task runs once a day on the server.

    https://github.com/javan/whenever

    I am assuming you have a Profile model. You could use the timestamps in this model created_at to get all the profiles created on a given day. You could then create a CSV or whatever you like with that data and email it to whoever needs the report (how you handle the data is up to you)

    You can do all the above in Sidekiq if you wish, I would recommend reading through the gem docs and this getting started guide from the official wiki https://github.com/mperham/sidekiq/wiki/Getting-Started

    It's fairly straightforward and once you get your first process working it will start to make more sense.

    I would also highly reccomend this video before you start working with sidekiq and redis, to give you an overall background of how sidekiq works and in what use cases it may be helpful to you.

    https://www.youtube.com/watch?v=GBEDvF1_8B8