view · edit · sidebar · attach · print · history

20101217-update-mail_process-bbmb_ch

<< Masa.20101220-debug-ch_oddb_org-generics_xls | 2010 | Masa.20101216-update-import_de_oddb_org_Festbe_Zubef >>


  1. Check smtp_tls library
  2. Check the current email sending process locally
  3. Update bbmb ver.2
  4. Confirm Bbmb2 working locally
  5. Check mail process bbmb2 locally
  6. bbmb2 setup script

Goal
  • Update bbmb.ch mail process / 70%
Milestones
  1. check smtp_tls 8:45
  2. bbmb.ch updating 10:30
    • check email sending in bbmb.ch locally
    • separate configuration data from the code (using bbmb.yaml) suspend
    • update code (test case too) suspend
  3. Update bbmb (ver.2)
    • Change smtp server
    • Separate account information from code
    • Check smtp_tls.rb with bbmb2 locally 14:15
    • Check mail process in bbmb2
    • Test mail process with smtp_tls and gmail server 15:50
  • setup script bbmb2 16:50
Summary
Commits
ToDo Tomorrow
Keep in Mind
  1. setup script bbmb
  2. different page 2010, 2011 and navigator link at the bottom of page PM-Wiki Markup for paging between pages
  3. export_fachinfo test locally (weekend)
  4. swissmedic_followers debug
  5. change email method bbmb.ch
  6. rpdf2txt announcement 20101214
  7. On Ice
  8. emerge --sync

Check smtp_tls library

What is smtp_tls?

  • smtp_tls is built in from Ruby 1.8.7, but not in Ruby 1.8.6

References

Confirm

test.rb

require 'net/smtp'
require 'smtp_tls'
require 'rmail'


def make_header(subject, from, recipients, charset="utf8")
  mpart = RMail::Message.new
  header = mpart.header
  header.to = recipients
  header.from = from
  header.subject = subject
  header.date = Time.now
  header.add('Content-Type', 'text/plain', nil,
             'charset' => charset)
  return mpart
end

def sendmail(subject, message, from, recipients, charset="utf8")
  mpart = make_header(subject, from, recipients, charset)
  mpart.body = message.join("\n")

  smtp_server = "smtp.gmail.com"
  smtp_port = 25
  smtp_domain = "ywesee.com"
  smtp_user = from
  smtp_pass = "ppp"
  smtp_authtype = :plain

  smtp = Net::SMTP.new(smtp_server, smtp_port)
  smtp.start(smtp_domain, smtp_user, smtp_pass,
                  smtp_authtype) do |server|
    recipients.each do |recipient|
      server.sendmail(mpart.to_s, from, recipient)
    end
  end
end


recipients = ["mhatakeyama@ywesee.com"]
from = "mhatakeyama@ywesee.com"
message = ["hello, world", "by masa"]
subject = "test mail"
charset = "utf8"


sendmail(subject, message, from, recipients, charset)

Note

  • Works

Experiment (install and use the latest version of smtp_tls)

Install

masa@masa ~/work $ sudo gem install smtp_tls

Run a sample of net/smtp

masa@masa ~/work $ cat test.rb 

require 'net/smtp'
require 'smtp_tls'
require 'rmail'


def make_header(subject, from, recipients, charset="utf8")
  mpart = RMail::Message.new
  header = mpart.header
  header.to = recipients
  header.from = from
  header.subject = subject
  header.date = Time.now
  header.add('Content-Type', 'text/plain', nil, 
             'charset' => charset)
  return mpart
end

def sendmail(subject, message, from, recipients, charset="utf8")
  mpart = make_header(subject, from, recipients, charset)
  mpart.body = message.join("\n")

  smtp_server = "smtp.gmail.com"
  smtp_port = 25
  smtp_domain = "ywesee.com"
  smtp_user = from
  smtp_pass = "ppp"
  smtp_authtype = :plain

  Net::SMTP.start(smtp_server, smtp_port,
                  smtp_domain, smtp_user, smtp_pass,
                  smtp_authtype) do |smtp|
    recipients.each do |recipient|
      smtp.sendmail(mpart.to_s, from, recipient)
    end
  end
end


