Class: BBMB::Util::Server
- Inherits:
-
SBSM::AdminServer
- Object
- SBSM::AdminServer
- BBMB::Util::Server
- Defined in:
- lib/bbmb/util/server.rb
Instance Method Summary collapse
-
#initialize(persistence, app) ⇒ Server
constructor
A new instance of Server.
- #inject_order(customer_id, products, infos, opts = {}) ⇒ Object
- #invoice(range) ⇒ Object
- #rename_user(customer_id, old_name, new_name) ⇒ Object
- #run_invoicer ⇒ Object
- #run_updater ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(persistence, app) ⇒ Server
Returns a new instance of Server.
29 30 31 32 33 |
# File 'lib/bbmb/util/server.rb', line 29 def initialize(persistence, app) @persistence = persistence @app = app super(app: app) end |
Instance Method Details
#inject_order(customer_id, products, infos, opts = {}) ⇒ Object
45 46 47 |
# File 'lib/bbmb/util/server.rb', line 45 def inject_order(customer_id, products, infos, opts={}) @app.inject_order(customer_id, products, infos, opts) end |
#invoice(range) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/bbmb/util/server.rb', line 34 def invoice(range) SBSM.info "invoice started at #{Time.now} for #{range}" Invoicer.run(range) rescue Exception => e Mail.notify_error(e) end |
#rename_user(customer_id, old_name, new_name) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bbmb/util/server.rb', line 48 def rename_user(customer_id, old_name, new_name) return if old_name.eql?(new_name) BBMB.auth.autosession(BBMB.config.auth_domain) do |session| if (old_name.nil?) begin session.create_entity(new_name) rescue => error raise error if Model::Customer.odba_extent.find {|x| x.email && x.email.index(new_name) } SBSM.info("Skip session.create_entity for customer #{customer_id} as we found no customer with e-mail #{new_name}") end else session.rename(old_name, new_name) end end end |
#run_invoicer ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bbmb/util/server.rb', line 63 def run_invoicer @invoicer ||= Thread.new { Thread.current.abort_on_exception = true loop { today = Date.today day = today >> 1 start = Time.local(today.year, today.month) now = Time.now at = Time.local(day.year, day.month) secs = at - now msg = "run_invoicer sleeping %.2f seconds (or more than %d days)" % [ secs, secs/3600/24 ] SBSM.debug(msg) sleep(secs) invoice(start...at) } } end |
#run_updater ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/bbmb/util/server.rb', line 80 def run_updater run_only_once_at_startup = false SBSM.debug("run_only_once_at_startup? #{run_only_once_at_startup} hour: #{BBMB.config.update_hour}") @updater ||= Thread.new { loop { day = Date.today now = Time.now if(now.hour >= BBMB.config.update_hour) day += 1 end at = Time.local(day.year, day.month, day.day, BBMB.config.update_hour) secs = at - now SBSM.debug("updater sleeping %.2f seconds. run_only_once_at_startup #{run_only_once_at_startup}" % secs) if run_only_once_at_startup then puts "Skipped sleeping #{secs}" else sleep(secs) end SBSM.debug("update starting") update SBSM.debug("update finished") Thread.abort if run_only_once_at_startup } } end |
#update ⇒ Object
40 41 42 43 44 |
# File 'lib/bbmb/util/server.rb', line 40 def update Updater.run rescue Exception => e Mail.notify_error(e) end |