Class: BBMB::Util::App

Inherits:
SBSM::App
  • Object
show all
Defined in:
lib/bbmb/util/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



58
59
60
61
62
63
64
# File 'lib/bbmb/util/app.rb', line 58

def initialize
    super
    SBSM.logger.info "Starting Rack-Service #{self.class} and service #{BBMB.config.server_url}"
    Thread.new {
        start_service
    }
end

Instance Attribute Details

#db_managerObject

Returns the value of attribute db_manager.



29
30
31
# File 'lib/bbmb/util/app.rb', line 29

def db_manager
  @db_manager
end

#yus_serverObject

Returns the value of attribute yus_server.



29
30
31
# File 'lib/bbmb/util/app.rb', line 29

def yus_server
  @yus_server
end

Instance Method Details

#send_order(order, customer) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bbmb/util/app.rb', line 65

def send_order order, customer
  SBSM.logger.info "send_order #{order.order_id} and customer #{customer.customer_id}"
  begin
    Timeout.timeout(300) {
      BBMB::Util::TargetDir.send_order(order)
    }
  rescue StandardError => err
    err.message << " (Email: #{customer.email} - Customer-Id: #{customer.customer_id})"
    BBMB::Util::Mail.notify_error(err)
  end
  begin
    Timeout.timeout(300) {
      BBMB::Util::Mail.send_order(order)
    }
  rescue StandardError => err
    err.message << " (Email: #{customer.email} - Customer-Id: #{customer.customer_id})"
    BBMB::Util::Mail.notify_error(err)
  end
  begin
    Timeout.timeout(300) {
      BBMB::Util::Mail.send_confirmation(order)
    }
  rescue StandardError => err
    err.message << " (Email: #{customer.email} - Customer-Id: #{customer.customer_id})"
    BBMB::Util::Mail.notify_error(err)
  end
end

#start_serviceObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bbmb/util/app.rb', line 30

def start_service
  case BBMB.config.persistence
  when 'odba'
    DRb.install_id_conv ODBA::DRbIdConv.new
    BBMB.persistence = BBMB::Persistence::ODBA
  end
  BBMB.auth = DRb::DRbObject.new(nil, BBMB.config.auth_url)
  BBMB.server = BBMB::Util::Server.new(BBMB.persistence, self)
  BBMB.server.extend(DRbUndumped)
  BBMB.server = BBMB.server
  if(BBMB.config.update?)
    BBMB.server.run_updater
  end
  if(BBMB.config.invoice?)
    BBMB.server.run_invoicer
  end
  url = BBMB.config.server_url
  url.untaint
  DRb.start_service(url, BBMB.server)
  $SAFE = 1
  $0 = BBMB.config.name
  SBSM.logger.info("started bbmb-server on #{url}")
  DRb.thread.join
  SBSM.logger.info('finished') { sprintf("starting bbmb-server on %s", url) }
rescue Exception => error
  SBSM.logger.error('fatal')
  raise
end