tartarus-rb 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changelog.md +5 -0
- data/Gemfile.lock +21 -3
- data/README.md +12 -0
- data/lib/tartarus.rb +3 -0
- data/lib/tartarus/archivable_collection_repository.rb +1 -1
- data/lib/tartarus/archive_strategy.rb +4 -0
- data/lib/tartarus/archive_strategy/delete_all.rb +3 -1
- data/lib/tartarus/archive_strategy/delete_all_without_batches.rb +9 -0
- data/lib/tartarus/archive_strategy/destroy_all.rb +3 -1
- data/lib/tartarus/archive_strategy/destroy_all_without_batches.rb +9 -0
- data/lib/tartarus/archive_strategy/extract_batch.rb +28 -0
- data/lib/tartarus/rb/version.rb +1 -1
- data/lib/tartarus/schedule_archiving_model.rb +1 -3
- data/tartarus-rb.gemspec +3 -0
- metadata +34 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffb5cafa941ec43d2c07a6745ef9b75b91c31784649bbf04187e90f6960812e0
|
4
|
+
data.tar.gz: 9615766c2064a4e127c836ca4cf6ad9b0f2925d08246e4486b9f9fd382884e4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a97481429cc2c5faa977d75baae80c78e17f56cfa0323b76e613a91a57586bbfb6890442e340b7d9aff88eb7a155f694174109a92317d77e7b8c4c367224ae50
|
7
|
+
data.tar.gz: 143dc43864c453873d6154f52d1504eff11f0f88e406e69893fd62937ea8b59899e4c1fdd344adc65fab4e4d6f15c8dcee4cd5c09c14e86a19d47be2e17d403d
|
data/.gitignore
CHANGED
data/Changelog.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,21 +1,35 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tartarus-rb (0.
|
4
|
+
tartarus-rb (0.2.0)
|
5
5
|
sidekiq (>= 5)
|
6
6
|
sidekiq-cron (~> 1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
activemodel (6.1.0.rc1)
|
12
|
+
activesupport (= 6.1.0.rc1)
|
13
|
+
activerecord (6.1.0.rc1)
|
14
|
+
activemodel (= 6.1.0.rc1)
|
15
|
+
activesupport (= 6.1.0.rc1)
|
16
|
+
activesupport (6.1.0.rc1)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 1.6, < 2)
|
19
|
+
minitest (>= 5.1)
|
20
|
+
tzinfo (~> 2.0)
|
21
|
+
zeitwerk (~> 2.3)
|
11
22
|
concurrent-ruby (1.1.7)
|
12
23
|
connection_pool (2.2.3)
|
13
24
|
diff-lcs (1.4.4)
|
14
25
|
et-orbi (1.2.4)
|
15
26
|
tzinfo
|
16
|
-
fugit (1.
|
27
|
+
fugit (1.4.0)
|
17
28
|
et-orbi (~> 1.1, >= 1.1.8)
|
18
|
-
raabro (~> 1.
|
29
|
+
raabro (~> 1.4)
|
30
|
+
i18n (1.8.5)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
minitest (5.14.2)
|
19
33
|
raabro (1.4.0)
|
20
34
|
rack (2.2.3)
|
21
35
|
rake (13.0.1)
|
@@ -43,16 +57,20 @@ GEM
|
|
43
57
|
sidekiq-cron (1.2.0)
|
44
58
|
fugit (~> 1.1)
|
45
59
|
sidekiq (>= 4.2.1)
|
60
|
+
sqlite3 (1.4.2)
|
46
61
|
tzinfo (2.0.2)
|
47
62
|
concurrent-ruby (~> 1.0)
|
63
|
+
zeitwerk (2.4.1)
|
48
64
|
|
49
65
|
PLATFORMS
|
50
66
|
ruby
|
51
67
|
|
52
68
|
DEPENDENCIES
|
69
|
+
activerecord (~> 6)
|
53
70
|
rake (~> 13.0)
|
54
71
|
rspec (~> 3.0)
|
55
72
|
rspec-sidekiq
|
73
|
+
sqlite3
|
56
74
|
tartarus-rb!
|
57
75
|
|
58
76
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -43,6 +43,7 @@ if File.exist?(schedule_file) && Sidekiq.server?
|
|
43
43
|
item.tenant_id_field = :account_uuid
|
44
44
|
item.archive_items_older_than = -> { 30.days.ago }
|
45
45
|
item.timestamp_field = :created_at
|
46
|
+
item.archive_with = :destroy_all
|
46
47
|
end
|
47
48
|
|
48
49
|
tartarus.register do |item|
|
@@ -77,6 +78,17 @@ You can use the following config params:
|
|
77
78
|
- `tenant_id_field` - required when using tenant_value_source/tenant_value_source. It's a DB column that will be used for scoping records by a tenant. For example, here it would be: `ModelThatYouWantToArchive.where(account_uuid: value_of_uuid_from_some_active_account)`
|
78
79
|
- `archive_items_older_than` - required, for defining retention policy
|
79
80
|
- `timestamp_field` - required, used for performing a query using the value from `archive_items_older_than`
|
81
|
+
- `archive_with` - optional (defaults to `delete_all`). Could be `delete_all`, `destroy_all`, `delete_all_without_batches`, `destroy_all_without_batches`
|
82
|
+
|
83
|
+
### Testing before actually using it
|
84
|
+
|
85
|
+
You might want to verify that the gem works in the way you expect it to work. For that, you will be mostly interested in 2 usecases:
|
86
|
+
|
87
|
+
1. scheduling/enqueueing: use `Tartarus::ScheduleArchivingModel#schedule` - for example, `Tartarus::ScheduleArchivingModel.new.schedule("PaperTrailVersion")`, it's going to enqueue either `Tartarus::Sidekiq::ArchiveModelWithTenantJob` or `Tartarus::Sidekiq::ArchiveModelWithoutTenantJob`, depending on the config.
|
88
|
+
2. execution of the archiving logic: use `Tartarus::ArchiveModelWithTenant#archive` (for example, `Tartarus::ArchiveModelWithTenant.new.archive("PaperTrailVersion", "User")`) or `Tartarus::ArchiveModelWithoutTenant#archive` (for example, `Tartarus::ArchiveModelWithoutTenant.new.archive("PaperTrailVersion")`)
|
89
|
+
|
90
|
+
|
91
|
+
You might also want to check `spec/integration` to get an idea how the integration tests were written.
|
80
92
|
|
81
93
|
## Development
|
82
94
|
|
data/lib/tartarus.rb
CHANGED
@@ -3,7 +3,10 @@ require "tartarus/archivable_item"
|
|
3
3
|
require "tartarus/archivable_item/sidekiq_cron_job_serializer"
|
4
4
|
require "tartarus/archive_strategy"
|
5
5
|
require "tartarus/archive_strategy/delete_all"
|
6
|
+
require "tartarus/archive_strategy/delete_all_without_batches"
|
6
7
|
require "tartarus/archive_strategy/destroy_all"
|
8
|
+
require "tartarus/archive_strategy/destroy_all_without_batches"
|
9
|
+
require "tartarus/archive_strategy/extract_batch"
|
7
10
|
require "tartarus/sidekiq"
|
8
11
|
require "tartarus/sidekiq/archive_model_with_tenant_job"
|
9
12
|
require "tartarus/sidekiq/archive_model_without_tenant_job"
|
@@ -5,6 +5,10 @@ class Tartarus::ArchiveStrategy
|
|
5
5
|
Tartarus::ArchiveStrategy::DeleteAll.new
|
6
6
|
when :destroy_all
|
7
7
|
Tartarus::ArchiveStrategy::DestroyAll.new
|
8
|
+
when :delete_all_without_batches
|
9
|
+
Tartarus::ArchiveStrategy::DeleteAllWithoutBatches.new
|
10
|
+
when :destroy_all_without_batches
|
11
|
+
Tartarus::ArchiveStrategy::DestroyAllWithoutBatches.new
|
8
12
|
else
|
9
13
|
raise "unknown strategy: #{strategy_name}"
|
10
14
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Tartarus
|
2
|
+
class ArchiveStrategy
|
3
|
+
class ExtractBatch
|
4
|
+
attr_reader :config
|
5
|
+
private :config
|
6
|
+
|
7
|
+
def initialize(config: Thread.current)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(collection)
|
12
|
+
if collection.respond_to?(:in_batches) && !suppressed_in_batches?
|
13
|
+
yield collection.in_batches
|
14
|
+
else
|
15
|
+
primary_key = collection.primary_key
|
16
|
+
|
17
|
+
collection.select(primary_key).find_in_batches do |group|
|
18
|
+
yield collection.where(primary_key => group)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def suppressed_in_batches?
|
24
|
+
!!config["__TARTARUS__SUPPRESSED_IN_BATCHES"]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/tartarus/rb/version.rb
CHANGED
@@ -24,9 +24,7 @@ class Tartarus::ScheduleArchivingModel
|
|
24
24
|
collection = archivable_item.tenants_range.call
|
25
25
|
|
26
26
|
if collection.respond_to?(:find_each)
|
27
|
-
archivable_item.
|
28
|
-
.call
|
29
|
-
.find_each { |element| yield element.public_send(archivable_item.tenant_value_source) }
|
27
|
+
collection.find_each { |element| yield element.public_send(archivable_item.tenant_value_source) }
|
30
28
|
else
|
31
29
|
collection.each { |element| yield element }
|
32
30
|
end
|
data/tartarus-rb.gemspec
CHANGED
@@ -33,4 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency "rake", "~> 13.0"
|
34
34
|
spec.add_development_dependency "rspec", "~> 3.0"
|
35
35
|
spec.add_development_dependency "rspec-sidekiq"
|
36
|
+
|
37
|
+
spec.add_development_dependency "activerecord", "~> 6"
|
38
|
+
spec.add_development_dependency "sqlite3"
|
36
39
|
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
|
+
version: 0.2.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: 2020-
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: A gem for archving (deleting) old records you no longer need. Send them
|
84
112
|
straight to tartarus!
|
85
113
|
email:
|
@@ -108,7 +136,10 @@ files:
|
|
108
136
|
- lib/tartarus/archive_model_without_tenant.rb
|
109
137
|
- lib/tartarus/archive_strategy.rb
|
110
138
|
- lib/tartarus/archive_strategy/delete_all.rb
|
139
|
+
- lib/tartarus/archive_strategy/delete_all_without_batches.rb
|
111
140
|
- lib/tartarus/archive_strategy/destroy_all.rb
|
141
|
+
- lib/tartarus/archive_strategy/destroy_all_without_batches.rb
|
142
|
+
- lib/tartarus/archive_strategy/extract_batch.rb
|
112
143
|
- lib/tartarus/rb.rb
|
113
144
|
- lib/tartarus/rb/version.rb
|
114
145
|
- lib/tartarus/registry.rb
|
@@ -139,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
170
|
- !ruby/object:Gem::Version
|
140
171
|
version: '0'
|
141
172
|
requirements: []
|
142
|
-
rubygems_version: 3.1.
|
173
|
+
rubygems_version: 3.1.2
|
143
174
|
signing_key:
|
144
175
|
specification_version: 4
|
145
176
|
summary: A gem for archving (deleting) old records you no longer need. Send them straight
|