contentful-scheduler-custom 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +26 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +178 -0
- data/Rakefile +7 -0
- data/contentful-scheduler.gemspec +35 -0
- data/example/Gemfile +7 -0
- data/example/Gemfile.lock +83 -0
- data/example/Procfile +4 -0
- data/example/Rakefile +45 -0
- data/example/config.ru +13 -0
- data/lib/contentful/scheduler.rb +57 -0
- data/lib/contentful/scheduler/controller.rb +30 -0
- data/lib/contentful/scheduler/queue.rb +147 -0
- data/lib/contentful/scheduler/tasks.rb +1 -0
- data/lib/contentful/scheduler/tasks/publish.rb +21 -0
- data/lib/contentful/scheduler/version.rb +5 -0
- data/spec/contentful/scheduler/controller_spec.rb +46 -0
- data/spec/contentful/scheduler/queue_spec.rb +257 -0
- data/spec/contentful/scheduler/tasks/publish_spec.rb +42 -0
- data/spec/contentful/scheduler_spec.rb +141 -0
- data/spec/spec_helper.rb +60 -0
- metadata +244 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f92623b5fe928b9bfe25297cf01e837ab8aa5046
|
4
|
+
data.tar.gz: f9bf39f91e6d5a3554586eb79f9a586088e29ac8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b879d5aca93a62fe73b284078a404c7a1d6680e71474c1f9b6fb55ec7ed1db82d7bc540282d4084acc3445fce8214ec5efb208bffa9879b1ba42fb6220c4b7b4
|
7
|
+
data.tar.gz: 5a0467c6f469baafefd4139f46d4188e5a06cb2ecbeb18b83ce29668b920302c2d8f0162f0a730b3a505f3ea312ee17d912b2d9daaa616ef76f5975c2acd1ab1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
## 1.4.0
|
6
|
+
* Contentful Scheduler now supports future publishing for any existing enteries and
|
7
|
+
publishing ContentBlocks first before publishing the page.
|
8
|
+
|
9
|
+
## 0.2.1
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
* Fix time parsing.
|
13
|
+
|
14
|
+
## 0.2.0
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
* Added User Agent Header Application Name
|
19
|
+
|
20
|
+
### Changed
|
21
|
+
|
22
|
+
* Updated to latest CMA SDK Version.
|
23
|
+
|
24
|
+
## 0.1.0
|
25
|
+
|
26
|
+
* Initial Release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/Guardfile
ADDED
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-custom-build-john', '~>1.30'
|
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,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"
|
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,83 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.5.2)
|
5
|
+
public_suffix (>= 2.0.2, < 4.0)
|
6
|
+
chronic (0.10.2)
|
7
|
+
contentful-management (1.10.0)
|
8
|
+
http (> 1.0, < 3.0)
|
9
|
+
json (~> 1.8)
|
10
|
+
multi_json (~> 1)
|
11
|
+
contentful-scheduler (0.2.1)
|
12
|
+
chronic (~> 0.10)
|
13
|
+
contentful-management (~> 1.8)
|
14
|
+
contentful-webhook-listener (~> 0.2)
|
15
|
+
redis (~> 3.0)
|
16
|
+
resque (~> 1.0)
|
17
|
+
resque-scheduler (~> 4.0)
|
18
|
+
contentful-webhook-listener (0.3.0)
|
19
|
+
domain_name (0.5.20170404)
|
20
|
+
unf (>= 0.0.5, < 1.0.0)
|
21
|
+
et-orbi (1.0.8)
|
22
|
+
tzinfo
|
23
|
+
http (2.2.2)
|
24
|
+
addressable (~> 2.3)
|
25
|
+
http-cookie (~> 1.0)
|
26
|
+
http-form_data (~> 1.0.1)
|
27
|
+
http_parser.rb (~> 0.6.0)
|
28
|
+
http-cookie (1.0.3)
|
29
|
+
domain_name (~> 0.5)
|
30
|
+
http-form_data (1.0.3)
|
31
|
+
http_parser.rb (0.6.0)
|
32
|
+
json (1.8.6)
|
33
|
+
mono_logger (1.1.0)
|
34
|
+
multi_json (1.13.1)
|
35
|
+
mustermann (1.0.1)
|
36
|
+
public_suffix (3.0.1)
|
37
|
+
rack (2.0.3)
|
38
|
+
rack-protection (2.0.0)
|
39
|
+
rack
|
40
|
+
rake (12.3.0)
|
41
|
+
redis (3.3.5)
|
42
|
+
redis-namespace (1.6.0)
|
43
|
+
redis (>= 3.0.4)
|
44
|
+
resque (1.27.4)
|
45
|
+
mono_logger (~> 1.0)
|
46
|
+
multi_json (~> 1.0)
|
47
|
+
redis-namespace (~> 1.3)
|
48
|
+
sinatra (>= 0.9.2)
|
49
|
+
vegas (~> 0.1.2)
|
50
|
+
resque-scheduler (4.3.1)
|
51
|
+
mono_logger (~> 1.0)
|
52
|
+
redis (>= 3.3, < 5)
|
53
|
+
resque (~> 1.26)
|
54
|
+
rufus-scheduler (~> 3.2)
|
55
|
+
rufus-scheduler (3.4.2)
|
56
|
+
et-orbi (~> 1.0)
|
57
|
+
sinatra (2.0.0)
|
58
|
+
mustermann (~> 1.0)
|
59
|
+
rack (~> 2.0)
|
60
|
+
rack-protection (= 2.0.0)
|
61
|
+
tilt (~> 2.0)
|
62
|
+
thread_safe (0.3.6)
|
63
|
+
tilt (2.0.8)
|
64
|
+
tzinfo (1.2.4)
|
65
|
+
thread_safe (~> 0.1)
|
66
|
+
unf (0.1.4)
|
67
|
+
unf_ext
|
68
|
+
unf_ext (0.0.7.4)
|
69
|
+
vegas (0.1.11)
|
70
|
+
rack (>= 1.0.0)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
ruby
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
contentful-management (~> 1.0)
|
77
|
+
contentful-scheduler (~> 0.1)
|
78
|
+
rake
|
79
|
+
resque (~> 1.0)
|
80
|
+
resque-scheduler (~> 4.0)
|
81
|
+
|
82
|
+
BUNDLED WITH
|
83
|
+
1.16.1
|
data/example/Procfile
ADDED
data/example/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'contentful/scheduler'
|
2
|
+
|
3
|
+
$stdout.sync = true
|
4
|
+
|
5
|
+
config = {
|
6
|
+
logger: Logger.new(STDOUT), # Defaults to NullLogger
|
7
|
+
port: 6378, # Defaults to 8081
|
8
|
+
endpoint: '/scheduler', # Defaults to /scheduler
|
9
|
+
redis: {
|
10
|
+
host: '127.0.0.1',
|
11
|
+
port: '6379',
|
12
|
+
password: '5D40001BB59A2EF2439A55DAB7E718609A3A93CC9D3FD414BB13A75933048CD7'
|
13
|
+
},
|
14
|
+
spaces: {
|
15
|
+
'qbra4qai2ti2' => {
|
16
|
+
publish_field: 'publishDate', # It specifies the field ID for your Publish Date in your Content Type
|
17
|
+
management_token: 'CFPAT-45f0c4258aa9b32e8a8b6ccebf64136386b31f3ec435cc17f540368d5416de02'
|
18
|
+
}
|
19
|
+
},
|
20
|
+
}
|
21
|
+
|
22
|
+
namespace :contentful do
|
23
|
+
task :setup do
|
24
|
+
Contentful::Scheduler.config = config
|
25
|
+
end
|
26
|
+
|
27
|
+
task :scheduler => :setup do
|
28
|
+
Contentful::Scheduler.start
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
require 'resque/tasks'
|
33
|
+
require 'resque/scheduler/tasks'
|
34
|
+
|
35
|
+
namespace :resque do
|
36
|
+
task :setup => 'contentful:setup' do
|
37
|
+
ENV['QUEUE'] = '*'
|
38
|
+
end
|
39
|
+
|
40
|
+
task :setup_schedule => :setup do
|
41
|
+
require 'resque-scheduler'
|
42
|
+
end
|
43
|
+
|
44
|
+
task :scheduler => :setup_schedule
|
45
|
+
end
|