purview 1.0.1 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8379bdb0d5f4798293f48485cb0a6f89808fb0a1
4
- data.tar.gz: 2264aa219ba7d50a60b2797aef55e8a335260928
3
+ metadata.gz: 4075095b0198b4d1a9f104e39cef70a86f678038
4
+ data.tar.gz: 8d87f15b33df6603d107edee2a5206f4579bca30
5
5
  SHA512:
6
- metadata.gz: ce8958f9eb4556c2d3106d015fb8be223d1911e7cb8e6341e0151be5baede61410da4d098c7671579399ddecf7af6c7678b36f4a47f9d1296084738d4ef100ff
7
- data.tar.gz: 5dc9a9313f0db29b31cba3b0700b09b86a819eeb4df70e59dc0eadedfd322de046c748930a9315e6ecedba0ea70d69d52327142de2cde64c732b00255d5ea964
6
+ metadata.gz: fe1283a266267325800140f453efe51da2be244c150a094d5d22c40d8b2e129b9a0192fdd004e44799377ec97625aa7c5621cdf24f0f6e4f46cef58ca216361d
7
+ data.tar.gz: 5f5bd8092e10d1f3f34b39aceb15ab4b4ccf307b0e94dead6a801b1c964818069e7775d5af24251be61670307f27555ae0993fa54c3411142048326ad9fd0d1c
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ Release 1.1.0
2
+ -------------
3
+
4
+ * Change how `starting_timestamp` is configured
5
+ * BUGFIX: Fix/standardize exception class/file names
6
+
1
7
  Release 1.0.1
2
8
  -------------
3
9
 
data/README.md CHANGED
@@ -69,12 +69,6 @@ loader_opts = {
69
69
  }
70
70
  ```
71
71
 
72
- Configure the `starting_timestamp` (this is the min-date to pull and can vary
73
- between `Table(s)`)
74
- ```ruby
75
- starting_timestamp = Time.parse('2012-01-01 00:00:00Z')
76
- ```
77
-
78
72
  Combine all the configuration options and instantiate the `Table`
79
73
  ```ruby