recipients = ["mhatakeyama@ywesee.com"]
from = "mhatakeyama@ywesee.com"
message = ["hello, world", "by masa"]
subject = "test mail"
charset = "utf8"


sendmail(subject, message, from, recipients, charset)

Result

masa@masa ~/work $ ruby test.rb 
/usr/lib64/ruby/1.8/net/smtp.rb:579:in `auth_plain': 530 5.7.0 Must issue a STARTTLS command first. f52sm465370wes.35 (Net::SMTPAuthenticationError)
        from /usr/lib64/ruby/1.8/net/smtp.rb:573:in `__send__'
        from /usr/lib64/ruby/1.8/net/smtp.rb:573:in `authenticate'
        from /usr/lib64/ruby/1.8/net/smtp.rb:410:in `do_start'
        from /usr/lib64/ruby/gems/1.8/gems/smtp_tls-1.0.3/lib/smtp_tls.rb:41:in `send'
        from /usr/lib64/ruby/gems/1.8/gems/smtp_tls-1.0.3/lib/smtp_tls.rb:41:in `start'
        from /usr/lib64/ruby/gems/1.8/gems/smtp_tls-1.0.3/lib/smtp_tls.rb:24:in `start'
        from test.rb:30:in `sendmail'
        from test.rb:47

Note

  • There is no error, when I use smtp_tls.rb of de.oddb.org
  • An error comes in the case of the latest smtp_tls
  • What is this error?

Experiment

test.rb


require 'net/smtp'
require 'smtp_tls'
require 'rmail'


def make_header(subject, from, recipients, charset="utf8")
  mpart = RMail::Message.new
  header = mpart.header
  header.to = recipients
  header.from = from
  header.subject = subject
  header.date = Time.now
  header.add('Content-Type', 'text/plain', nil,
             'charset' => charset)
  return mpart
end

def sendmail(subject, message, from, recipients, charset="utf8")
  mpart = make_header(subject, from, recipients, charset)
  mpart.body = message.join("\n")

  smtp_server = "smtp.gmail.com"
  smtp_port = 25
  smtp_domain = "ywesee.com"
  smtp_user = from
  smtp_pass = "ppp"
  smtp_authtype = :plain

  smtp = Net::SMTP.new(smtp_server, smtp_port)
  smtp.enable_starttls
  smtp.start(smtp_domain, smtp_user, smtp_pass, smtp_authtype) do |server|
    recipients.each do |recipient|
      server.sendmail(mpart.to_s, from, recipient)
    end
  end
end

recipients = ["mhatakeyama@ywesee.com"]
from = "mhatakeyama@ywesee.com"
message = ["hello, world", "by masa"]
subject = "test mail"
charset = "utf8"

sendmail(subject, message, from, recipients, charset)

Result

  • success
masa@masa ~/work $ ruby test.rb 
masa@masa ~/work $ 

Note

  • There is no log coming on console
  • Email test mail
hello, world
by masa

Conclusion

  • There are a little bit differences between the latest and the old version of smtp_tls
  • At the moment, it is simpler solution to use the old smtp_tls for bbmb.ch updating

Check the current email sending process locally

Note

  • mail_send method is called only from run_statistics

Experiment

src/testenrivonment.rb

#!/usr/bin/env ruby

puts 'loading testenvironment'
class BbmbApp < SBSM::DRbServer
    puts "disabling UPDATER"
    remove_const :RUN_UPDATER
#    remove_const :RUN_STATISTICS
    RUN_UPDATER = false
#    RUN_STATISTICS = false
print "BbmbApp::RUN_UPDATER="
p RUN_UPDATER
print "BbmbApp::RUN_STATISTICS="
p RUN_STATISTICS

