Skip to content

Commit

Permalink
Merge branch 'master' into 84_base_objects
Browse files Browse the repository at this point in the history
  • Loading branch information
gburgett committed Oct 31, 2018
2 parents 9b0cd73 + c036a68 commit d9f26b2
Show file tree
Hide file tree
Showing 26 changed files with 430 additions and 363 deletions.
2 changes: 1 addition & 1 deletion wcc-contentful-app/lib/generators/wcc/model_generator.rb
Expand Up @@ -26,7 +26,7 @@ def ensure_migration_tools_installed
package = JSON.parse(File.read('package.json'))
deps = package['dependencies']

unless deps.try(:[], 'contentful-migration').present?
unless deps.try(:[], '@watermarkchurch/contentful-migration').present?
run 'npm install --save @watermarkchurch/contentful-migration ts-node ' \
'typescript contentful-export'
end
Expand Down
1 change: 0 additions & 1 deletion wcc-contentful-app/spec/spec_helper.rb
Expand Up @@ -51,5 +51,4 @@

HttpLog.configure do |config|
config.compact_log = true
config.color = true
end
2 changes: 1 addition & 1 deletion wcc-contentful/README.md
Expand Up @@ -2,7 +2,7 @@
[![CircleCI](https://circleci.com/gh/watermarkchurch/wcc-contentful.svg?style=svg)](https://circleci.com/gh/watermarkchurch/wcc-contentful)
[![Coverage Status](https://coveralls.io/repos/github/watermarkchurch/wcc-contentful/badge.svg?branch=master)](https://coveralls.io/github/watermarkchurch/wcc-contentful?branch=master)

Full documentation: https://www.rubydoc.info/github/watermarkchurch/wcc-contentful
Full documentation: https://www.rubydoc.info/gems/wcc-contentful

# WCC::Contentful

Expand Down
8 changes: 5 additions & 3 deletions wcc-contentful/app/jobs/wcc/contentful/delayed_sync_job.rb
Expand Up @@ -33,7 +33,7 @@ def sync!(up_to_id: nil)
return unless store.respond_to?(:index)

self.class.mutex.synchronize do
next_sync_token = store.find('sync:token')&.fetch('token')
next_sync_token = store.find('sync:token')&.fetch('token', nil)
sync_resp = client.sync(sync_token: next_sync_token)

id_found = up_to_id.nil?
Expand All @@ -45,10 +45,12 @@ def sync!(up_to_id: nil)
store.index(item)
count += 1
end
store.set('sync:token', token: sync_resp.next_sync_token)
store.set('sync:token', 'token' => sync_resp.next_sync_token)

logger.info "Synced #{count} entries. Next sync token:\n #{sync_resp.next_sync_token}"
sync_later!(up_to_id: up_to_id) unless id_found
logger.info "Should enqueue again? [#{!id_found}]"
# Passing nil to only enqueue the job 1 more time
sync_later!(up_to_id: nil) unless id_found
sync_resp.next_sync_token
end
end
Expand Down
5 changes: 2 additions & 3 deletions wcc-contentful/lib/wcc/contentful/client_ext.rb
Expand Up @@ -19,10 +19,9 @@ def self.get_http(url, query, headers = {}, proxy = {})
adapter.call(url, query, headers, proxy)
end

REWRITE_REGEXP = /^(https?\:\/\/(?:\w+)\.contentful\.com\/spaces\/[^\/]+\/)(?!environments)(.+)$/
.freeze
REWRITE_REGX = /^(https?\:\/\/(?:\w+)\.contentful\.com\/spaces\/[^\/]+\/)(?!environments)(.+)$/.freeze
def self.rewrite_to_environment(url, environment)
return url unless m = REWRITE_REGEXP.match(url)
return url unless m = REWRITE_REGX.match(url)

File.join(m[1], 'environments', environment, m[2])
end
Expand Down
68 changes: 64 additions & 4 deletions wcc-contentful/spec/jobs/wcc/contentful/delayed_sync_job_spec.rb
Expand Up @@ -31,7 +31,7 @@
))

expect(WCC::Contentful::Services.instance.store).to receive(:set)
.with('sync:token', { token: 'test' })
.with('sync:token', { 'token' => 'test' })
expect(WCC::Contentful::Services.instance.store).to_not receive(:index)

# act
Expand All @@ -55,7 +55,7 @@

items = next_sync['items']
expect(WCC::Contentful::Services.instance.store).to receive(:set)
.with('sync:token', { token: 'test2' })
.with('sync:token', { 'token' => 'test2' })
expect(WCC::Contentful::Services.instance.store).to receive(:index)
.exactly(items.count).times

Expand All @@ -80,7 +80,7 @@
end
end

it 'Drops the job again if the ID still does not come back' do
it 'Drops the job again if the ID still does not come back and told to go again' do
allow(client).to receive(:sync)
.and_return(double(
items: next_sync['items'],
Expand All @@ -89,11 +89,71 @@

# expect
expect(job).to receive(:sync_later!)
.with(up_to_id: 'foobar')
.with(up_to_id: nil)

# act
job.sync!(up_to_id: 'foobar')
end

it 'does not drop a job if the ID is nil' do
allow(client).to receive(:sync)
.and_return(double(
items: next_sync['items'],
next_sync_token: 'test2'
))

expect(ActiveJob::Base.queue_adapter).to_not receive(:enqueue)
expect(ActiveJob::Base.queue_adapter).to_not receive(:enqueue_at)

# act
job.sync!(up_to_id: nil)
end

it 'continues from prior sync token with LazyCacheStore' do
allow(WCC::Contentful::Services.instance).to receive(:store)
.and_return(WCC::Contentful::Store::LazyCacheStore.new(client))

allow(client).to receive(:sync)
.with({ sync_token: nil })
.and_return(double(
items: [],
next_sync_token: 'test'
))
expect(client).to receive(:sync)
.with({ sync_token: 'test' })
.and_return(double(
items: [],
next_sync_token: 'test2'
))

# act
synced = job.sync!
synced2 = job.sync!

# assert
expect(synced).to eq('test')
expect(synced2).to eq('test2')
end

it 'ignores a poison sync token in the store' do
allow(WCC::Contentful::Services.instance).to receive(:store)
.and_return(WCC::Contentful::Store::LazyCacheStore.new(client))

store.set('sync:token', poison: 'poison')

expect(client).to receive(:sync)
.with({ sync_token: nil })
.and_return(double(
items: [],
next_sync_token: 'test'
))

# act
synced = job.sync!

# assert
expect(synced).to eq('test')
end
end

describe 'Perform' do
Expand Down
2 changes: 1 addition & 1 deletion wcc-contentful/spec/spec_helper.rb
Expand Up @@ -8,6 +8,7 @@
require 'webmock/rspec'
require 'vcr'
require 'httplog'
require 'byebug'

require 'bench_helper'

Expand Down Expand Up @@ -70,5 +71,4 @@

HttpLog.configure do |config|
config.compact_log = true
config.color = true
end

0 comments on commit d9f26b2

Please sign in to comment.