80
74
  table_opts = {
@@ -82,7 +76,6 @@ table_opts = {
82
76
  :loader => loader_opts,
83
77
  :parser => parser_opts,
84
78
  :puller => puller_opts,
85
- :starting_timestamp => starting_timestamp,
86
79
  }
87
80
 
88
81
  table = Purview::Tables::Raw.new(
@@ -126,8 +119,19 @@ rescue Mysql2::Error
126
119
  end
127
120
  ```
128
121
 
129
- Enable the `Table` (in the DB). Once the related schema has been created the
130
- `Table` needs to be enabled in order for to be able to be synchronized.
122
+ Initialize the `Table` (in the DB). This process sets the `max_timestamp_pulled`
123
+ value in the `table_metadata` table and is used by the candidate `Table`
124
+ selection algorithm to determine which `Table` should be synchronized next (the
125
+ least recently synchronized `Table` will be selected). This value is also used
126
+ as the high-water mark for records pulled from its source
127
+ ```ruby
128
+ database.initialize_table(table, timestamp)
129
+ ```
130
+
131
+ Enable the `Table` (in the DB). This process sets the `enabled_at` value in the
132
+ `table_metadata` table and is used by the candidate `Table` selection algorithm
133
+ to determine the pool of `Table(s)` available for synchronization (to remove a
134
+ `Table` from the pool simply execute `disable_table`)
131
135
  ```ruby
132
136
  database.enable_table(table)
133
137
  ```
@@ -67,7 +67,7 @@ module Purview
67
67
  with_new_connection do |connection|
68
68
  rows_affected = \
69
69
  connection.execute(disable_table_sql(table)).rows_affected
70
- raise Purview::Exceptions::TableAlreadyDisabled.new(table) \
70
+ raise Purview::Exceptions::CouldNotDisable.new(table) \
71
71
  if zero?(rows_affected)
72
72
  end
73
73
  table_name
@@ -98,7 +98,20 @@ module Purview
98
98
  with_new_connection do |connection|
99
99
  rows_affected = \
100
100
  connection.execute(enable_table_sql(table, timestamp)).rows_affected
101
- raise Purview::Exceptions::TableAlreadyEnabled.new(table) \
101
+ raise Purview::Exceptions::CouldNotEnable.new(table) \
102
+ if zero?(rows_affected)
103
+ end
104
+ table_name
105
+ end
106
+ end
107
+
108
+ def initialize_table(table, starting_timestamp=Time.now.utc)
109
+ table_name = table_name(table)
110
+ with_context_logging("`initialize_table` for: #{table_name}") do
111
+ with_new_connection do |connection|
112
+ rows_affected = \
113
+ connection.execute(initialize_table_sql(table, starting_timestamp)).rows_affected
114
+ raise Purview::Exceptions::CouldNotInitialize.new(table) \
102
115
  if zero?(rows_affected)
103
116
  end
104
117
  table_name
@@ -111,7 +124,7 @@ module Purview
111
124
  with_new_connection do |connection|
112
125
  rows_affected = \
113
126
  connection.execute(lock_table_sql(table, timestamp)).rows_affected
114
- raise Purview::Exceptions::TableAlreadyLocked.new(table) \
127
+ raise Purview::Exceptions::CouldNotLock.new(table) \
115
128
  if zero?(rows_affected)
116
129
  end
117
130
  table_name
@@ -144,7 +157,7 @@ module Purview
144
157
  with_new_connection do |connection|
145
158
  rows_affected = \
146
159
  connection.execute(unlock_table_sql(table)).rows_affected
147
- raise Purview::Exceptions::TableAlreadyUnlocked.new(table) \
160
+ raise Purview::Exceptions::CouldNotUnlock.new(table) \
148
161
  if zero?(rows_affected)
149
162
  end
150
163
  table_name
@@ -372,7 +385,7 @@ module Purview
372
385
  def get_max_timestamp_pulled_for_table(connection, table)
373
386
  row = connection.execute(get_max_timestamp_pulled_for_table_sql(table)).rows[0]
374
387
  timestamp = row[table_metadata_max_timestamp_pulled_column_name]
375
- timestamp ? Time.parse(timestamp) : table.starting_timestamp
388
+ timestamp ? Time.parse(timestamp) : nil
376
389
  end
377
390
 
378
391
  def get_max_timestamp_pulled_for_table_sql(table)
@@ -386,6 +399,10 @@ module Purview
386
399
  ]
387
400
  end
388
401
 
402
+ def initialize_table_sql(table, starting_timestamp)
403
+ raise %{All "#{Base}(s)" must override the "initialize_table_sql" method}
404
+ end
405
+
389
406
  def limit(column)
390
407
  return nil if limitless_types.include?(column.type)
391
408
  column.limit || limit_map[column.type]
@@ -97,6 +97,17 @@ module Purview
97
97
  ]
98
98
  end
99
99
 
100
+ def initialize_table_sql(table, starting_timestamp)
101
+ 'UPDATE %s SET %s = %s WHERE %s = %s AND %s IS NULL' % [
102
+ table_metadata_table_name,
103
+ table_metadata_max_timestamp_pulled_column_name,
104
+ quoted(starting_timestamp),
105
+ table_metadata_table_name_column_name,
106
+ quoted(table.name),
107
+ table_metadata_max_timestamp_pulled_column_name,
108
+ ]
109
+ end
110
+
100
111
  def get_enabled_at_for_table_sql(table)
101
112
  'SELECT %s FROM %s WHERE %s = %s' % [
102
113
  table_metadata_enabled_at_column_name,
@@ -149,10 +160,11 @@ module Purview
149
160
  end
150
161
 
151
162
  def next_table_sql(timestamp)
152
- 'SELECT %s FROM %s WHERE %s IS NOT NULL AND %s IS NULL ORDER BY %s IS NULL DESC, %s LIMIT 1' % [
163
+ 'SELECT %s FROM %s WHERE %s IS NOT NULL AND %s IS NOT NULL AND %s IS NULL ORDER BY %s IS NULL DESC, %s LIMIT 1' % [
153
164
  table_metadata_table_name_column_name,
154
165
  table_metadata_table_name,
155
166
  table_metadata_enabled_at_column_name,
167
+ table_metadata_max_timestamp_pulled_column_name,
156
168
  table_metadata_locked_at_column_name,
157
169
  table_metadata_last_pulled_at_column_name,
158
170
  table_metadata_last_pulled_at_column_name,
@@ -97,6 +97,17 @@ module Purview
97
97
  ]
98
98
  end
99
99
 
100
+ def initialize_table_sql(table, starting_timestamp)
101
+ 'UPDATE %s SET %s = %s WHERE %s = %s AND %s IS NULL' % [
102
+ table_metadata_table_name,
103
+ table_metadata_max_timestamp_pulled_column_name,
104
+ quoted(starting_timestamp),
105
+ table_metadata_table_name_column_name,
106
+ quoted(table.name),
107
+ table_metadata_max_timestamp_pulled_column_name,
108
+ ]
109
+ end
110
+
100
111
  def get_enabled_at_for_table_sql(table)
101
112
  'SELECT %s FROM %s WHERE %s = %s' % [
102
113
  table_metadata_enabled_at_column_name,
@@ -152,10 +163,11 @@ module Purview
152
163
  end
153
164
 
154
165
  def next_table_sql(timestamp)
155
- 'SELECT %s FROM %s WHERE %s IS NOT NULL AND %s IS NULL ORDER BY %s IS NULL DESC, %s LIMIT 1' % [
166
+ 'SELECT %s FROM %s WHERE %s IS NOT NULL AND %s IS NOT NULL AND %s IS NULL ORDER BY %s IS NULL DESC, %s LIMIT 1' % [
156
167
  table_metadata_table_name_column_name,
157
168
  table_metadata_table_name,
158
169
  table_metadata_enabled_at_column_name,
170
+ table_metadata_max_timestamp_pulled_column_name,
159
171
  table_metadata_locked_at_column_name,
160
172
  table_metadata_last_pulled_at_column_name,
161
173
  table_metadata_last_pulled_at_column_name,
@@ -0,0 +1,9 @@
1
+ module Purview
2
+ module Exceptions
3
+ class CouldNotDisable < BaseTable
4
+ def message
5
+ "Could not disable table: #{table.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Purview
2
+ module Exceptions
3
+ class CouldNotEnable < BaseTable
4
+ def message
5
+ "Could not enable table: #{table.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Purview
2
+ module Exceptions
3
+ class CouldNotInitialize < BaseTable
4
+ def message
5
+ "Could not initialize table: #{table.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Purview
2
+ module Exceptions
3
+ class CouldNotLock < BaseTable
4
+ def message
5
+ "Could not lock table: #{table.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Purview
2
+ module Exceptions
3
+ class CouldNotUnlock < BaseTable
4
+ def message
5
+ "Could not unlock table: #{table.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,9 +1,13 @@
1
1
  require 'purview/exceptions/base'
2
2
  require 'purview/exceptions/base_table'
3
3
 
4
- require 'purview/exceptions/could_not_acquire_lock'
4
+ require 'purview/exceptions/could_not_disable'
5
+ require 'purview/exceptions/could_not_enable'
6
+ require 'purview/exceptions/could_not_initialize'
7
+ require 'purview/exceptions/could_not_lock'
8
+ require 'purview/exceptions/could_not_unlock'
9
+
5
10
  require 'purview/exceptions/database_already_assigned'
6
- require 'purview/exceptions/lock_already_released'
7
11
  require 'purview/exceptions/no_table'
8
12
  require 'purview/exceptions/no_window'
9
13
  require 'purview/exceptions/rows_outside_window'
@@ -56,10 +56,6 @@ module Purview
56
56
  end
57
57
  end
58
58
 
59
- def starting_timestamp
60
- opts[:starting_timestamp]
61
- end
62
-
63
59
  def sync(connection, window)
64
60
  raw_data = puller.pull(window)
65
61
  parser.validate(raw_data)
@@ -1,3 +1,3 @@
1
1
  module Purview
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purview
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan W. Zaleski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,9 +112,12 @@ files:
112
112
  - lib/purview/exceptions.rb
113
113
  - lib/purview/exceptions/base.rb
114
114
  - lib/purview/exceptions/base_table.rb
115
- - lib/purview/exceptions/could_not_acquire_lock.rb
115
+ - lib/purview/exceptions/could_not_disable.rb
116
+ - lib/purview/exceptions/could_not_enable.rb
117
+ - lib/purview/exceptions/could_not_initialize.rb
118
+ - lib/purview/exceptions/could_not_lock.rb
119
+ - lib/purview/exceptions/could_not_unlock.rb
116
120
  - lib/purview/exceptions/database_already_assigned.rb
117
- - lib/purview/exceptions/lock_already_released.rb
118
121
  - lib/purview/exceptions/no_table.rb
119
122
  - lib/purview/exceptions/no_window.rb
120
123
  - lib/purview/exceptions/rows_outside_window.rb
@@ -1,9 +0,0 @@
1
- module Purview
2
- module Exceptions
3
- class CouldNotAcquireLock < BaseTable
4
- def message
5
- "Could not acquire the lock for table: #{table.name}"
6
- end
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Purview
2
- module Exceptions
3
- class LockAlreadyReleased < BaseTable
4
- def message
5
- "Lock already released for table: #{table.name}"
6
- end
7
- end
8
- end
9
- end