Sha256: 2ece0f050cdc079f5dcf2ce68ded586adebfe2bc7624a922bc20f9b5043c5286

Contents?: true

Size: 518 Bytes

Versions: 3

Compression:

Stored size: 518 Bytes

Contents

module Workarea
  module Orderbot
    class ImportLog
      include ApplicationDocument

      field :importer, type: String
      field :started_at, type: Time
      field :finished_at, type: Time

      def self.log(type)
        instance = find_or_create_by(importer: type)
        last_imported_at = instance.started_at || 1.day.ago
        instance.update!(started_at: Time.current, finished_at: nil)
        yield(last_imported_at)
        instance.update!(finished_at: Time.current)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
workarea-orderbot-1.0.2 app/models/workarea/orderbot/import_log.rb
workarea-orderbot-1.0.1 app/models/workarea/orderbot/import_log.rb
workarea-orderbot-1.0.0 app/models/workarea/orderbot/import_log.rb