nexus_seed 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3fb70231c76e859262ea28255d625d4904b99a2e4fae96da3baeb5f9a2e30f36
4
+ data.tar.gz: 53a9e3507714af99e8e826e11ebf55bae6e8f89ad0d5ba0c3e86a90f08562a76
5
+ SHA512:
6
+ metadata.gz: 877f35fa660e49088ce1686eafc40cdc9d69a543c60910998764aaa6daaa7e58dea0b979c5bd02f7a8cd7fd199cd1d1695f0aa09fcec01f1169b7a6b020cda46
7
+ data.tar.gz: 837e9a61883bb53c460e4b3d57e1e8c0c53ccc547d3f20411b0a92f5608d3ae0eaa6823c4025e838e6ddf6a45b125881c3653213ff384cfe57bb31529700bee7
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .idea/
2
+ .vscode/
3
+ results/
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,36 @@
1
+ image: "ruby:2.7"
2
+
3
+ stages:
4
+ - release
5
+ - test
6
+
7
+ before_script:
8
+ - gem install bundler --no-document
9
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
10
+
11
+ rspec:
12
+ script:
13
+ - bundle exec rspec
14
+
15
+ rubocop:
16
+ script:
17
+ - bundle exec rubocop
18
+
19
+ release:
20
+ stage: release
21
+ rules:
22
+ - if: '$CI_COMMIT_TAG'
23
+ script:
24
+ - mkdir -p ~/.gem
25
+ - cp $RUBYGEMS_CREDENTIALS ~/.gem/credentials
26
+ - chmod 0600 ~/.gem/credentials
27
+ - gem update --system
28
+ - ruby --version
29
+ - gem env version
30
+ - sed -i "s/0.0.0/$CI_COMMIT_TAG/g" lib/nexus_seed/version.rb
31
+ - gem build nexus_seed.gemspec
32
+ - gem push nexus_seed*.gem
33
+ artifacts:
34
+ paths:
35
+ - nexus_seed*.gem
36
+ expire_in: 30 days
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
+
4
+ Style/ClassVars:
5
+ Enabled: false
6
+ Style/ConditionalAssignment:
7
+ Enabled: false
8
+ Style/GlobalVars:
9
+ Enabled: false
10
+ Style/FrozenStringLiteralComment:
11
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ gemspec
5
+
6
+ gem 'rubocop'
7
+ gem 'rubocop-shopify', "~> 1.0.4", require: false
8
+
9
+ gem 'rspec'
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # nexus_seed
2
+
3
+ Common rails application seeding logic.
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ module NexusSeed
3
+ # Leave this as 0.1.0 in order for CI process to replace with the tagged version.
4
+ VERSION = '0.1.0'
5
+ end
data/lib/nexus_seed.rb ADDED
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+ require 'nexus_seed'
3
+
4
+ module NexusSeed
5
+ # defaults
6
+ @@retry_limit = 0
7
+ @@sleep_interval = 5
8
+ @@retries = 0
9
+ @@logger = SemanticLogger::Logger.new('NexusSeed')
10
+
11
+ # override this method with your specific requirement
12
+ def requires
13
+ true
14
+ end
15
+
16
+ def run
17
+ logger.measure_info('Total seed run.') do
18
+ _run_internal
19
+ end
20
+ end
21
+
22
+ # recursively called until requirement is met or the limit is reached
23
+ def _run_internal
24
+ if Rails.env.test? || Rails.env.development?
25
+ if requires
26
+ seed
27
+
28
+ elsif retries >= retry_limit && retry_limit != 0
29
+ # log error stating seeding could not complete and task details
30
+ logger.warn('limit reached')
31
+
32
+ else
33
+ # sleep and increment retries
34
+ sleep(sleep_interval)
35
+ self.retries = retries + 1
36
+
37
+ # log retry attempts
38
+ logger.warn("retrying after #{sleep_interval}s. Retry #{retries} of #{retry_limit}")
39
+
40
+ # call itself
41
+ _run_internal
42
+ end
43
+ else
44
+ logger.error('Will not seed in this rails env.', env: Rails.env)
45
+ end
46
+ rescue => e
47
+ logger.error('Error during seed task.', exception: e)
48
+ end
49
+
50
+ # retry limit
51
+ def retries
52
+ @@retries
53
+ end
54
+
55
+ # sleep interval
56
+ def sleep_interval
57
+ @@sleep_interval
58
+ end
59
+
60
+ # retry limit
61
+ def retry_limit
62
+ @@retry_limit
63
+ end
64
+
65
+ def retry_limit=(limit)
66
+ @@retry_limit = limit
67
+ end
68
+
69
+ def sleep_interval=(seconds)
70
+ # nope
71
+ return if seconds.to_i == 0
72
+
73
+ @@sleep_interval = seconds
74
+ end
75
+
76
+ def retries=(retries)
77
+ @@retries = retries
78
+ end
79
+
80
+ def logger
81
+ @@logger
82
+ end
83
+
84
+ def task_options(opts = {})
85
+ self.retry_limit = opts[:retry_limit].to_i unless opts[:retry_limit].nil?
86
+ self.sleep_interval = opts[:sleep_interval].to_i unless opts[:sleep_interval].nil?
87
+ end
88
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'lib/nexus_seed/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "nexus_seed"
6
+ spec.version = NexusSeed::VERSION
7
+ spec.summary = "seed usage for nexus"
8
+ spec.authors = ["Johnathon Harris"]
9
+ spec.email = "john.harris@nexusmods.com"
10
+ # Specify which files should be added to the gem when it is released.
11
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
12
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
13
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ end
15
+ spec.require_paths = ['lib']
16
+ spec.add_dependency('nexus_semantic_logger', '~> 1.10.0')
17
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
18
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexus_seed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Johnathon Harris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nexus_semantic_logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.10.0
27
+ description:
28
+ email: john.harris@nexusmods.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".gitlab-ci.yml"
35
+ - ".rubocop.yml"
36
+ - Gemfile
37
+ - README.md
38
+ - lib/nexus_seed.rb
39
+ - lib/nexus_seed/version.rb
40
+ - nexus_seed.gemspec
41
+ homepage:
42
+ licenses: []
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.7.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.4.6
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: seed usage for nexus
63
+ test_files: []