Skip to content

Instantly share code, notes, and snippets.

@amboxer21
Created February 26, 2015 21:32
Show Gist options
  • Save amboxer21/7a1aa361ce2eb27fe92f to your computer and use it in GitHub Desktop.
Save amboxer21/7a1aa361ce2eb27fe92f to your computer and use it in GitHub Desktop.
mtt3 program that is responsible for handling forwards
#!/usr/bin/ruby
#
# ivad_driver.rb is closely related to the rails application
# located at https://mtt4.monmouth.com/ivad.
# ivad_driver.rb's job is to read the pending operations from the database
# (that the web app writes to) and perform the modification on the necessary
# equipment as well as update the callerid and whodunit tables
require "/etc/ivad/ivad_rails_env_config"
require 'ivad/simple_factory'
#Add check to see if switch processing has been done in last
#5 minutes. If check is true exit.
last_processed = ActionSession.find(:all,:limit => 1, :order => "processed_at DESC")[0].processed_at
#If stdin is a terminal we can bypass this check
if !$stdin.tty? and last_processed > 5.minutes.ago then exit end
#Add check to see if another invocation of ivad_driver.rb
#is already running. If check is true exit.
#running = `ps -u sysadmin | grep ivad_driver.rb | wc -l`
running = `ps -e | grep [i]vad_driver.rb | wc -l`
if running.to_i > 1 then
puts "Exiting because an invocation of ivad_driver.rb is already running.[#{running.to_i}]:\n"
puts `ps -e | grep [i]vad_driver.rb`
exit
end
#This logic relies on prepare_forwards to sort the forwards
#such that the pending deletes are all before the pending adds
#this is not very intuitive:(
SimpleFactory.prepare_forwards.each do | f |
puts f
case f.operation.id
when IvadTransaction::OPERATION_ADD, IvadTransaction::OPERATION_EDIT, IvadTransaction::OPERATION_UNSUSPEND
if(f.activate_billing)
f.activate_service
end
when IvadTransaction::OPERATION_DELETE, IvadTransaction::OPERATION_SUSPEND
if(f.deactivate_service)
f.deactivate_billing
end
end
end
#SimpleFactory.prepare_nps.each do |np|
# if np.deactivate_service
# np.deactivate_billing
# end
#end
SimpleFactory.prepare_nps.each do |np|
case np.operation.name
when "port_in"
np.activate_service
when "suspend_number"
np.complete_suspension
when "unsuspend_number"
np.complete_unsuspend
when "mark_unmark_hpbx"
np.complete_mark_unmark_hpbx
else
if np.deactivate_service
np.deactivate_billing
end
end
end
SimpleFactory.prepare_uneps.each do |np|
if np.deactivate_service
np.deactivate_billing
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment