Class: GoogleMailingListJob
- Inherits:
-
Struct
- Object
- Struct
- GoogleMailingListJob
- Defined in:
- lib/google_mailing_list_job.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#emails_array ⇒ Object
Returns the value of attribute emails_array.
-
#model_id ⇒ Object
Returns the value of attribute model_id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#new_distribution_list ⇒ Object
Returns the value of attribute new_distribution_list.
-
#old_distribution_list ⇒ Object
Returns the value of attribute old_distribution_list.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description
1 2 3 |
# File 'lib/google_mailing_list_job.rb', line 1 def description @description end |
#emails_array ⇒ Object
Returns the value of attribute emails_array
1 2 3 |
# File 'lib/google_mailing_list_job.rb', line 1 def emails_array @emails_array end |
#model_id ⇒ Object
Returns the value of attribute model_id
1 2 3 |
# File 'lib/google_mailing_list_job.rb', line 1 def model_id @model_id end |
#name ⇒ Object
Returns the value of attribute name
1 2 3 |
# File 'lib/google_mailing_list_job.rb', line 1 def name @name end |
#new_distribution_list ⇒ Object
Returns the value of attribute new_distribution_list
1 2 3 |
# File 'lib/google_mailing_list_job.rb', line 1 def new_distribution_list @new_distribution_list end |
#old_distribution_list ⇒ Object
Returns the value of attribute old_distribution_list
1 2 3 |
# File 'lib/google_mailing_list_job.rb', line 1 def old_distribution_list @old_distribution_list end |
#table_name ⇒ Object
Returns the value of attribute table_name
1 2 3 |
# File 'lib/google_mailing_list_job.rb', line 1 def table_name @table_name end |
Instance Method Details
#perform ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/google_mailing_list_job.rb', line 3 def perform Rails.logger.info("#{table_name}.update_google_mailing_list(#{new_distribution_list}, #{old_distribution_list}, #{model_id}) executed") new_group = new_distribution_list.split('@')[0] unless new_distribution_list.blank? old_group = old_distribution_list.split('@')[0] unless old_distribution_list.blank? new_group_exists = false old_group_exists = false google_apps_connection.retrieve_all_groups.each do |list| group_name = list.group_id.split('@')[0] old_group_exists = true if old_group == group_name new_group_exists = true if new_group == group_name end if old_group_exists Rails.logger.info "Deleting #{old_group}" google_apps_connection.delete_group(old_group) new_group_exists = false if old_group == new_group end if !new_group_exists Rails.logger.info "Creating #{new_group}" google_apps_connection.create_group(new_group, [name, description, "Domain"]) end emails_array.each do |member| Rails.logger.info "#{table_name}:adding #{member.email}" google_apps_connection.add_member_to_group(member.email, new_group) end #verify that this method worked. If it didn't an error will be raised and it will be run again through delayed job all_team_members = google_apps_connection.retrieve_all_members(new_group) google_list = all_team_members.map { |l| l.member_id }.sort team_list = emails_array.map { |l| l.email }.sort unless google_list.eql?(team_list) Rails.logger.warn("The people on the google list isn't right") Rails.logger.warn("google list: #{google_list} ") Rails.logger.warn("rails list: #{team_list} ") raise Exception.new("The people on the google list isn't right \n" + "google list: #{google_list} " + "\n rails list: #{team_list} \n") end ActiveRecord::Base.connection.execute "UPDATE #{table_name} SET updating_email=false WHERE id=#{model_id}"; Rails.logger.info "#{model_id} -- finished" end |