-
Notifications
You must be signed in to change notification settings - Fork 0
Using a custom scheduling module
[Documentation in progress]
Find more information here: Post Scheduling Wiki
Ghost ships a default adapter for scheduling, which will schedule your posts or newsletters within the process. This adapter is configured by default, so if you start your server the scheduling feature is ready to use.
A disadvantage of the default adapter can be for you:
- if you have a cache in front of your blog, the default adapter is not able to clear a cache entry
- if your blog is off, scheduling is as well. That's why you maybe want to write custom adapters to communicate with external schedulers
You can write your own adapters. For example if you want to use the Heroku Scheduler or your own external logic.
1. Writing your adapter
my-adapter.js
// change the require path so that your adapter can import the scheduling base
var SchedulingBase = require('..../core/server/scheduling/SchedulingBase'),
function MyAdapter(options) {
SchedulingBase.call(this, options);
}
util.inherits(MyAdapter, SchedulingBase);
// required functions you need to implement
MyAdapter.prototype.schedule = function(object) {
// when the job should be executed (time is a UTC timestamp)
var time = object.time;
// the url you need to execute when the time is reached
var url = object.url;
// the HTTP method you need to use
var httpMethod = object.extra.httpMethod;
};
MyAdapter.prototype.reschedule = function(object) {
// see MyAdapter.prototype.schedule
// the time when the url was scheduled before (oldTime is a UTC timestamp)
var oldTime = object.extra.oldTime;
};
MyAdapter.prototype.unschedule = function(object) {
// see MyAdapter.prototype.schedule
};
//this function is called on server bootstrap
MyAdapter.prototype.run = function() {};
2. Adding your adapter
- copy your adapter to
content/data/scheduling/.
3. Extend your config.js
production: {
scheduling: {
active: 'my-adapter'
}
}
In this example we run Ghost in production, replace production if you run Ghost for example in development mode.
By default Ghost disallows publishing posts in the past or in the future to avoid problems/bugs. But in case your scheduling service was down, you can use the force flag to publish posts in the past.
if (moment(time).isBefore(moment())) {
request[httpMethod](url)
.send({ force: true })
.end(...)
}
If the httpMethod is a GET, you need to use query parameters.