end
module BBMB
  class CustomBehaviorGag < CustomBehavior
    remove_const :MAIL_RECIPIENTS
    remove_const :MAIL_RECIPIENTS_CC
    remove_const :MAIL_INJECT_RECIPIENTS
    remove_const :MAIL_PDF_RECIPIENTS
    remove_const :MAIL_PDF_RECIPIENTS_CC
    remove_const :MAIL_PDF_FROM
    remove_const :REMOTE_ACCESS
    MAIL_RECIPIENTS = ['mhatakeyama@ywesee.com']
    MAIL_RECIPIENTS_CC = []
    MAIL_INJECT_RECIPIENTS = ['mhatakeyama@ywesee.com']
    MAIL_PDF_RECIPIENTS = ['mhatakeyama@ywesee.com']
    MAIL_PDF_RECIPIENTS_CC = []
    MAIL_PDF_FROM = 'mhatakeyama@ywesee.com'
    REMOTE_ACCESS = 'ftp://ftp_user1:ppp@localhost'
print "BBMB::CustomBehaviorGag::MAIL_RECIPIENTS="
p BBMB::CustomBehaviorGag::MAIL_RECIPIENTS

  end

end

src/custom/behavior.rb

        def mail_send(mail, from, to)
p "getin mail_send"
print "from=", from, "\n"
print "to=", to, "\n"
unless to.grep(/mhatakeyama/)
  p "Oh, my GOD!"
  exit
end
            #smtp = Net::SMTP.new('localhost')
            smtp = Net::SMTP.new('smtp.google.com', 25)
            #smtp.start {
            smtp.start("ywesee.com", "mhatakeyama@ywesee.com", "ppp", :plain) {
                begin
p "gefore sendmail"
                    smtp.sendmail(mail.encoded(), from, to)
p "after sendmail"
                rescue Net::SMTPFatalError => error

Result

/usr/lib64/ruby/1.8/timeout.rb:60:in `new': execution expired (Timeout::Error)
        from /usr/lib64/ruby/1.8/net/protocol.rb:206:in `old_open'
        from /usr/lib64/ruby/1.8/net/protocol.rb:206:in `old_open'
        from /usr/lib64/ruby/1.8/net/smtp.rb:392:in `do_start'
        from /usr/lib64/ruby/1.8/net/smtp.rb:377:in `start'
        from /home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:360:in `mail_send'
        from /home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:418:in `mail_statistics'
        from /home/masa/ywesee/bbmb.ch/src/model/reseller.rb:48:in `send'
        from /home/masa/ywesee/bbmb.ch/src/model/reseller.rb:48:in `method_missing'
         ... 9 levels...
        from /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:514:in `run_statistics'
        from /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:299:in `initialize'
        from bin/bbmbd:10:in `new'
        from bin/bbmbd:10

Note

  • fail

Experiment

src/custom/behavior.rb

        def mail_send(mail, from, to)
            #smtp = Net::SMTP.new('localhost')
            smtp = Net::SMTP.new('smtp.gmail.com', 25)
            #smtp.start {
            smtp.start("ywesee.com", "mhatakeyama@ywesee.com", "ppp", :plain) {
                begin
#raise Net::SMTPFatalError, "masa error"
                    smtp.sendmail(mail.encoded(), from, to)
                rescue Net::SMTPFatalError => err
                    error = TMail::Mail.new
                    error.from = from
                    error.to = 'mhatakeyama@ywesee.com'
                    error.subject = "Mail-Delivery Error!"
                    error.date = Time.now

                    etext = TMail::Mail.new
                    etext.set_content_type('text', 'plain', 'charset'=>'iso-8859-1')
                    etext.body = [
                    #   errror,
                    #   error.message,
                    #   error.backtrace,
                        err,
                        err.message,
                        err.backtrace,
                    ].join("\n")
                    error.parts << etext
                    smtp.sendmail(error.encoded(), from, to)
                end
            }
        end

Run bbmb.ch/bin/bbmbd

Result

Monatlicher Export verkaufte Produkte: GXXXXpharm-17.12.2010
Verkaufte Produkte von 01. bis 30.11.2010

Notes

  • But the company name (GXXXXpharm) is still the old one
  • It seems that the mail sending is recorded in log, and an email will not be sent in the same month
    • If I delete (replace) the log file, then an email is sent

Error mail check

src/custom/behavior.rb

        def mail_send(mail, from, to)
            #smtp = Net::SMTP.new('localhost')
            smtp = Net::SMTP.new('smtp.gmail.com', 25)
            #smtp.start {
            smtp.start("ywesee.com", "mhatakeyama@ywesee.com", "ppp", :plain) {
                begin

raise Net::SMTPFatalError, "masa error"

                    smtp.sendmail(mail.encoded(), from, to)
                rescue Net::SMTPFatalError => err
                    error = TMail::Mail.new
                    error.from = from
                    error.to = 'mhatakeyama@ywesee.com'
                    error.subject = "Mail-Delivery Error!"
                    error.date = Time.now

                    etext = TMail::Mail.new
                    etext.set_content_type('text', 'plain', 'charset'=>'iso-8859-1')
                    etext.body = [
                    #   errror,
                    #   error.message,
                    #   error.backtrace,
                        err,
                        err.message,
                        err.backtrace,
                    ].join("\n")
                    error.parts << etext
                    smtp.sendmail(error.encoded(), from, to)
                end
            }
        end

Result

masa error
masa error
/home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:357:in `mail_send'
/usr/lib64/ruby/1.8/net/smtp.rb:378:in `start'
/home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:354:in `mail_send'
/home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:414:in `mail_statistics'
/home/masa/ywesee/bbmb.ch/src/model/reseller.rb:48:in `send'
/home/masa/ywesee/bbmb.ch/src/model/reseller.rb:48:in `method_missing'
/home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:613:in `statistics'
/home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:611:in `each'
/home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:611:in `statistics'
/home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:609:in `loop'
/home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:609:in `statistics'
/home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:516:in `run_statistics'
/usr/lib64/ruby/site_ruby/1.8/mnemonic/Mnemonic.rb:207:in `initialize'
/usr/lib64/ruby/site_ruby/1.8/mnemonic/Mnemonic.rb:207:in `__mnemonic_new__'
/usr/lib64/ruby/site_ruby/1.8/mnemonic/Mnemonic.rb:207:in `new'
/home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:513:in `run_statistics'
/home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:299:in `initialize'
bin/bbmbd:10:in `new'
bin/bbmbd:10

Note

  • Good

Commit

Reference

Next

  • separate the account information from the source code, store it in yaml file

suspend

Update bbmb ver.2

Reference

Memo

  • I cannot find 'SMPT' keyword anywhere

Question

  • How does the system send an email message?

Note

  • The project 'sanxxx.bbmb.ch' is the custom files from 'bbmb'
  • So, I should check 'bbmb', not 'sanxxx.bbmb.ch'

grep search

masa@masa ~/ywesee/bbmb $ grep -ri smtp *
lib/bbmb/config.rb:    'smtp_authtype'                   => nil,
lib/bbmb/config.rb:    'smtp_helo'                       => 'localhost.localdomain',
lib/bbmb/config.rb:    'smtp_pass'                       => nil,
lib/bbmb/config.rb:    'smtp_port'                       => 25,
lib/bbmb/config.rb:    'smtp_server'                     => 'mail.bbmb.ch',
lib/bbmb/config.rb:    'smtp_user'                       => nil,
lib/bbmb/util/mail.rb:require 'net/smtp'
lib/bbmb/util/mail.rb:    Net::SMTP.start(config.smtp_server, config.smtp_port, config.smtp_helo,
lib/bbmb/util/mail.rb:                    config.smtp_user, config.smtp_pass, 
lib/bbmb/util/mail.rb:                    config.smtp_authtype) { |smtp|
lib/bbmb/util/mail.rb:      smtp.sendmail(message.to_s, from, [to, cc].flatten.compact)

Note

  • It looks that lib/bbmb/util/mail.rb is the part to send an email as well as src/custom/behavior.rb in bbmb.ch (ver.1)

Summary

  • The account information is separated from source code
  • The smtp server is replaced by the different from 'localhost'
  • But gmail server is not used, and smtp_tls.rb is not used either

Next

  • just git push smtp_tls.rb in bbmb project
  • before that, I should check that smtp_tls.rb works locally

Confirm Bbmb2 working locally

Try to run bin/bbmbd

masa@masa ~/ywesee/bbmb $ bin/bbmbd 
/usr/lib64/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:118:in `initialize': FATAL:  database "bbmb" does not exist (DBI::OperationalError)
        from /usr/lib64/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:62:in `new'
        from /usr/lib64/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:62:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/dbi.rb:448:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/dbi.rb:221:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:60:in `_connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:59:in `times'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:59:in `_connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `synchronize'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:19:in `initialize'
        from /home/masa/ywesee/bbmb/lib/bbmb/persistence/odba.rb:38:in `new'
        from /home/masa/ywesee/bbmb/lib/bbmb/persistence/odba.rb:38
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bin/bbmbd:18

Note

  • I have to review the past blogs

References

Check bbmbd working locally

masa@masa ~/ywesee/bbmb $ bin/bbmbd config="config.yml"
masa@masa ~/ywesee/yus $ bin/yusd server_url="druby://localhost:12001"

config.yml

---
error_recipients:
 - mhatakeyama@ywesee.com
bbmb_dir: /home/masa/ywesee/bbmb
db_name: sandoz_bbmb
db_user: sandoz
db_pass: sandoz
importers:
 "Kunden.txt": "CustomerImporter"
load_files:
# - 'bbmb/sandoz'
 - 'bbmb/util/csv_importer'
log_level: DEBUG
mail_order_to: mhatakeyama@ywesee.com
mail_order_from: mhatakeyama@ywesee.com
name: "Bbmb(Masa)"
smtp_server: mail.ywesee.com
smtp_authtype: :plain
smtp_user: 'mhatakeyama@ywesee.com'
smtp_pass: ppp
target_format: csv
#ydim_config: /var/www/sandoz.bbmb.ch/etc/ydim.yml
#ydim_id: 51
inject_error_body: |
  inject_error_body
inject_error_subject: 'Bestellung "%s" mit fehlendem Kunden: "%s"'
inject_error_from: 'mhatakeyama@ywesee.com'
inject_error_to: 'mhatakeyama@ywesee.com'
mail_confirm_from: 'mhatakeyama@ywesee.com'
mail_confirm_reply_to: 'mhatakeyama@ywesee.com'
mail_confirm_subject: "Masa: Auftragsbestätigung %s"
mail_confirm_lines:
 - "%3i x %-40s ā %6.2f, total  %7.2f"
 - "%3i x %-40s ā %6.2f, total  %7.2f"
 - "%3i x %-40s a %6.2f, totale %7.2f"
mail_confirm_body: |
  mail_confirm_body
confirm_error_body: |
  confirm_error_body
confirm_error_subject: Kunde "%s" ohne hinterlegte Email-Adresse im Masa E-shop
confirm_error_from: 'mhatakeyama@ywesee.com'
confirm_error_to: 'mhatakeyama@ywesee.com'

invoice?: false
update?: true
new_customer_mail: "mailto:mhatakeyama@ywesee.com?subject=Neukunde BBMB - bitte Passwort generieren"
polling_file: '/home/masa/ywesee/bbmb/etc/polling.yml'

/etc/apache2/vhosts.d/04_bbmb_vhost.conf

masa@masa ~/ywesee/bbmb $ cat /etc/apache2/vhosts.d/04_bbmb_vhost.conf 
<Directory /home/masa/ywesee/bbmb/doc>
  Options ExecCGI FollowSymlinks Indexes
  AllowOverride None
  Order allow,deny
  Allow from all
#  SSLRequireSSL
#  ErrorDocument 403 https://masa.bbmb.ch
</Directory>

<VirtualHost *:80>
  DocumentRoot /home/masa/ywesee/bbmb/doc
  ServerName bbmb.masa.ch
  DirectoryIndex index.rbx
  RubyAddPath /home/masa/ywesee/bbmb/src
  RubyRequire 'sbsm/trans_handler'
  SetHandler ruby-object
  RubyTransHandler SBSM::TransHandler.instance
#  ErrorLog "|/usr/sbin/cronolog -l /home/masa/ywesee/bbmb/log/error_log /home/masa/ywesee/bbmb/log/%Y/%m/%d/error_log"
#  CustomLog "|/usr/sbin/cronolog -l /home/masa/ywesee/bbmb/log/access_log /home/masa/ywesee/bbmb/log/%Y/%m/%d/access_log" combined
#  SetEnv DEFAULT_FLAVOR masa_bbmb
  SetEnv DRB_SERVER druby://localhost:12000
</VirtualHost>

Result

Check mail process bbmb2 locally

grep search

masa@masa ~/ywesee/bbmb $ grep -r sendmail lib
lib/bbmb/util/mail.rb:      Mail.sendmail message, from, to, cc
lib/bbmb/util/mail.rb:    Mail.sendmail(message, from, to)
lib/bbmb/util/mail.rb:    Mail.sendmail(message, from, to)
lib/bbmb/util/mail.rb:      Mail.sendmail message, from, to, cc
lib/bbmb/util/mail.rb:  def Mail.sendmail(message, from, to, cc=[])
lib/bbmb/util/mail.rb:p "getin Mail.sendmail"
lib/bbmb/util/mail.rb:      smtp.sendmail(message.to_s, from, [to, cc].flatten.compact)
lib/bbmb/util/mail.rb:    Mail.sendmail(message, from, to, config.mail_confirm_cc)
lib/bbmb/util/mail.rb:    Mail.sendmail(message, from, to, cc)
lib/bbmb/util/mail.rb:    Mail.sendmail(message, from, to, cc)

Notes

  • Every 'sendmail' calling is in lib/bbmb/util/mail.rb
  • All the methods in Mail module except for Mail.setup call 'Mail.sendmail' at the last line of the methods
masa@masa ~/ywesee/bbmb $ grep -r "Mail.send" lib|grep -v mail.rb
lib/bbmb/html/state/login.rb:        BBMB::Util::Mail.send_request(input[:email], input[:organisation], body)
lib/bbmb/util/server.rb:            BBMB::Util::Mail.send_order(order)
lib/bbmb/util/server.rb:            BBMB::Util::Mail.send_confirmation(order)

masa@masa ~/ywesee/bbmb $ grep -r "Mail.notify" lib|grep -v mail.rb
lib/bbmb/util/invoicer.rb:        Util::Mail.notify_debug("No invoice necessary", body)
lib/bbmb/util/polling_manager.rb:    BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/polling_manager.rb:    BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/polling_manager.rb:    BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/server.rb:          BBMB::Util::Mail.notify_inject_error(order, opts)
lib/bbmb/util/server.rb:        Mail.notify_error(e)
lib/bbmb/util/server.rb:          BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/server.rb:          BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/server.rb:          BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/server.rb:        Mail.notify_error(e)

Consideration

  • Choose one process and check it

Experiment

config.yml (change the following parts)

...
smtp_server: smtp.gmail.com
smtp_port: 587
...
update?: true
...

lib/bbmb/util/server.rb

require 'bbmb/util/smtp_tls'
...
      def run_updater
        @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)
                            now.hour, now.min+1)
print "at="
p at
print "now="
p now
            secs = at - now
            BBMB.logger.debug("updater") {
              "sleeping %.2f seconds" % secs
            }
            sleep(secs)
            update
p "done update"
            sleep(100000)
          }
        }
      end
...
      def update
p "getin BBSB::Util::Server#update"
raise Exception, "masa error"
        Updater.run
      rescue Exception => e
        Mail.notify_error(e)
      end

Copy smtp_tls.rb in lib/bbmb/util/

masa@masa ~/ywesee/bbmb $ ls lib/bbmb/util/
csv_importer.rb  mail.rb          numbers.rb             polling_manager.rb  smtp_tls.rb    transfer_dat.rb
invoicer.rb      multilingual.rb  password_generator.rb  server.rb           target_dir.rb  updater.rb

Run

masa@masa ~/ywesee/bbmb $ bin/bbmbd config="config.yml"

Result

Exception
masa error
["/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:162:in `update'",
 "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:128:in `run_updater'",
 "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:110:in `loop'",
 "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:110:in `run_updater'",
 "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:109:in `initialize'",
 "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:109:in `new'",
 "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:109:in `run_updater'",
 "bin/bbmbd:43"]
  • Works

Commit

bbmb2 setup script

Notes

  • This script is only for my local environment
  • 'config.yml' is necessary
  • An account to the server is also necessary
  • The virtual host setting is necessary

References

view · edit · sidebar · attach · print · history
Page last modified on July 13, 2011, at 12:05 PM