consyncful 0.7.1 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -13
- data/README.md +6 -1
- data/lib/consyncful/sync.rb +11 -7
- data/lib/consyncful/tasks/consyncful.rake +5 -0
- data/lib/consyncful/version.rb +1 -1
- data/lib/consyncful.rb +21 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39ad7cde060eb4740f59d3d630116456e4ca766a288e69589da90d16d501688b
|
4
|
+
data.tar.gz: e1498ad860cae54c4a7779979d0ec501dec1df99d3e1f1b8942c710c2a014520
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 447015c1e208ef8f8d70b4e6d5f0c006fbbc762bc88b90be3bc73ab39c10eb94e6ce0babd86cee7fc509e3664edc14ebb796c443536f58018a1a2358120c913f
|
7
|
+
data.tar.gz: 8f4a2561961ebe86546b3c3b9760107c3b90ddab8958a872940323f889928a89219315c6e41ced013a33374b352b66b3c0d275539c442549e77f6206ea3bb3a5
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
consyncful (0.7.
|
4
|
+
consyncful (0.7.3)
|
5
5
|
contentful (>= 2.11.1, < 3.0.0)
|
6
6
|
hooks (>= 0.4.1)
|
7
7
|
mongoid (>= 7.0.2, < 8.0.0)
|
@@ -10,15 +10,15 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activemodel (7.0.3)
|
14
|
-
activesupport (= 7.0.3)
|
15
|
-
activesupport (7.0.3)
|
13
|
+
activemodel (7.0.3.1)
|
14
|
+
activesupport (= 7.0.3.1)
|
15
|
+
activesupport (7.0.3.1)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
19
19
|
tzinfo (~> 2.0)
|
20
|
-
addressable (2.8.
|
21
|
-
public_suffix (>= 2.0.2, <
|
20
|
+
addressable (2.8.1)
|
21
|
+
public_suffix (>= 2.0.2, < 6.0)
|
22
22
|
ast (2.4.2)
|
23
23
|
bson (4.15.0)
|
24
24
|
concurrent-ruby (1.1.10)
|
@@ -45,12 +45,12 @@ GEM
|
|
45
45
|
http-form_data (2.3.0)
|
46
46
|
http-parser (1.2.3)
|
47
47
|
ffi-compiler (>= 1.0, < 2.0)
|
48
|
-
i18n (1.
|
48
|
+
i18n (1.12.0)
|
49
49
|
concurrent-ruby (~> 1.0)
|
50
|
-
minitest (5.16.
|
51
|
-
mongo (2.
|
52
|
-
bson (>= 4.
|
53
|
-
mongoid (7.
|
50
|
+
minitest (5.16.3)
|
51
|
+
mongo (2.18.1)
|
52
|
+
bson (>= 4.14.1, < 5.0.0)
|
53
|
+
mongoid (7.5.1)
|
54
54
|
activemodel (>= 5.1, < 7.1, != 7.0.0)
|
55
55
|
mongo (>= 2.10.5, < 3.0.0)
|
56
56
|
ruby2_keywords (~> 0.0.5)
|
@@ -58,7 +58,7 @@ GEM
|
|
58
58
|
parallel (1.22.1)
|
59
59
|
parser (3.1.2.0)
|
60
60
|
ast (~> 2.4.1)
|
61
|
-
public_suffix (
|
61
|
+
public_suffix (5.0.0)
|
62
62
|
rainbow (3.1.1)
|
63
63
|
rake (13.0.1)
|
64
64
|
regexp_parser (2.3.1)
|
@@ -93,7 +93,7 @@ GEM
|
|
93
93
|
rubocop (~> 1.19)
|
94
94
|
ruby-progressbar (1.11.0)
|
95
95
|
ruby2_keywords (0.0.5)
|
96
|
-
tzinfo (2.0.
|
96
|
+
tzinfo (2.0.5)
|
97
97
|
concurrent-ruby (~> 1.0)
|
98
98
|
uber (0.0.15)
|
99
99
|
unf (0.1.4)
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ If you don't already use Mongoid, generate a mongoid.yml by running:
|
|
42
42
|
|
43
43
|
Add an initializer:
|
44
44
|
|
45
|
-
Consyncful uses [contentful.rb](https://github.com/contentful/contentful.rb); client options are as documented there.
|
45
|
+
Consyncful uses [contentful.rb](https://github.com/contentful/contentful.rb); client options are as documented there. Sync options are documented in the [Content Delivery Sync API docs](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization).
|
46
46
|
```rb
|
47
47
|
Consyncful.configure do |config|
|
48
48
|
config.locale = 'en-NZ'
|
@@ -53,6 +53,11 @@ Consyncful.configure do |config|
|
|
53
53
|
environment: 'master', # optional
|
54
54
|
logger: Logger.new(STDOUT) # optional for debugging
|
55
55
|
}
|
56
|
+
|
57
|
+
# optional to override the Sync API defaults
|
58
|
+
config.contentful_sync_options = {
|
59
|
+
limit: 50
|
60
|
+
}
|
56
61
|
end
|
57
62
|
```
|
58
63
|
|
data/lib/consyncful/sync.rb
CHANGED
@@ -83,13 +83,17 @@ module Consyncful
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def start_sync
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
86
|
+
next_url.present? ? start_update : start_new_sync
|
87
|
+
end
|
88
|
+
|
89
|
+
def start_update
|
90
|
+
puts Rainbow("Starting update, last update: #{last_run_at} (#{(Time.current - last_run_at).round(3)}s ago)").blue
|
91
|
+
Consyncful.client.sync(next_url)
|
92
|
+
end
|
93
|
+
|
94
|
+
def start_new_sync
|
95
|
+
puts Rainbow('Starting full refresh').blue
|
96
|
+
Consyncful.client.sync(Consyncful.configuration.initial_sync_options)
|
93
97
|
end
|
94
98
|
|
95
99
|
def sync_items(sync, stats)
|
@@ -10,6 +10,11 @@ namespace :consyncful do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
task :sync, [:seconds] => %i[environment update_model_names] do |_task, args|
|
13
|
+
Signal.trap('TERM') do
|
14
|
+
puts Rainbow("Graceful shutdown PID=#{Process.pid}").red
|
15
|
+
exit 0
|
16
|
+
end
|
17
|
+
|
13
18
|
seconds = args[:seconds].to_i
|
14
19
|
seconds = 15 if seconds.zero?
|
15
20
|
loop do
|
data/lib/consyncful/version.rb
CHANGED
data/lib/consyncful.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'consyncful/version'
|
4
|
-
|
5
4
|
require 'mongoid'
|
6
5
|
require 'contentful'
|
7
|
-
|
8
6
|
require 'consyncful/base'
|
9
7
|
require 'consyncful/sync'
|
10
|
-
|
11
8
|
require 'consyncful/railtie' if defined?(Rails)
|
12
9
|
|
13
10
|
module Consyncful
|
14
11
|
# Handles Rails configurations for Consynful
|
15
12
|
class Configuration
|
16
13
|
attr_accessor :contentful_client_options,
|
14
|
+
:contentful_sync_options,
|
17
15
|
:locale,
|
18
16
|
:mongo_client,
|
19
17
|
:mongo_collection,
|
@@ -22,9 +20,8 @@ module Consyncful
|
|
22
20
|
:preserve_contentful_timestamps
|
23
21
|
|
24
22
|
def initialize
|
25
|
-
@contentful_client_options = {
|
26
|
-
|
27
|
-
}
|
23
|
+
@contentful_client_options = {}
|
24
|
+
@contentful_sync_options = {}
|
28
25
|
@locale = 'en-NZ'
|
29
26
|
@mongo_client = :default
|
30
27
|
@mongo_collection = 'contentful_models'
|
@@ -32,6 +29,17 @@ module Consyncful
|
|
32
29
|
@ignore_content_tags = []
|
33
30
|
@preserve_contentful_timestamps = false
|
34
31
|
end
|
32
|
+
|
33
|
+
def initial_sync_options
|
34
|
+
options = { initial: true }
|
35
|
+
options = options.reverse_merge(@contentful_sync_options)
|
36
|
+
options.reverse_merge(DEFAULT_SYNC_OPTIONS)
|
37
|
+
end
|
38
|
+
|
39
|
+
def client_options
|
40
|
+
options = @contentful_client_options
|
41
|
+
options.reverse_merge!(DEFAULT_CLIENT_OPTIONS)
|
42
|
+
end
|
35
43
|
end
|
36
44
|
|
37
45
|
DEFAULT_CLIENT_OPTIONS = {
|
@@ -39,6 +47,12 @@ module Consyncful
|
|
39
47
|
api_url: 'cdn.contentful.com'
|
40
48
|
}.freeze
|
41
49
|
|
50
|
+
# see https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization
|
51
|
+
DEFAULT_SYNC_OPTIONS = {
|
52
|
+
limit: 100,
|
53
|
+
type: 'all'
|
54
|
+
}.freeze
|
55
|
+
|
42
56
|
class << self
|
43
57
|
def configuration
|
44
58
|
@configuration ||= Configuration.new
|
@@ -49,11 +63,7 @@ module Consyncful
|
|
49
63
|
end
|
50
64
|
|
51
65
|
def client
|
52
|
-
@client ||=
|
53
|
-
options = Consyncful.configuration.contentful_client_options
|
54
|
-
options.reverse_merge!(DEFAULT_CLIENT_OPTIONS)
|
55
|
-
Contentful::Client.new(options)
|
56
|
-
end
|
66
|
+
@client ||= Contentful::Client.new(Consyncful.configuration.client_options)
|
57
67
|
end
|
58
68
|
end
|
59
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consyncful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Anastasiadis-Gray
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|