|
| 1 | +namespace :light do |
| 2 | + desc 'Checking and updating the User status (Subscribed and Unsubscribed)' |
| 3 | + task :update_user_status => :environment do |
| 4 | + |
| 5 | + print "\n\n Update the flag is_subscribed for status: " |
| 6 | + ['Bounced', 'Spam', 'Opt in mail sent', 'Invalid'].each do |status| |
| 7 | + print "\n #{status} : " |
| 8 | + print Light::User.where(sidekiq_status: status) |
| 9 | + .update_all(is_subscribed: false)[:n] |
| 10 | + # Keeping is_blocked as is, because we have code sit in there depending on it. |
| 11 | + end |
| 12 | + |
| 13 | + print "\n\n Fix the data for Blocked Users : " |
| 14 | + print "\n Update flags for Block user : " |
| 15 | + print Light::User.where(sidekiq_status: 'Block') |
| 16 | + .update_all(is_subscribed: false, is_blocked: true)[:n] |
| 17 | + |
| 18 | + print "\n Update status for new_users who are blocked : " |
| 19 | + print Light::User.where(is_subscribed: false, sidekiq_status: 'new user', is_blocked: true) |
| 20 | + .update_all(sidekiq_status: 'Block')[:n] |
| 21 | + |
| 22 | + |
| 23 | + print "\n\n Update one who dones't have sidekiq_status : " |
| 24 | + print "\n Unsubscribed : " |
| 25 | + print Light::User.where(is_subscribed: false, sidekiq_status: nil, :is_blocked.in => [false, nil]) |
| 26 | + .update_all(sidekiq_status: 'Unsubscribed', unsubscribed_at: DateTime.now)[:n] |
| 27 | + |
| 28 | + print "\n Block (is_subscribed: false) : " |
| 29 | + print Light::User.where(is_subscribed: false, is_blocked: true, sidekiq_status: nil) |
| 30 | + .update_all(sidekiq_status: 'Block')[:n] |
| 31 | + |
| 32 | + print "\n Block (is_subscribed: true) : " |
| 33 | + print Light::User.where(is_subscribed: true, is_blocked: true, sidekiq_status: nil) |
| 34 | + .update_all(is_subscribed: false, sidekiq_status: 'Block')[:n] |
| 35 | + |
| 36 | + print "\n Subscribed : " |
| 37 | + print Light::User.where(is_subscribed: true, sidekiq_status: nil) |
| 38 | + .update_all(sidekiq_status: 'Subscribed')[:n] |
| 39 | + |
| 40 | + print "\n\n Updated flag value for is_blocked: nil to flase : " |
| 41 | + print Light::User.where(is_blocked: nil) |
| 42 | + .update_all(is_blocked: false)[:n] |
| 43 | + |
| 44 | + print "\n\n Updated Status for Web Subscription Request : " |
| 45 | + print Light::User.where(sidekiq_status: 'web subscription request') |
| 46 | + .update_all(source: 'web subscription request', |
| 47 | + is_subscribed: false, |
| 48 | + sidekiq_status: 'Unsubscribed', |
| 49 | + unsubscribed_at: DateTime.now)[:n] |
| 50 | + |
| 51 | + def check_status(status) |
| 52 | + Light::User.where(sidekiq_status: status).count |
| 53 | + end |
| 54 | + |
| 55 | + # Status wise count of User |
| 56 | + print "\n\n Total no of User Status : " + |
| 57 | + "\n Subscribed : #{check_status('Subscribed')}" + |
| 58 | + "\n Unsubscribed : #{check_status('Unsubscribed')}" + |
| 59 | + "\n New User : #{check_status('new user')}" + |
| 60 | + "\n Invalid : #{check_status('Invalid')}" + |
| 61 | + "\n Spam : #{check_status('Spam')}" + |
| 62 | + "\n Blocked : #{check_status('Block')}" + |
| 63 | + "\n Bounced : #{check_status('Bounced')}" + |
| 64 | + "\n Opt in User: #{check_status('Opt in mail sent')} \n\n" |
| 65 | + end |
| 66 | +end |
| 67 | + |
0 commit comments