nexus_seed 0.2.7 → 0.2.9

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: cc77af89892529f0462010fcb476a944738ffa595b31db3fdd6e5d241697a498
4
- data.tar.gz: b70baa5184488918f26fc50536b8b3206a8ad3fc6a159d41a5e771f302c71773
3
+ metadata.gz: 3d0602fbc47d7d2441dfd389ee099c07c163ad9f9614733b44ade4c694e9de3b
4
+ data.tar.gz: 0eabcd944bafa8a1088e0bdf30d93fb5343f39fbbcb23eab0cef31a04754dfca
5
5
  SHA512:
6
- metadata.gz: 23ba6a3fce2affaa629bae22b0e66acbeab6314ddb71490dd03e8f975a6f86634ae427611b5c7f14945b7c5753ca60fe8d100a05f8d0f9bc57ddf7f920491d3d
7
- data.tar.gz: b55d81c2ccbf01d161d714252cb66d0d2cbca8e3072fcb2b6ef0f9ce52edab001d7fbc5c3f55b06f944dd3f6a741fe95054691afa717001cf1f9091adad3b221
6
+ metadata.gz: df29415b25122e1320693f78e36cf91b799943d5b21b1bea59f5ee23d188d2fd635345f1e8f90f73fef55477a2b951ef4aff955d6dea3a7382ea75bf9f5c706a
7
+ data.tar.gz: d7452164c0c606570e77146fc884450eb955e0bc14ee742f42061f0232e0da00aed365b3779212d54e656698d1736d21717054d6ea4689c20f08054ec6e28f90
data/README.md CHANGED
@@ -1,3 +1,75 @@
1
1
  # nexus_seed
2
2
 
3
3
  Common rails application seeding logic.
4
+
5
+ # Running
6
+
7
+ ## Running tasks on deploy
8
+
9
+ Task files must be placed in `/lib/tasks/seed_#{name}.rake`
10
+
11
+ Set task name in helm values e.g. for a `common` seed task:
12
+
13
+ ```
14
+ helm:
15
+ values:
16
+ rails:
17
+ seedTasks:
18
+ - common
19
+ ```
20
+
21
+ Configure the post deploy hook in `devspace.yaml` and set `COMPONENT` appropriately:
22
+
23
+ ```
24
+ hooks:
25
+ - name: post-deploy-seed-task-hook
26
+ events: [ "after:deploy" ]
27
+ command: |-
28
+ docker run --rm --pull always registry.nexusmods.com/nexus-mods/devops/tools/seed_task_start:stable cat seed_task_start.sh |
29
+ NAMESPACE=${devspace.namespace} COMPONENT=api bash
30
+ ```
31
+
32
+ ## Running tasks manually
33
+
34
+ Run `common` seed task with default options:
35
+
36
+ `bundle exec rake seed_common:run`
37
+
38
+ Options are `[:retry_limit, :sleep_interval]`
39
+
40
+ E.g. to retry 100 times every 3 seconds:
41
+
42
+ `bundle exec rake seed_common:run[100,3]`
43
+
44
+ # Local gem development
45
+
46
+ Steps to run this gem from local sources in one the nexus 'staged build' rails components:
47
+
48
+ ## Copy gem sources to component
49
+
50
+ ```
51
+ cd ~/nexus-api
52
+ cp -r ../nexus_seed .
53
+ ```
54
+
55
+ ## Adjust component Dockerfile to include gem sources
56
+
57
+ Within stage 1, append a COPY after the Gemfile copy:
58
+
59
+ ```
60
+ COPY --chown=nexus:nexus Gemfile* ./
61
+ COPY --chown=nexus:nexus nexus_seed/ ./nexus_seed/
62
+ ```
63
+
64
+ Within stage 2, append a COPY after the bundle copy:
65
+
66
+ ```
67
+ COPY --from=stage1 /usr/local/bundle /usr/local/bundle
68
+ COPY --from=stage1 /app/nexus_seed/ /app/nexus_seed/
69
+ ```
70
+
71
+ ## Adjust Gemfile to use local path
72
+
73
+ ```
74
+ gem 'nexus_seed', :path => "/app/nexus_seed"
75
+ ```
@@ -10,7 +10,7 @@ module NexusSeed
10
10
  NexusSeed::Builder.destroy_seeds
11
11
  end
12
12
 
13
- # Reset table sequences. Apparently rails looses track of a pk sequence if the pk value is inserted manually, e.g
13
+ # Reset table sequences. Apparently rails loses track of a pk sequence if the pk value is inserted manually, e.g
14
14
  # User.new(id: 1).save. When subsequently running User.create(), ActiveRecord should increment the id value to 2
15
15
  # by default, but turns out it will try to insert id: 1 again which will result in an error.
16
16
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusSeed
3
- # Leave this as 0.2.7 in order for CI process to replace with the tagged version.
4
- VERSION = '0.2.7'
3
+ # Leave this as 0.2.9 in order for CI process to replace with the tagged version.
4
+ VERSION = '0.2.9'
5
5
  end
data/lib/nexus_seed.rb CHANGED
@@ -7,10 +7,9 @@ require 'nexus_seed/base'
7
7
 
8
8
  module NexusSeed
9
9
  # defaults
10
- @@retry_limit = 0
10
+ @@retry_limit = 12
11
11
  @@sleep_interval = 5
12
12
  @@retries = 0
13
- @@logger = SemanticLogger::Logger.new('NexusSeed')
14
13
 
15
14
  # override this method with your specific requirement
16
15
  def requires
@@ -18,6 +17,7 @@ module NexusSeed
18
17
  end
19
18
 
20
19
  def run
20
+ logger.info('Run with options:', limit: retry_limit, interval: sleep_interval)
21
21
  logger.measure_info('Total seed run.') do
22
22
  _run_internal
23
23
  end
@@ -26,8 +26,12 @@ module NexusSeed
26
26
  # recursively called until requirement is met or the limit is reached
27
27
  def _run_internal
28
28
  if Rails.env.test? || Rails.env.development?
29
+
30
+ logger.info("Starting run attempt #{retries + 1}")
29
31
  if requires
30
- seed
32
+ NexusSeed::Base.transaction do
33
+ seed
34
+ end
31
35
 
32
36
  elsif retries >= retry_limit && retry_limit != 0
33
37
  # log error stating seeding could not complete and task details
@@ -82,7 +86,7 @@ module NexusSeed
82
86
  end
83
87
 
84
88
  def logger
85
- @@logger
89
+ @logger ||= SemanticLogger::Logger.new('NexusSeed')
86
90
  end
87
91
 
88
92
  def task_options(opts = {})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_seed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnathon Harris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-02 00:00:00.000000000 Z
11
+ date: 2023-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nexus_semantic_logger
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubygems_version: 3.4.7
62
+ rubygems_version: 3.4.8
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: seed usage for nexus