nexus_seed 0.2.8 → 0.2.10

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: 7c30412d463327ee535c5abe6862a2c7079726562cd6bc1dcb359e5e719c242c
4
- data.tar.gz: 1dbed102d6cb21ee5eb8c2958ef844f011303f529413d5e75d11b8ae0cd932e6
3
+ metadata.gz: 61cc46080bca8e537d0290de925e2c4a24ec08251f4613af77233712bfc87368
4
+ data.tar.gz: 7a192d784f4baf6b2e5eee0b553c2c12f12b08f97c81c1f58ef897e01273e648
5
5
  SHA512:
6
- metadata.gz: c3dbcec4ca06afbda2e4f64f1ad6324f99be0a350e43cc25ce83d0db40cc576e1a8861fb92851e2d0cef066335903633d764a672f9141be969b4d4fcdde8316f
7
- data.tar.gz: 5bee9f4dfd6b6634a17af5cbf60d17b38199a30629d16718339dd98843a0c1a3307f643c2475124a9ec2690ff8708ebfd87912cb03b1f4c01743b8b5e6c3b91b
6
+ metadata.gz: faefc536924c2c8341c0722b06b9b5ccdddb11458db2985381a73dcb9596eae90ce787fc31a34aa7145bf0c24a6dd72169c6d07d6a76f65ad922162d6a2b419a
7
+ data.tar.gz: 919c1c15889cb931610e60d677b122df71476b3650f2baa6a65385d9921086b36ace17b0d4b6dd260f2811b1be4b3de9a2506f6231e2d81d377195f96cb7f978
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
+ ```
@@ -6,7 +6,7 @@ module NexusSeed
6
6
 
7
7
  NexusSeed::Builder.seed_report
8
8
 
9
- if ENV['destroy_seeds']
9
+ if ENV['NEXUS_SEED_DESTROY']
10
10
  NexusSeed::Builder.destroy_seeds
11
11
  end
12
12
 
@@ -5,14 +5,17 @@ module NexusSeed
5
5
  @counts = {}
6
6
  @start = Time.now
7
7
  @seeds = []
8
- @logger = Logger.new(STDOUT)
8
+
9
+ def self.logger
10
+ @logger ||= SemanticLogger::Logger.new('NexusSeed::Builder')
11
+ end
9
12
 
10
13
  def self.build_called
11
14
  @build_called
12
15
  end
13
16
 
14
17
  def self.build(class_name, params = {}, options = {})
15
- if ENV['seed_report']
18
+ if ENV['NEXUS_SEED_REPORT']
16
19
  pre_seed_counts unless @build_called
17
20
  end
18
21
 
@@ -21,25 +24,25 @@ module NexusSeed
21
24
  end
22
25
 
23
26
  def self.seed_report
24
- if ENV['seed_report']
27
+ if ENV['NEXUS_SEED_REPORT']
25
28
  total = 0
26
29
 
27
- @logger.info('SEED REPORT:')
30
+ logger.info('SEED REPORT:')
28
31
  NexusSeed::Builders.constants.select do |c|
29
32
  NexusSeed::Builders.const_get(c).is_a?(Class)
30
33
  k = NexusSeed::Builders.const_get(c).new.send(:klass)
31
34
  if @counts[k.name.demodulize] != k.count
32
35
  total += (k.count - @counts[k.name.demodulize])
33
- @logger.info("Generated #{k.count - @counts[k.name.demodulize]} new #{k.name.demodulize}s")
36
+ logger.info("Generated #{k.count - @counts[k.name.demodulize]} new #{k.name.demodulize}s")
34
37
  end
35
38
  end
36
39
 
37
- @logger.info("Generated total of #{total} new seeds.")
40
+ logger.info("Generated total of #{total} new seeds.")
38
41
  else
39
- @logger.info('Seeding completed.')
42
+ logger.info('Seeding completed.')
40
43
  end
41
44
 
42
- @logger.info("Time: #{(Time.now - @start).round(2)}s")
45
+ logger.info("Time: #{(Time.now - @start).round(2)}s")
43
46
  end
44
47
 
45
48
  def self.add_seed(seed)
@@ -53,7 +56,7 @@ module NexusSeed
53
56
  count += 1
54
57
  seed.destroy
55
58
  end
56
- @logger.info("Destroyed #{count} seeds (including dependants). All seeds deleted.")
59
+ logger.info("Destroyed #{count} seeds (including dependants). All seeds deleted.")
57
60
  end
58
61
  end
59
62
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusSeed
3
- # Leave this as 0.2.8 in order for CI process to replace with the tagged version.
4
- VERSION = '0.2.8'
3
+ # Leave this as 0.2.10 in order for CI process to replace with the tagged version.
4
+ VERSION = '0.2.10'
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,6 +26,8 @@ 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
32
  NexusSeed::Base.transaction do
31
33
  seed
@@ -84,7 +86,7 @@ module NexusSeed
84
86
  end
85
87
 
86
88
  def logger
87
- @@logger
89
+ @logger ||= SemanticLogger::Logger.new('NexusSeed')
88
90
  end
89
91
 
90
92
  def task_options(opts = {})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_seed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnathon Harris