Class: BBMB::Util::Server
- Inherits:
-
Object
- Object
- 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(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.
28 29 30 31 |
# File 'lib/bbmb/util/server.rb', line 28 def initialize(persistence, app) @persistence = persistence @app = app end |
Instance Method Details
#inject_order(customer_id, products, infos, opts = {}) ⇒ Object
43 44 45 |
# File 'lib/bbmb/util/server.rb', line 43 def inject_order(customer_id, products, infos, opts={}) @app.inject_order(customer_id, products, infos, opts) end |
#invoice(range) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/bbmb/util/server.rb', line 32 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(old_name, new_name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bbmb/util/server.rb', line 46 def rename_user(old_name, new_name) return if old_name.eql?(new_name) BBMB.auth.autosession(BBMB.config.auth_domain) do |session| if(old_name.nil?) session.create_entity(new_name) else session.rename(old_name, new_name) end end end |
#run_invoicer ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bbmb/util/server.rb', line 56 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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bbmb/util/server.rb', line 73 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
38 39 40 41 42 |
# File 'lib/bbmb/util/server.rb', line 38 def update Updater.run rescue Exception => e Mail.notify_error(e) end |