scripterator 0.1.1 → 1.0.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGUxZGVhNWNmNjNkMDM2YzY0MWQ5MzkzY2Y2Y2ExYWQ2ZTM1YzVkNA==
4
+ Zjc3Yjk1YzdjZTZkODIxYmExYmJmMWFjNDNhYTQ0MzE0ZDBjMTY3Zg==
5
5
  data.tar.gz: !binary |-
6
- Y2FmYzZhNmZmYjY0MWYxZThkYThmZjE0ZThiYTkwOWFkMzM4Yzk1Ng==
6
+ MTBiYjQ5NWE3OWQ5ZGY5Yzg1YTNmNDJjM2EyMzE0ZDVhZGU3YWZhOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTFiYzA3ZGVkNjdkOTc5NmIwN2NmNGQ1ZTAyNDM4YTA0MzgwNDEyMDA4NzYz
10
- YTcxYTFiNTc2MDA3MGQwZWU3MWY4OWY0NWQzNjM3NWRhMTViZDIxYTFmOTU3
11
- M2IyMmZlMGQ1NThmNWFjYTQwNWYwY2Y3MDIyOTkzYzExN2ZiZjk=
9
+ MDkzN2ExOTU4MzRhMDJmNjQxMTYyMWVkY2ZiZjkwMTg3OTBlNWFmYTI2YzJl
10
+ ZTRjNjA3N2ZmM2MzZDNhMDc4MzQxZDkxYzA5MDA3NDU2OGJjZDU4MTQ3OWM4
11
+ MDA2MTk5YTU4YjE1NWJlZDUzNTI0YmZjYzE1M2QxOGQxNmU5MDg=
12
12
  data.tar.gz: !binary |-
13
- Njc0ZmYyMjIwNGU5NTRjYzg3MTg2YTdmMGRmNjE2OGQyNmRhZGUxOTE3NDE2
14
- NzVmNDVhYjhiNzZmOTFjMzFiMGUxOGZhOWUxYjdiNzg5MjEyYzgyYTMyZmFi
15
- YmI0MjY1NDE4NGQ3YmExNmNlNTg3YTAwYjQxMzY3NTg1N2E4ODY=
13
+ YjMzZDI0YjI3ZTVhZmRlY2QzYzUyYjRjOWJhYTUyOTY4YTJhZGU0MzIyODk2
14
+ Yjc0MDU0NTI2ZjNjZjZlNjVkMjAzZDhiNmYxYjNjZWYzYmIzZGMxMTQ1Mzk0
15
+ ZGNlZTlkOTI4NWY2MTNkZjkzNzU0NDA2N2NlZjUyMzcwYTU5MDE=
data/README.md CHANGED
@@ -24,6 +24,7 @@ Works with ActiveRecord 3.* (Rails 4 support coming).
24
24
  ## Usage
25
25
 
26
26
  Create a .rb file with your script code:
27
+
27
28
  ```ruby
28
29
  Scripterator.run "Convert users from legacy auth data" do
29
30
 
@@ -62,6 +63,10 @@ Total rows migrated: 34903 / 34903
62
63
  0 errors
63
64
  ```
64
65
 
66
+ Or, instead of a range, pass in the specific IDs you want to run against:
67
+
68
+ $ ID_LIST=1,2,100,999 bundle exec rails runner my_script.rb >out.txt
69
+
65
70
  Retrieve set information about checked and failed records:
66
71
 
67
72
  ```
@@ -88,6 +93,7 @@ Environment variable options:
88
93
 
89
94
  - `START`: first model ID to scripterate
90
95
  - `END`: last model ID to scripterate
96
+ - `ID_LIST`: comma-delimited list of IDs to scripterate (e.g. "ID_LIST=1,99,440,23")
91
97
  - `REDIS_EXPIRATION`: amount of time (in seconds) before Redis result sets (checked IDs and failed IDs) are expired
92
98
 
93
99
  Either a starting or an ending ID must be provided.
@@ -17,9 +17,10 @@ module Scripterator
17
17
  end
18
18
 
19
19
  def run(options = {})
20
- unless options[:start_id] || options[:end_id]
21
- raise 'You must provide either a start ID or end ID'
20
+ unless (options[:start_id] || options[:end_id]) || options[:id_list]
21
+ raise 'You must provide either a start ID or end ID, or a comma-delimited id list'
22
22
  end
23
+ @id_list = options[:id_list] || []
23
24
  @start_id = options[:start_id] || 1
24
25
  @end_id = options[:end_id]
25
26
  @redis_expiration = options[:redis_expiration]
@@ -27,6 +28,7 @@ module Scripterator
27
28
 
28
29
  raise 'No per_record code defined' unless @per_record
29
30
 
31
+ output_init_details
30
32
  init_vars
31
33
  run_blocks
32
34
  output_stats
@@ -79,6 +81,11 @@ module Scripterator
79
81
  end
80
82
  end
81
83
 
84
+ def output_init_details
85
+ output "Checked IDs being stored in redis list: #{script_key(:checked)}"
86
+ output "Failed IDs being stored in redis list: #{script_key(:failed)}"
87
+ end
88
+
82
89
  def output(*args)
83
90
  @output_stream.puts(*args)
84
91
  end
@@ -95,8 +102,11 @@ module Scripterator
95
102
  end
96
103
 
97
104
  def run_loop
98
- if @end_id
99
- (@start_id..@end_id).each { |id| transform_one_record(fetch_record(id)) }
105
+ if @id_list.count > 0
106
+ run_for_id_list
107
+ elsif @end_id
108
+ @id_list = (@start_id..@end_id)
109
+ run_for_id_list
100
110
  else
101
111
  model_finder.find_each(start: @start_id) { |record| transform_one_record(record) }
102
112
  end
@@ -104,6 +114,10 @@ module Scripterator
104
114
  expire_redis_sets
105
115
  end
106
116
 
117
+ def run_for_id_list
118
+ @id_list.each { |id| transform_one_record(fetch_record(id)) }
119
+ end
120
+
107
121
  def transform_one_record(record)
108
122
  return if record.nil?
109
123
 
@@ -1,3 +1,3 @@
1
1
  module Scripterator
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/scripterator.rb CHANGED
@@ -18,6 +18,7 @@ module Scripterator
18
18
  options = {}.tap do |o|
19
19
  o[:start_id] = ENV['START'].try(:to_i)
20
20
  o[:end_id] = ENV['END'].try(:to_i)
21
+ o[:id_list] = ENV['ID_LIST'].try(:split, ',')
21
22
  o[:redis_expiration] = ENV['REDIS_EXPIRATION'].try(:to_i) || config.redis_expiration
22
23
  end
23
24
 
data/scripterator.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
  require File.expand_path('../lib/scripterator/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Ted Dumitrescu"]
6
- gem.email = ["ted@lumoslabs.com"]
5
+ gem.authors = ["Ted Dumitrescu", "Carl Furrow"]
6
+ gem.email = ["ted@lumoslabs.com", "carl@lumoslabs.com"]
7
7
  gem.description = %q{Script iterator for ActiveRecord models}
8
8
  gem.summary = %q{DSL for running operations on each of a set of models}
9
9
  gem.homepage = "http://lumosity.com"
data/spec/runner_spec.rb CHANGED
@@ -49,6 +49,20 @@ describe Scripterator::Runner do
49
49
  it_behaves_like 'raises an error'
50
50
  end
51
51
 
52
+ context 'when an id list is passed' do
53
+ before { num_widgets.times { Widget.create! } }
54
+
55
+ let(:num_widgets) { 3 }
56
+ let(:options) { { id_list: Widget.all.map(&:id) } }
57
+
58
+ it 'transforms each widget in the list' do
59
+ options[:id_list].each do |id|
60
+ runner.should_receive(:fetch_record).once.with(id)
61
+ end
62
+ subject
63
+ end
64
+ end
65
+
52
66
  context 'when no per-record block is defined' do
53
67
  let(:awesome_script) do
54
68
  Proc.new do
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scripterator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ted Dumitrescu
8
+ - Carl Furrow
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-09-25 00:00:00.000000000 Z
12
+ date: 2014-03-19 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activerecord
@@ -83,6 +84,7 @@ dependencies:
83
84
  description: Script iterator for ActiveRecord models
84
85
  email:
85
86
  - ted@lumoslabs.com
87
+ - carl@lumoslabs.com
86
88
  executables: []
87
89
  extensions: []
88
90
  extra_rdoc_files: []
@@ -121,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  version: '0'
122
124
  requirements: []
123
125
  rubyforge_project:
124
- rubygems_version: 2.1.4
126
+ rubygems_version: 2.2.2
125
127
  signing_key:
126
128
  specification_version: 4
127
129
  summary: DSL for running operations on each of a set of models