<commit_before># -*- coding: utf-8 -*-

require 'sequel'

module Isono
  module ManagerModules
    class DataStore < Base
      include Logger

      config_section do
        desc ""
        database_dsn ''
      end
      
      def self.pass(&blk)
        instance.db_writer_thread.pass {
          instance.db.transaction {
            blk.call
          }
        }
      end

      def self.barrier(&blk)
        instance.db_writer_thread.barrier {
          instance.db.transaction {
            blk.call
          }
        }
      end

      attr_reader :db_writer_thread, :db
      
      def on_init(args)
        @db_writer_thread = ThreadPool.new(1)

        @db_writer_thread.barrier {
          #@db = Sequel.connect(config_section.database_dsn, {:logger=>logger})
          @db = Sequel.connect(config_section.database_dsn)
          logger.debug("connected to the database: #{config_section.database_dsn}, #{@db}")
        }
      end
      
      def on_terminate
        @db_writer_thread.shutdown
      end
      
    end
  end
end<commit_msg>data_store: call disconnect() on termination.<commit_after># -*- coding: utf-8 -*-

require 'sequel'

module Isono
  module ManagerModules
    class DataStore < Base
      include Logger

      config_section do
        desc ""
        database_dsn ''
      end
      
      def self.pass(&blk)
        instance.db_writer_thread.pass {
          instance.db.transaction {
            blk.call
          }
        }
      end

      def self.barrier(&blk)
        instance.db_writer_thread.barrier {
          instance.db.transaction {
            blk.call
          }
        }
      end

      attr_reader :db_writer_thread, :db
      
      def on_init(args)
        @db_writer_thread = ThreadPool.new(1)

        @db_writer_thread.barrier {
          #@db = Sequel.connect(config_section.database_dsn, {:logger=>logger})
          @db = Sequel.connect(config_section.database_dsn)
          logger.debug("connected to the database: #{config_section.database_dsn}, #{@db}")
        }
      end
      
      def on_terminate
        @db_writer_thread.shutdown
        @db.disconnect
      end
      
    end
  end
end
{'fraction_non_alphanumeric': 0.08986703347088491, 'fraction_numerical': 0.0018340210912425492, 'mean_word_length': 1.7206982543640899, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3418809', 'n_tokens_mistral': 664, 'n_tokens_neox': 651, 'n_words': 120}