Class: ODDB::Util::Server
- Inherits:
-
SBSM::DRbServer
- Object
- SBSM::DRbServer
- ODDB::Util::Server
- Defined in:
- lib/oddb/util/server.rb
Constant Summary collapse
Instance Method Summary collapse
- #_admin(src, result, priority = 0) ⇒ Object
- #create_product(name) ⇒ Object
- #generate_dictionaries ⇒ Object
- #generate_dictionary(language, locale) ⇒ Object
- #grant_download(*arg) ⇒ Object
-
#initialize(*args) ⇒ Server
constructor
A new instance of Server.
- #ipn(notification) ⇒ Object
- #login(email, pass) ⇒ Object
- #logout(session) ⇒ Object
- #peer_cache(cache) ⇒ Object
- #run_at(hour, &block) ⇒ Object
- #run_exporter ⇒ Object
- #run_updater ⇒ Object
- #unpeer_cache(cache) ⇒ Object
- #update_feedback_rss_feed ⇒ Object
Constructor Details
Instance Method Details
#_admin(src, result, priority = 0) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/oddb/util/server.rb', line 26 def _admin(src, result, priority=0) raise "admin interface disabled" unless(self::class::ENABLE_ADMIN) t = Thread.new { Thread.current.abort_on_exception = false begin response = instance_eval(src) str = response.to_s result << if(str.length > 200) response.class else str end.to_s rescue StandardError => error result << error. require 'pp' ODDB.logger.error('admin') { error.class } ODDB.logger.error('admin') { error. } ODDB.logger.error('admin') { error.backtrace.pretty_inspect } error end } t[:source] = src t.priority = priority @admin_threads.add(t) t end |
#create_product(name) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/oddb/util/server.rb', line 79 def create_product name if prod = ODDB::Drugs::Product.find_by_name(name) "The product already exists. You may edit it at http://de.oddb.org/de/drugs/product/uid/#{prod.uid}" else prod = ODDB::Drugs::Product.new prod.name.de = name prod.save "Success! You may now edit the product at http://de.oddb.org/de/drugs/product/uid/#{prod.uid}" end end |
#generate_dictionaries ⇒ Object
95 96 97 |
# File 'lib/oddb/util/server.rb', line 95 def generate_dictionaries generate_dictionary('german', 'de_DE@euro') end |
#generate_dictionary(language, locale) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/oddb/util/server.rb', line 89 def generate_dictionary(language, locale) ODBA.storage.remove_dictionary(language) base = File.join(ODDB.config.data_dir, "fulltext", "data", "dicts", language) ODBA.storage.generate_dictionary(language, locale, base) end |
#grant_download(*arg) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/oddb/util/server.rb', line 52 def grant_download(*arg) # This method is for bin/admin sub-command usage = "Usage:\n" + " Set grant: grant_download 'email address', 'file', Time.local(20yy,mm,dd)\n" + " Show grant: grant_download 'email address'\n" email = arg[0] file = arg[1] expiry_time = arg[2] if arg.length == 3 # register unless user = ODDB::Business::GrantDownload.find_by_email(email) user = ODDB::Business::GrantDownload.new(email) end user.grant_download(file, expiry_time) user.save ODDB.config.http_server + '/de/temp/grant_download/email/' + email + '/file/' + file elsif arg.length == 1 # search if user = ODDB::Business::GrantDownload.find_by_email(email) grant_list = user.grant_list.sort_by{|filename, expirytime| expirytime}.reverse str = grant_list[0..3].map{|x| x[1].strftime("%Y%m%d") + ', ' + x[0]}.join("\n") "grant list(total:" + grant_list.length.to_s + "): odba_id: " + user.uid.to_s + "\n" + str else 'No registration for ' + email end else usage end end |
#ipn(notification) ⇒ Object
98 99 100 101 |
# File 'lib/oddb/util/server.rb', line 98 def ipn(notification) Util::Ipn.process notification nil # don't return the invoice back across drb - it's not defined in yipn end |
#login(email, pass) ⇒ Object
102 103 104 105 |
# File 'lib/oddb/util/server.rb', line 102 def login(email, pass) session = ODDB.auth.login(email, pass, ODDB.config.auth_domain) Html::Util::KnownUser.new(session) end |
#logout(session) ⇒ Object
106 107 108 109 |
# File 'lib/oddb/util/server.rb', line 106 def logout(session) ODDB.auth.logout(session) rescue DRb::DRbError, RangeError, NameError end |
#peer_cache(cache) ⇒ Object
110 111 112 |
# File 'lib/oddb/util/server.rb', line 110 def peer_cache cache ODBA.peer cache end |
#run_at(hour, &block) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/oddb/util/server.rb', line 113 def run_at(hour, &block) Thread.new { loop { now = Time.now run_at = Time.local(now.year, now.month, now.day, hour) while(now > run_at) run_at += 24*60*60 end sleep(run_at - now) block.call } } end |
#run_exporter ⇒ Object
126 127 128 |
# File 'lib/oddb/util/server.rb', line 126 def run_exporter @exporter = run_at(ODDB.config.export_hour) { Exporter.run } end |
#run_updater ⇒ Object
129 130 131 |
# File 'lib/oddb/util/server.rb', line 129 def run_updater @updater = run_at(ODDB.config.update_hour) { Updater.run } end |
#unpeer_cache(cache) ⇒ Object
132 133 134 |
# File 'lib/oddb/util/server.rb', line 132 def unpeer_cache cache ODBA.unpeer cache end |
#update_feedback_rss_feed ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/oddb/util/server.rb', line 135 def update_feedback_rss_feed async { begin @rss_mutex.synchronize { Export::Rss::Feedback.new.export } rescue StandardError => error ODDB.logger.error('rss_feed') { error.class } ODDB.logger.error('rss_feed') { error. } ODDB.logger.error('rss_feed') { error.backtrace.pretty_inspect } end } end |