Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'json'
- require 'awesome_print'
- require 'open-uri'
- require 'mysql2'
- require 'net/ssh/gateway'
- client = Mysql2::Client.new(
- host: "somedomain.com",
- username: 'username',
- password: 'password',
- database: 'db_name',
- port: '3306'
- )
- #Returns source_name. external_tracking_id for all active sources of chosen PP
- def get_active_sources(client, pp_id)
- response = client.query("SELECT s.code, ptm.external_tracking_id
- FROM runashop_pp.portal_tracking_map ptm
- INNER JOIN runashop_pp.priceportal_sources pps ON ptm.source_id = pps.source_id
- INNER JOIN runashop_pp.sources s on ptm.source_id = s.id
- WHERE ptm.portal_id = #{pp_id}
- AND pps.proportion != 0
- AND pps.portal_id = #{pp_id};")
- hash = Hash.new
- response.each{|row|
- hash.store(row['code'],row['external_tracking_id'])
- }
- hash
- end
- def insert(client, url, error)
- client.query("INSERT INTO runashop_qa.external_trackings_errors (url, error)
- VALUES ('#{url}', '#{error}');")
- end
- #returns id, channel_value for active test projects
- active_test_projects = client.query("SELECT p.id, d.channel_value
- FROM runashop_pp.portals p
- INNER JOIN runashop_pp.domains d on p.id = d.portal_id
- WHERE p.status = 'active'
- AND p.name like '%.testpp.com'
- AND p.name != 'berlin.testpp.com';")
- def check_ext_id(project)
- begin
- client = Mysql2::Client.new(
- host: "somedomain.com",
- username: 'username',
- password: 'password',
- database: 'db_name',
- port: '3306'
- )
- active_sources = get_active_sources(client, project['id'])
- domain = project['channel_value']
- url = 'http://pp2.' + domain + '/ipad%20red?wingman=on&format=json'
- json = open(url, 'X-Requested-With' => 'XMLHttpRequest').read
- parsed = JSON.parse(json)
- outclick_links = parsed['debug_info']['out_clicks']
- outclick_links.each{|outclick_src_name, outclick_link|
- active_sources.each{|source_name, source_external_id|
- if outclick_src_name == source_name
- if outclick_link
- if outclick_link.index(source_external_id)
- puts "#{domain} - #{source_name} - #{source_external_id} - PASS"
- end
- else
- puts "#{domain} - Outclick link for source #{source_name} is empty"
- insert(client, domain, "External tracking id was not found for source #{source_name} in the outclick url")
- end
- active_sources.delete(outclick_src_name)
- end
- }
- }
- if active_sources.empty?
- #do nothing all sources have outclicks
- else
- failed_sources = active_sources.keys.join(',')
- puts "#{domain} - #{failed_sources} - FAIL"
- insert(client, domain, "Outclick section didnt contain #{failed_sources}")
- end
- rescue Exception => ex
- puts "#{domain} - #{ex} - FAIL"
- insert(client, domain, ex)
- ensure
- client.close if client
- end
- end
- threads = []
- active_test_projects.each{|project|
- threads.push Thread.new{check_ext_id(project)}
- }
- threads.each(&:join)
- client.close if client
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement