hekenga 0.2.13 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ module Hekenga
2
+ class TaskSplitter
3
+ attr_reader :record, :executor_key
4
+
5
+ def initialize(record, executor_key)
6
+ @record = record
7
+ @executor_key = executor_key
8
+ end
9
+
10
+ def call
11
+ return if record.failed_ids.blank? && record.invalid_ids.blank?
12
+
13
+ Hekenga::DocumentTaskRecord.new.tap do |new_record|
14
+ new_record.migration_key = record.migration_key
15
+ new_record.task_idx = record.task_idx
16
+ new_record.executor_key = executor_key
17
+ new_record.ids = record.failed_ids | record.invalid_ids
18
+ new_record.save!
19
+
20
+ record.ids -= new_record.ids
21
+ record.failed_ids = []
22
+ record.invalid_ids = []
23
+ record.id_count = record.ids.count
24
+ record.stats = record.stats.merge('failed' => 0, 'invalid' => 0)
25
+ record.save!
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -1,3 +1,3 @@
1
1
  module Hekenga
2
- VERSION = "0.2.13"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/hekenga.rb CHANGED
@@ -8,39 +8,50 @@ require "hekenga/virtual_method"
8
8
  require "hekenga/scaffold"
9
9
 
10
10
  module Hekenga
11
+ @@load_all_mutex = Mutex.new
12
+ @@registry_mutex = Mutex.new
13
+ @@registry = []
14
+
11
15
  class << self
12
16
  def configure
13
17
  yield(config)
14
18
  end
19
+
15
20
  def config
16
21
  @config ||= Hekenga::Config.new
17
22
  end
23
+
18
24
  def load_all!
19
25
  return if @loaded
20
- Dir.glob(File.join(config.abs_dir, "*.rb")).each do |path|
21
- require path
22
- end.tap { @loaded = true }
26
+
27
+ @@load_all_mutex.synchronize do
28
+ Dir.glob(File.join(config.abs_dir, "*.rb")).each do |path|
29
+ require path
30
+ end
31
+
32
+ @loaded = true
33
+ end
23
34
  end
35
+
24
36
  def migration(&block)
25
37
  Hekenga::DSL::Migration.new(&block).object.tap do |obj|
26
- self.registry.push(obj)
38
+ @@registry_mutex.synchronize { registry.push(obj) }
27
39
  end
28
40
  end
41
+
29
42
  def find_migration(key)
30
43
  load_all!
31
44
  registry.detect do |migration|
32
45
  migration.to_key == key
33
46
  end
34
47
  end
48
+
35
49
  def registry
36
- @registry || reset_registry
37
- end
38
- def reset_registry
39
- @registry = []
50
+ @@registry
40
51
  end
41
52
 
42
- def any_fatal?
43
- Hekenga::Log.where(cancel: true, skip: false).any?
53
+ def reset_registry
54
+ @@registry_mutex.synchronize { @@registry = [] }
44
55
  end
45
56
 
46
57
  def status(migration)
@@ -53,6 +64,7 @@ module Hekenga
53
64
  return :complete if logs.all? {|x| x.done} && logs.length == migration.tasks.length
54
65
  return :running
55
66
  end
67
+
56
68
  def log(str)
57
69
  print str.to_s+"\n"
58
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hekenga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tapio Saarinen
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.10
19
+ version: 2.4.6
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.10
26
+ version: 2.4.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: database_cleaner
56
+ name: database_cleaner-mongoid
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '5'
103
+ version: '6'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '5'
110
+ version: '6'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: activejob
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '4'
117
+ version: '5'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '4'
124
+ version: '5'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: thor
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -147,11 +147,13 @@ files:
147
147
  - ".gitignore"
148
148
  - ".rspec"
149
149
  - ".travis.yml"
150
+ - CHANGELOG.md
150
151
  - Gemfile
151
152
  - README.md
152
153
  - Rakefile
153
154
  - bin/console
154
155
  - bin/setup
156
+ - docker-compose.yml
155
157
  - examples/simple_example.rb
156
158
  - exe/hekenga
157
159
  - hekenga.gemspec
@@ -160,6 +162,8 @@ files:
160
162
  - lib/hekenga/config.rb
161
163
  - lib/hekenga/context.rb
162
164
  - lib/hekenga/document_task.rb
165
+ - lib/hekenga/document_task_executor.rb
166
+ - lib/hekenga/document_task_record.rb
163
167
  - lib/hekenga/dsl.rb
164
168
  - lib/hekenga/dsl/document_task.rb
165
169
  - lib/hekenga/dsl/migration.rb
@@ -171,16 +175,21 @@ files:
171
175
  - lib/hekenga/failure/write.rb
172
176
  - lib/hekenga/invalid.rb
173
177
  - lib/hekenga/irreversible.rb
178
+ - lib/hekenga/iterator.rb
174
179
  - lib/hekenga/log.rb
175
180
  - lib/hekenga/master_process.rb
176
181
  - lib/hekenga/migration.rb
177
182
  - lib/hekenga/parallel_job.rb
183
+ - lib/hekenga/parallel_task.rb
178
184
  - lib/hekenga/scaffold.rb
179
185
  - lib/hekenga/simple_task.rb
186
+ - lib/hekenga/task_failed_error.rb
187
+ - lib/hekenga/task_splitter.rb
180
188
  - lib/hekenga/version.rb
181
189
  - lib/hekenga/virtual_method.rb
182
190
  homepage: https://github.com/tzar/hekenga
183
- licenses: []
191
+ licenses:
192
+ - MIT
184
193
  metadata: {}
185
194
  post_install_message:
186
195
  rdoc_options: []