Skip to content

Instantly share code, notes, and snippets.

@txssseal
Last active December 18, 2015 00:29
Show Gist options
  • Save txssseal/963fe5feea6c546c3e20 to your computer and use it in GitHub Desktop.
Save txssseal/963fe5feea6c546c3e20 to your computer and use it in GitHub Desktop.

#Rewrite commsys worker

###UUID might be the best approach, see bottom

I think we need to have a CommsysWorker, that calls a Commsys.rb class and does the below.

I beleive we should use the same queries that we have been using such as

Person.has_open_warrant.where(:last_commsys_run => nil).order('id desc')

or

Person.has_open_warrant.where("last_commsys_run <= current_date - interval '7 days' or last_commsys_run is null").order('id desc')

and send the results off to a Commsys.rb class

Commsys.rb will go through each person within the above query and run the appropriate commsys calls on them.

for example if we want to get the address of the person we will run

a = CommsysAddress.new( first_name: 'person.nam_first.upcase', last_name: 'person.nam_last.upcase', date_of_birth: 'person.dob', sex: 'person.sex', race: 'person.race')

or to run by the drivers license if it exists

a = CommsysAddress.new( dl: 'person.dl_no', state: 'TX')

from there we would create a new address record

  Address.create!(person_id: 'person.id', address_type: 'HOME', 
  address_1: a.get_address_street_by_name,
  city: a.get_address_city_by_name,
  state: a.get_address_state_by_name,
  zip: a.get_address_zip_by_name,
  how_update_obtained: 'Commsys')

and then we would have an address record for that person from commsys.

Afterwards we would do do the same for all the other commsys classes.

list of classes is as follows

CommsysAddress
CommsysDriversLicense
CommsysInsurance
CommsysNcic
CommsysPicture (this returns back a Base64 image)
CommsysRegionsHit
CommsysTcic
CommsysUuid
CommsysVehicle
Connect (this is the base class that makes the calls to the API)

the only thing I see not being effective here is that we are making a bunch of calls to the database at once and waiting 12 sec to recieve back each call. So maybe the most effective way of doing this would be to make a call to the IG initially just to get back the UUID. Save that UUID, and then for the rest of the calls use that person UUID to hit the database on the IG and recieve back calls within a second or so. I dont know which way would be best.

#Using UUID

if we were to use UUIDs i think the best way to do it would be to create a field in the people table called ig_uuid and another field called last_ig_uuid_update. We then have a worker that does something like below

Person.has_open_warrant.where('last_ig_uuid_update is null').each do |c|
  u = CommsysUuid.new( first_name: c.nam_first, last_name: c.nam_last, date_of_birth: c.dob, sex: c.sex, race: c.race).get_uuid_by_name 
  c.update_attributes( ig_uuid: u, last_ig_uuid_update: Time.now )
  c.save
end

then once we have the UUID we can run most all of our calls extremly fast.

So for the above example for saving an address we would do something like this

Person.has_open_warrant.each do |c|
  a = CommsyAddress.new( uuid: c.ig_uuid )
  Address.create!(person_id: 'person.id', address_type: 'HOME', 
      address_1: a.get_address_street_by_uuid,
      city: a.get_address_city_by_uuid,
      state: a.get_address_state_by_uuid,
      zip: a.get_address_zip_by_uuid,
      how_update_obtained: 'Commsys')
end

we could add in insurance and whatever else we want to that block.

###To Get Vehicle UUID you must use the folowing call

so I think the best way to do this would be the same process as above, create a field in the vehicles table called ig_vehicle_uuid, and last_ig_vehicle_uuid_update.

a = CommsysUuid.new( license_plate_number: 'BHZ2186', license_plate_year: '2015').get_vehicle_uuid_by_plate

then to get the various insurance info you can do the following types of calls.

CommsysInsurance.new( vehicle_uuid: '4f249670-efc1-490b-b2ef-1f217be9f9a3' ).get_insurance_carrier_by_uuid

#Notes

  1. Remeber to update the last commsys ran field in the people table

  2. Remeber to create a Note that says commsys has been ran

  3. UUID probably the best approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment