elastic_ar_sync 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53be1f275059f78080af2ed902fbbf5d10af6fcf62b31b189fe22294b9623742
4
- data.tar.gz: ef20e4a2d9ee446e9ea741b6758c4609a3f4f015ec0e5815435fa706b9cc2beb
3
+ metadata.gz: bce44a711b1391e382ac02278af2203b1a0cc304f161c6d3f1c6b68f2a3c24b2
4
+ data.tar.gz: 1f356f4086089f0a7edff3b9355fc35a31a89ad3bc98e01080939c62cca18618
5
5
  SHA512:
6
- metadata.gz: 90c15465ed3b20a2055e10cf09c1d6719c5d6c21d7ae070f373e5afbe04f1053fc0d4eda106a905b9d21ae80a7a19e4f2bae1d5d40453abb523f3f8e964bf7c1
7
- data.tar.gz: 814e9fb8c93ab4532d546d61f1063f134b4448154be246089cdf45291f0108ac4c1485a3a7853be38f3bde1265c3b7eb65ad3d81028b479c3a7bc536f3f7506e
6
+ metadata.gz: 92a604d4d3e7fcdf6645317c8dbfb4dc2633b5994c8523c2ab66eb773dfc5cca4dee3a82d1d5339208d947a05a6e17a6582d52f1985038dfebb371cf1edbe900
7
+ data.tar.gz: 4fd9baff81fd0707100e12a9c8d56048d788e4cea1e1b9b9cdb2cc80020fc1b1eb1dac39e4b78549bcd646deb60b9412a8843f05b3d0f107ca9cc2e141f45f10
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # ElasticArSync
2
2
  This repository contains easy set up modules for RDB and elasticsearch index with Active Record.
3
3
  This is based on `gem elasticsearch-rails`.
4
+
5
+ 日本語での説明はこちら
6
+ https://ted-tech.hateblo.jp/entry/2020/08/11/103155
7
+
4
8
  ## Usage
5
9
  ### Preparation
6
10
  Install `gem sidekiq` and `gem redis-rails` to use Asynchronous processing for your app.
@@ -13,27 +13,27 @@ module ElasticArSync
13
13
  # after_commitでRDBを操作した時にESのインデックスも同期させる
14
14
  # アプリのサーバーに負荷をかけ無いように非同期で実行させる
15
15
  after_commit on: [:create] do
16
- document_sync_create(self.class, id)
16
+ document_sync_create(self.class.to_s, id)
17
17
  end
18
18
 
19
19
  after_commit on: [:update] do
20
- document_sync_update(self.class, id)
20
+ document_sync_update(self.class.to_s, id)
21
21
  end
22
22
 
23
23
  after_commit on: [:destroy] do
24
- document_sync_delete(self.class, id)
24
+ document_sync_delete(self.class.to_s, id)
25
25
  end
26
26
 
27
- def document_sync_create(klass, record_id)
28
- ElasticArSync::Elastic::Worker::IndexWorker.perform_async(klass, :index, record_id)
27
+ def document_sync_create(klass_str, record_id)
28
+ ElasticArSync::Elastic::Worker::IndexWorker.perform_async(klass_str, :index, record_id)
29
29
  end
30
30
 
31
- def document_sync_update(klass, record_id)
32
- ElasticArSync::Elastic::Worker::IndexWorker.perform_async(klass, :index, record_id)
31
+ def document_sync_update(klass_str, record_id)
32
+ ElasticArSync::Elastic::Worker::IndexWorker.perform_async(klass_str, :index, record_id)
33
33
  end
34
34
 
35
- def document_sync_delete(klass, record_id)
36
- ElasticArSync::Elastic::Worker::IndexWorker.perform_async(klass, :delete, record_id)
35
+ def document_sync_delete(klass_str, record_id)
36
+ ElasticArSync::Elastic::Worker::IndexWorker.perform_async(klass_str, :delete, record_id)
37
37
  end
38
38
 
39
39
  def as_indexed_json(_option = {})
@@ -60,7 +60,7 @@ module ElasticArSync
60
60
 
61
61
  # DBの内容をESのインデックスに同期する
62
62
  def import_all_record(target_index: ,batch_size: 100)
63
- ElasticArSync::Elastic::Worker::IndexImportWorker.perform_async(self, target_index, batch_size)
63
+ ElasticArSync::Elastic::Worker::IndexImportWorker.perform_async(self.to_s, target_index, batch_size)
64
64
  end
65
65
 
66
66
  # ダウンタイムなしでインデックスを切り替える
@@ -2,11 +2,11 @@ class ElasticArSync::Elastic::Worker::IndexImportWorker
2
2
  include Sidekiq::Worker
3
3
  sidekiq_options queue: :elasticsearch, retry: false
4
4
 
5
- def perform(klass, target_index, batch_size)
5
+ def perform(klass_str, target_index, batch_size)
6
6
  Rails.logger.debug "[elastic IndexImportWorker] start import #{target_index}"
7
7
 
8
8
  begin
9
- ElasticArSync::Elastic::Services::IndexHandler.new(Object.const_get(klass)).import_all_record(target_index, batch_size)
9
+ ElasticArSync::Elastic::Services::IndexHandler.new(Object.const_get(klass_str)).import_all_record(target_index, batch_size)
10
10
  rescue => e
11
11
  Rails.logger.debug "[elastic IndexImportWorker] error occur #{target_index} \n #{e.message}"
12
12
  end
@@ -2,8 +2,8 @@ class ElasticArSync::Elastic::Worker::IndexWorker
2
2
  include Sidekiq::Worker
3
3
  sidekiq_options queue: :elasticsearch, retry: false
4
4
 
5
- def perform(klass, operation, record_id)
6
- Rails.logger.debug "[elasticsearch IndexWorker] operation: #{operation} #{klass} ID: #{record_id}"
7
- ElasticArSync::Elastic::Services::DocumentIndexer.new.index_document(klass, operation, record_id)
5
+ def perform(klass_str, operation, record_id)
6
+ Rails.logger.debug "[elasticsearch IndexWorker] operation: #{operation} #{klass_str} ID: #{record_id}"
7
+ ElasticArSync::Elastic::Services::DocumentIndexer.new.index_document(klass_str.constantize, operation, record_id)
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module ElasticArSync
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic_ar_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - KitakatsuTed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-14 00:00:00.000000000 Z
11
+ date: 2022-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails