contentful-scheduler-custom-build-john 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19a1ad44ae171175e2cd91229b2f3961c63bbbf7
4
+ data.tar.gz: 44532bf65de030afa80e1ae709b7a3083fbc3f79
5
+ SHA512:
6
+ metadata.gz: c3b65cc6cbe92d3ae90c1d8e1b9045171fa7ad2cb793092411b2bfd03dfa7cf34d82358132023150bd405aaf1f6b7115b6685efdde262ebfdc099987211290b5
7
+ data.tar.gz: cf1bc0a3402f02e28b93461d3854d8b430f5dbb6e54a26592b074ef3f1d9eb1c06c8ac300956a9a5932c9d436201f436eabc58087eb4d902fe6919ab874bf72a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ dump.rdb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ - 2.3.1
5
+ - 2.4.0
6
+ before_install: gem install bundler -v 1.10.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # CHANGELOG
2
+
3
+ ## Unreleased
4
+
5
+ ## 0.2.1
6
+
7
+ ### Fixed
8
+ * Fix time parsing.
9
+
10
+ ## 0.2.0
11
+
12
+ ### Added
13
+
14
+ * Added User Agent Header Application Name
15
+
16
+ ### Changed
17
+
18
+ * Updated to latest CMA SDK Version.
19
+
20
+ ## 0.1.0
21
+
22
+ * Initial Release
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in contentful-scheduler.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'rspec --format documentation --color' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Contentful GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # Contentful Scheduler
2
+
3
+ Scheduling Server for Contentful entries.
4
+
5
+ ## Contentful
6
+ [Contentful](https://www.contentful.com) provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.
7
+
8
+ ## What does `contentful-scheduler` do?
9
+ The aim of `contentful-scheduler` is to have developers setting up their Contentful
10
+ entries for scheduled publishing.
11
+
12
+ ## How does it work
13
+ `contentful-scheduler` provides a web endpoint to receive webhook calls from Contentful,
14
+ every time the endpoint recieves a call it looks for the value of the field defined in the configuration,
15
+ if the value is a time in the future it will schedule the entry for publishing at the specified time.
16
+ A background worker based on the popular `resque` gem will then proceed to actually make the publish call
17
+ against the Content Management API at the due time. For this the Entries you wish to publish require a
18
+ customizable Date field, which we advice to call `publishDate`, this field can be configured inside your
19
+ `Rakefile` and is specific per-space.
20
+
21
+ You can add multiple spaces to your configuration, making it useful if you have a milti-space setup.
22
+
23
+ ## Requirements
24
+
25
+ * [Redis](http://redis.io/)
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'contentful-scheduler'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install contentful-scheduler
42
+
43
+ ## Usage
44
+
45
+ The best way to use Scheduler is as a stand-alone application that wraps Scheduler and Resque on an execution pipe using [Foreman](http://ddollar.github.io/foreman/).
46
+
47
+ You can get the template for this setup in the [`/example`](./example) directory.
48
+
49
+ If you want to roll out your own, you need to follow the next steps:
50
+
51
+ * Create a new folder
52
+ * Create a `Gemfile` with the following:
53
+
54
+ ```ruby
55
+ source 'https://rubygems.org'
56
+
57
+ gem 'contentful-scheduler', '~> 0.1'
58
+ gem 'contentful-management', '~> 1.0'
59
+ gem 'resque', '~> 1.0'
60
+ gem 'resque-scheduler', '~> 4.0'
61
+ gem 'rake'
62
+ ```
63
+
64
+ * Create a `Procfile` with the following:
65
+
66
+ ```
67
+ web: env bundle exec rake contentful:scheduler
68
+ monitor: env bundle exec rackup
69
+ resque: env bundle exec rake resque:work
70
+ resque_scheduler: env bundle exec rake resque:scheduler
71
+ ```
72
+
73
+ * Create a `Rakefile` with the following:
74
+
75
+ ```ruby
76
+ require 'contentful/scheduler'
77
+
78
+ $stdout.sync = true
79
+
80
+ config = {
81
+ logger: Logger.new(STDOUT), # Defaults to NullLogger
82
+ port: 32123, # Defaults to 32123
83
+ endpoint: '/scheduler', # Defaults to /scheduler
84
+ redis: {
85
+ host: 'YOUR_REDIS_HOST',
86
+ port: 'YOUR_REDIS_PORT',
87
+ password: 'YOUR_REDIS_PASSWORD'
88
+ },
89
+ spaces: {
90
+ 'YOUR_SPACE_ID' => {
91
+ publish_field: 'publishDate', # It specifies the field ID for your Publish Date in your Content Type
92
+ management_token: 'YOUR_TOKEN'
93
+ }
94
+ },
95
+ }
96
+
97
+ namespace :contentful do
98
+ task :setup do
99
+ Contentful::Scheduler.config = config
100
+ end
101
+
102
+ task :scheduler => :setup do
103
+ Contentful::Scheduler.start
104
+ end
105
+ end
106
+
107
+ require 'resque/tasks'
108
+ require 'resque/scheduler/tasks'
109
+
110
+ namespace :resque do
111
+ task :setup => 'contentful:setup' do
112
+ ENV['QUEUE'] = '*'
113
+ end
114
+
115
+ task :setup_schedule => :setup do
116
+ require 'resque-scheduler'
117
+ end
118
+
119
+ task :scheduler => :setup_schedule
120
+ end
121
+ ```
122
+
123
+ * Create a `config.ru` with the following for the Resque monitoring server:
124
+
125
+ ```ruby
126
+ require 'resque'
127
+ require 'resque/server'
128
+ require 'resque/scheduler/server'
129
+
130
+ config = {
131
+ host: 'YOUR_REDIS_HOST',
132
+ port: 'YOUR_REDIS_PORT',
133
+ password: 'YOUR_REDIS_PASSWORD'
134
+ }
135
+ Resque.redis = config
136
+
137
+ run Rack::URLMap.new \
138
+ "/" => Resque::Server.new
139
+ ```
140
+
141
+ * Run the Application:
142
+
143
+ ```bash
144
+ $ foreman start
145
+ ```
146
+
147
+ * Configure the webhook in Contentful:
148
+
149
+ Under the space settings menu choose webhook and add a new webhook pointing to `http://YOUR_SERVER:32123/scheduler`.
150
+
151
+ Keep in mind that if you modify the defaults, the URL should be changed to the values specified in the configuration.
152
+
153
+ ## Running in Heroku
154
+
155
+ Heroku offers various Redis plugins, select the one of your liking, add the credentials into your configuration, and proceed to
156
+ `git heroku push master`.
157
+
158
+ This will get your application set up and running. It will require 4 dynos, so a free plan isn't enough for it to run.
159
+
160
+ To run the `monitor` process, you'll require to run it from a different application pointing to the same Redis instance.
161
+
162
+ Make sure to change the `Procfile`'s `web` process to the following:
163
+
164
+ ```
165
+ web: PORT=$PORT bundle exec env rake contentful:scheduler
166
+ ```
167
+
168
+ That will allow Heroku to set it's own Port according to their policy.
169
+
170
+ The URL for the webhook then will be on port 80, so you should change it to: `http://YOUR_APPLICATION/scheduler`.
171
+
172
+ ## Contributing
173
+
174
+ Bug reports and pull requests are welcome on GitHub at https://github.com/contentful/contentful-scheduler.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
175
+
176
+ ## License
177
+
178
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'contentful/scheduler/tasks'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'contentful/scheduler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "contentful-scheduler-custom-build-john"
8
+ spec.version = Contentful::Scheduler::VERSION
9
+ spec.authors = ["Contentful GmbH (David Litvak Bruno0"]
10
+ spec.email = ["david.litvak@contentful.com"]
11
+
12
+ spec.summary = %q{Customizable Scheduler for Contentful Entries.}
13
+ spec.description = %q{Customizable Scheduler for Contentful Entries.}
14
+ spec.homepage = "https://www.contentful.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "contentful-webhook-listener", "~> 0.2"
23
+ spec.add_runtime_dependency "contentful-management", "~> 1.8"
24
+ spec.add_runtime_dependency "resque", "~> 1.27.4"
25
+ spec.add_runtime_dependency "resque-scheduler", "~> 4.2.1"
26
+ spec.add_runtime_dependency "redis", "~> 3.0"
27
+ spec.add_runtime_dependency "chronic", "~> 0.10"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec"
32
+ spec.add_development_dependency "guard"
33
+ spec.add_development_dependency "guard-rspec"
34
+ spec.add_development_dependency "simplecov"
35
+ end
data/example/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'contentful-scheduler', '~> 0.1'
4
+ gem 'contentful-management', '~> 1.0'
5
+ gem 'resque', '~> 1.0'
6
+ gem 'resque-scheduler', '~> 4.0'
7
+ gem 'rake'
data/example/Procfile ADDED
@@ -0,0 +1,4 @@
1
+ web: env bundle exec rake contentful:scheduler
2
+ monitor: env bundle exec rackup
3
+ resque: env bundle exec rake resque:work
4
+ resque_scheduler: env bundle exec rake resque:scheduler
data/example/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'contentful/scheduler'
2
+ require 'logger' # Optional
3
+
4
+ $stdout.sync = true
5
+
6
+ config = {
7
+ logger: Logger.new(STDOUT), # Defaults to NullLogger
8
+ port: 32123, # Defaults to 32123
9
+ endpoint: '/scheduler', # Defaults to /scheduler
10
+ redis: {
11
+ host: 'YOUR_REDIS_HOST',
12
+ port: 'YOUR_REDIS_PORT',
13
+ password: 'YOUR_REDIS_PASSWORD'
14
+ },
15
+ spaces: {
16
+ 'YOUR_SPACE_ID' => {
17
+ publish_field: 'publishDate', # It specifies the field ID for your Publish Date in your Content Type
18
+ management_token: 'YOUR_TOKEN'
19
+ }
20
+ }
21
+ }
22
+
23
+ namespace :contentful do
24
+ task :setup do
25
+ Contentful::Scheduler.config = config
26
+ end
27
+
28
+ task :scheduler => :setup do
29
+ Contentful::Scheduler.start
30
+ end
31
+ end
32
+
33
+ require 'resque/tasks'
34
+ require 'resque/scheduler/tasks'
35
+
36
+ namespace :resque do
37
+ task :setup => 'contentful:setup' do
38
+ ENV['QUEUE'] = '*'
39
+ end
40
+
41
+ task :setup_schedule => :setup do
42
+ require 'resque-scheduler'
43
+ end
44
+
45
+ task :scheduler => :setup_schedule
46
+ end
data/example/config.ru ADDED
@@ -0,0 +1,13 @@
1
+ require 'resque'
2
+ require 'resque/server'
3
+ require 'resque/scheduler/server'
4
+
5
+ config = {
6
+ host: 'YOUR_REDIS_HOST',
7
+ port: 'YOUR_REDIS_PORT',
8
+ password: 'YOUR_REDIS_PASSWORD'
9
+ }
10
+ Resque.redis = config
11
+
12
+ run Rack::URLMap.new \
13
+ "/" => Resque::Server.new
@@ -0,0 +1,57 @@
1
+ require 'resque'
2
+ require 'redis'
3
+ require 'logger'
4
+ require 'contentful/webhook/listener'
5
+
6
+ require_relative 'scheduler/controller'
7
+ require_relative 'scheduler/version'
8
+
9
+ module Contentful
10
+ module Scheduler
11
+ DEFAULT_PORT = 32123
12
+ DEFAULT_ENDPOINT = '/scheduler'
13
+ DEFAULT_LOGGER = ::Contentful::Webhook::Listener::Support::NullLogger.new
14
+
15
+ @@config = nil
16
+
17
+ def self.config=(config)
18
+ fail ':redis configuration missing' unless config.key?(:redis)
19
+ fail ':spaces configuration missing' unless config.key?(:spaces)
20
+ config[:spaces].each do |space, data|
21
+ fail ":management_token missing for space: #{space}" unless data.key?(:management_token)
22
+ end
23
+
24
+ config[:port] = (ENV.key?('PORT') ? ENV['PORT'].to_i : DEFAULT_PORT) unless config.key?(:port)
25
+ config[:logger] = DEFAULT_LOGGER unless config.key?(:logger)
26
+ config[:endpoint] = DEFAULT_ENDPOINT unless config.key?(:endpoint)
27
+
28
+ ::Resque.redis = config[:redis].dup
29
+ @@config ||= config
30
+ end
31
+
32
+ def self.config
33
+ @@config
34
+ end
35
+
36
+ def self.start(config = {})
37
+ fail "Scheduler not configured" if self.config.nil? && !block_given?
38
+
39
+ if block_given?
40
+ yield(config) if block_given?
41
+ self.config = config
42
+ end
43
+
44
+ ::Contentful::Webhook::Listener::Server.start do |config|
45
+ config[:port] = self.config[:port]
46
+ config[:logger] = self.config[:logger]
47
+ config[:endpoints] = [
48
+ {
49
+ endpoint: self.config[:endpoint],
50
+ controller: ::Contentful::Scheduler::Controller,
51
+ timeout: 0
52
+ }
53
+ ]
54
+ end.join
55
+ end
56
+ end
57
+ end