tartarus-rb 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a9a2ee5b7e8889bc07acdb01d4bf1fad93cf412fe3a0109cb63ab547ccb1255
4
- data.tar.gz: 4a4f1ede48123fa774e7ccbd55d1eadd19476292558f73ed09b1dee0234c2e4b
3
+ metadata.gz: f7669ce816882e4f9607e41afde316cbe50027291a0dd89008d3baaa9ca6b308
4
+ data.tar.gz: d03d89b04491a2dce92820674e94c895cac9cad706b790927aab9129f8c15b26
5
5
  SHA512:
6
- metadata.gz: d59b03b2a163d831bee9766892fe59c3a19c6b771f297bbbf564d30f5c007bd94f2e96357f0ec6b30d602572b8d4de636c3124eebcba2b46f86ffabc69d545dc
7
- data.tar.gz: 24a9efa3d116ed97a6113e855457a7f13ac41d8ea6669010794b973615c425ce6b1aef5fbfc327e76156b909cb52035747fe28cdc70ed4d817431a2bf34a4563
6
+ metadata.gz: e3906591489650a6e4f9ce9f3b0eaa17ab2a95797096abcf8bba9f50855a7463f0a2f1354017f3df512519775765e807ece44b4c75cbc2b3b3bd326f67a6ffcf
7
+ data.tar.gz: 48d503bc4bbea2be0196778d5dca18b9d9770cf069685128860f4567fdc1727f46042e009b43a86dc9697b217c8a6b5816a45eae1ed935f362ce63b42c2301e2
data/Changelog.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 0.5.0
6
+
7
+ - Provide ability to explicitly set the name of archivable item to have multiple ways of archiving the same model
8
+
5
9
  ## 0.4.1
6
10
 
7
11
  - Do not make Glacier a required dependency if not used
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tartarus-rb (0.4.1)
4
+ tartarus-rb (0.5.0)
5
5
  sidekiq (>= 5)
6
6
  sidekiq-cron (~> 1)
7
7
 
@@ -57,7 +57,7 @@ GEM
57
57
  erubi (1.10.0)
58
58
  et-orbi (1.2.4)
59
59
  tzinfo
60
- fugit (1.4.2)
60
+ fugit (1.4.5)
61
61
  et-orbi (~> 1.1, >= 1.1.8)
62
62
  raabro (~> 1.4)
63
63
  hashdiff (1.0.0)
data/README.md CHANGED
@@ -82,6 +82,31 @@ end
82
82
 
83
83
  You can use the following config params:
84
84
  - `model` - a name of the ActiveReord model you want to archive, required
85
+ - `name` - name of your strategy, optional. It fallbacks `model.to_s`. It's important to set in in cases when you have several strategies for the same model:
86
+ ```rb
87
+ tartarus.register do |item|
88
+ item.model = InternalEvent
89
+ item.name = "archive_account_and_user_internal_events"
90
+ item.cron = "5 5 * * *"
91
+ item.queue = "default"
92
+ item.tenants_range = -> { ["Account", "User"] }
93
+ item.tenant_id_field = :model_type
94
+ item.archive_items_older_than = -> { 30.days.ago }
95
+ item.timestamp_field = :created_at
96
+ end
97
+
98
+ tartarus.register do |item|
99
+ item.model = InternalEvent
100
+ item.name = "archive_post_and_comment_internal_events"
101
+ item.cron = "5 15 * * *"
102
+ item.queue = "default"
103
+ item.tenants_range = -> { ["Post", "Comment"] }
104
+ item.tenant_id_field = :model_type
105
+ item.archive_items_older_than = -> { 10.days.ago }
106
+ item.timestamp_field = :created_at
107
+ end
108
+ ```
109
+
85
110
  - `cron` - cron syntax, required
86
111
  - `queue` - name of the sidekiq queue you want to use for execution of the jobs, required
87
112
  - `tenants_range` - optional, use if you want to scope items by a tenant (or any field that can be used for partitioning). It doesn't have to be ActiveRecord collection, could be just an array. Must be a proc/lambda/object responding to `call` method. For ActvieRecord collection, `find_each` loop will be used for optimization.
@@ -91,7 +116,7 @@ You can use the following config params:
91
116
  - `timestamp_field` - required, used for performing a query using the value from `archive_items_older_than`
92
117
  - `archive_with` - optional (defaults to `delete_all`). Could be `delete_all`, `destroy_all`, `delete_all_without_batches`, `destroy_all_without_batches`, `delete_all_using_limit_in_batches`
93
118
  - `batch_size` - optional (defaults to `10_000`, used with `delete_all_using_limit_in_batches` strategy)
94
- - `remote_storage` - optional (defaults to `Tartarus::RemoteStorage::Null` which does nothing). Use this option if you want store the data somewhere before deleting it.
119
+ - `remote_storage` - optional (defaults to `Tartarus::RemoteStorage::Null` which does nothing). Use this option if you want store the data somewhere before deleting it.
95
120
 
96
121
  ### Remote Storage
97
122
 
@@ -171,7 +196,7 @@ class Glacier
171
196
  @configuration = configuration
172
197
  end
173
198
 
174
- def store(collection, archivable_model, tenant_id: nil, tenant_id_field: nil)
199
+ def store(collection, archivable_model, tenant_id: nil, tenant_id_field: nil)
175
200
  end
176
201
  end
177
202
  ```
@@ -1,7 +1,7 @@
1
1
  class Tartarus::ArchivableItem
2
2
  REQUIRED_ATTRIBUTES_NAMES = %i(model cron queue archive_items_older_than timestamp_field active_job
3
3
  archive_with tenant_value_source).freeze
4
- OPTIONAL_ATTRIBUTES_NAMES = %i(tenants_range tenant_id_field batch_size remote_storage).freeze
4
+ OPTIONAL_ATTRIBUTES_NAMES = %i(tenants_range tenant_id_field batch_size remote_storage name).freeze
5
5
 
6
6
  attr_accessor *(REQUIRED_ATTRIBUTES_NAMES + OPTIONAL_ATTRIBUTES_NAMES)
7
7
 
@@ -51,6 +51,10 @@ class Tartarus::ArchivableItem
51
51
  @batch_size ||= 10_000
52
52
  end
53
53
 
54
+ def name
55
+ @name || @model.to_s
56
+ end
57
+
54
58
  def validate!
55
59
  validate_presence
56
60
  end
@@ -63,10 +67,6 @@ class Tartarus::ArchivableItem
63
67
  factory.for(archive_with, batch_size: batch_size)
64
68
  end
65
69
 
66
- def for_model?(provided_model_name)
67
- model.to_s == provided_model_name.to_s
68
- end
69
-
70
70
  def remote_storage
71
71
  @remote_storage || Tartarus::RemoteStorage::Null
72
72
  end
@@ -7,7 +7,7 @@ class Tartarus
7
7
  description: description_for_item(archivable_item),
8
8
  cron: archivable_item.cron,
9
9
  class: Tartarus::Sidekiq::ScheduleArchivingModelJob,
10
- args: [archivable_item.model],
10
+ args: [archivable_item.name],
11
11
  queue: archivable_item.queue,
12
12
  active_job: archivable_item.active_job
13
13
  }
@@ -16,7 +16,7 @@ class Tartarus
16
16
  private
17
17
 
18
18
  def name_for_item(archivable_item)
19
- "TARTARUS_#{archivable_item.model}"
19
+ "TARTARUS_#{archivable_item.name}"
20
20
  end
21
21
 
22
22
  def description_for_item(archivable_item)
@@ -7,20 +7,20 @@ class Tartarus::ArchiveModelWithTenant
7
7
  @repository = repository
8
8
  end
9
9
 
10
- def archive(model_name, tenant_id)
11
- archivable_item = registry.find_by_model(model_name)
12
- collection = collection_to_archive(model_name, archivable_item, tenant_id)
13
- archivable_item.remote_storage.store(collection, model_name, tenant_id: tenant_id,
10
+ def archive(archivable_item_name, tenant_id)
11
+ archivable_item = registry.find_by_name(archivable_item_name)
12
+ collection = collection_to_archive(archivable_item, tenant_id)
13
+ archivable_item.remote_storage.store(collection, archivable_item.name, tenant_id: tenant_id,
14
14
  tenant_id_field: archivable_item.tenant_id_field)
15
15
  archivable_item.archive_strategy.call(collection)
16
16
  end
17
17
 
18
18
  private
19
19
 
20
- def collection_to_archive(model_name, archivable_item, tenant_id)
20
+ def collection_to_archive(archivable_item, tenant_id)
21
21
  repository
22
22
  .items_older_than_for_tenant(
23
- model_name,
23
+ archivable_item.model,
24
24
  archivable_item.timestamp_field, archivable_item.archive_items_older_than.call,
25
25
  archivable_item.tenant_id_field, tenant_id
26
26
  )
@@ -7,19 +7,19 @@ class Tartarus::ArchiveModelWithoutTenant
7
7
  @repository = repository
8
8
  end
9
9
 
10
- def archive(model_name)
11
- archivable_item = registry.find_by_model(model_name)
12
- collection = collection_to_archive(model_name, archivable_item)
13
- archivable_item.remote_storage.store(collection, model_name)
10
+ def archive(archivable_item_name)
11
+ archivable_item = registry.find_by_name(archivable_item_name)
12
+ collection = collection_to_archive(archivable_item)
13
+ archivable_item.remote_storage.store(collection, archivable_item.name)
14
14
  archivable_item.archive_strategy.call(collection)
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- def collection_to_archive(model_name, archivable_item)
19
+ def collection_to_archive(archivable_item)
20
20
  repository
21
21
  .items_older_than(
22
- model_name,
22
+ archivable_item.model,
23
23
  archivable_item.timestamp_field, archivable_item.archive_items_older_than.call
24
24
  )
25
25
  end
@@ -1,5 +1,5 @@
1
1
  class Tartarus
2
2
  module Rb
3
- VERSION = "0.4.1"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -16,8 +16,8 @@ class Tartarus::Registry
16
16
  @storage << item
17
17
  end
18
18
 
19
- def find_by_model(model)
20
- storage.find(->{ raise "#{model} not found in registry" }) { |item| item.for_model?(model) }
19
+ def find_by_name(name)
20
+ storage.find(->{ raise "#{name} not found in registry" }) { |item| item.name == name }
21
21
  end
22
22
 
23
23
  def reset
@@ -6,15 +6,15 @@ class Tartarus::ScheduleArchivingModel
6
6
  @registry = registry
7
7
  end
8
8
 
9
- def schedule(model_name)
10
- archivable_item = registry.find_by_model(model_name)
9
+ def schedule(archivable_item_name)
10
+ archivable_item = registry.find_by_name(archivable_item_name)
11
11
 
12
12
  if archivable_item.scope_by_tenant?
13
13
  each_tenant(archivable_item) do |tenant|
14
- enqueue(Tartarus::Sidekiq::ArchiveModelWithTenantJob, archivable_item.queue, model_name, tenant)
14
+ enqueue(Tartarus::Sidekiq::ArchiveModelWithTenantJob, archivable_item.queue, archivable_item.name, tenant)
15
15
  end
16
16
  else
17
- enqueue(Tartarus::Sidekiq::ArchiveModelWithoutTenantJob, archivable_item.queue, model_name)
17
+ enqueue(Tartarus::Sidekiq::ArchiveModelWithoutTenantJob, archivable_item.queue, archivable_item.name)
18
18
  end
19
19
  end
20
20
 
@@ -4,8 +4,8 @@ class Tartarus
4
4
  class Sidekiq::ArchiveModelWithTenantJob
5
5
  include ::Sidekiq::Worker
6
6
 
7
- def perform(model_name, tenant_id)
8
- Tartarus::ArchiveModelWithTenant.new.archive(model_name, tenant_id)
7
+ def perform(archivable_item_name, tenant_id)
8
+ Tartarus::ArchiveModelWithTenant.new.archive(archivable_item_name, tenant_id)
9
9
  end
10
10
  end
11
11
  end
@@ -4,8 +4,8 @@ class Tartarus
4
4
  class Sidekiq::ArchiveModelWithoutTenantJob
5
5
  include ::Sidekiq::Worker
6
6
 
7
- def perform(model_name)
8
- Tartarus::ArchiveModelWithoutTenant.new.archive(model_name)
7
+ def perform(archivable_item_name)
8
+ Tartarus::ArchiveModelWithoutTenant.new.archive(archivable_item_name)
9
9
  end
10
10
  end
11
11
  end
@@ -4,8 +4,8 @@ class Tartarus
4
4
  class Sidekiq::ScheduleArchivingModelJob
5
5
  include ::Sidekiq::Worker
6
6
 
7
- def perform(model_name)
8
- Tartarus::ScheduleArchivingModel.new.schedule(model_name)
7
+ def perform(archivable_item_name)
8
+ Tartarus::ScheduleArchivingModel.new.schedule(archivable_item_name)
9
9
  end
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tartarus-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Galanciak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq