ExtBatch

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/ext_batch. To experiment with that code, run bin/console for an interactive prompt.

Extended the ext_logger gem package, services for Ruby batch and Ruby rake. 
Other extensions see version updates.
2019-01-20(0.1.4):
    dependency: ext_logger ~> v0.2
    Add configuration for batch mail.

Installation

Add this line to your application's Gemfile:

gem 'ext_batch'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ext_batch

Configure

Mail configuration, add the following configuration to the Application Mailer file.

  # add to application_mailer.rb
  def send_batch_mail(to, title, body)
    mail_hash = {
        to: to,
        subject: title,
        body: body,
        content_type: 'text/html',
    }

    mail(mail_hash)
  end

Usage

  1. Initialization object (It automatically creates non-existent directories based on paths):
    batch = ExtBatch.new(task_name, {log: {age: 7/'weekly', size: 1024000, split_format: '%Y%m%d%H%M', log_max_num: 5}})
    # task_name: task object or task name string, if there is ":", it will automatically change to "/", and finally generate the log directory.
  1. Output log (Extended ext_logger.info):
    batch.info("log content")
    batch.debug("log content")
    batch.error("log content")
    batch.warn("log content")
    batch.fatal("log content")
    batch.exception(e, {send_mail: ExtBatch::SEND_MAIL_NO/ExtBatch::SEND_MAIL_YES}) # when rescure Exception => e, send_mail default ExtBatch::SEND_MAIL_NO
  1. Send mail:
    batch.mail_ok({content: "mail content"})
    batch.mail_error({content: "mail content"})
    batch.mail_warn({content: "mail content"})
    batch.mail_exception(e, {content: "mail content"}) # when rescure Exception => e
  1. Real-time display time:
    batch.show_use_time
  1. Batch termination processing:
    batch.end

Example:

    # In rake batch_name = task
    # In ruby file batch_name = File.basename(__FILE__).gsub('.rb', '')
    # In method batch_name = __method__

    batch = ExtBatch.new(batch_name)
    begin
      batch.info 'info message'
      batch.error 'error message'
      ...

      batch.mail_ok({to: '[email protected]', content: 'mail content.'})
      batch.mail_ok({to: '[email protected]', content: 'mail content.'})
      ...
    rescue Exception => e
      batch.exception(e, {send_mail: true/false})
    end
    batch.end

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ext_batch.

License

The gem is available as open source under the terms of the MIT License.