Rewrite url service (#9550)
refs https://github.com/TryGhost/Team/issues/65
We are currently work on dynamic routing (aka channels).
An important piece of this feature is the url service, which always knows the url of a resource at any time.
Resources can belong to collections or taxonomies, which can be defined in a [routing yaml file](https://github.com/TryGhost/Ghost/issues/9528). We are currently shipping portions, which will at end form the full dynamic routing feature.
### Key Notes
- each routing type (collections, taxonomies, static pages) is registered in order - depending on the yaml routes file configuration
- static pages are an internal concept - they sit at the end of the subscriber queue
- we make use of a temporary [`Channels2`](https://github.com/TryGhost/Ghost/pull/9550/files#diff-9e7251409844521470c9829013cd1563) file, which simulates the current static routing in Ghost (this file will be modified, removed or whatever - this is one of the next steps)
- two way binding: you can ask for a resource url based on the resource id, you can ask for the resource based on the url
- in theory it's possible that multiple resources generate the same url: we don't handle this with collision (because this is error prone), we handle this with the order of serving content. if you ask the service for a resource, which lives behind e.g. /test/, you will get the resource which is served
- loose error handling -> log errors and handle instead of throw error and do nothing (we log the errors with a specific code, so we can react in case there is a bug)
- the url services fetches all resources on bootstrap. we only fetch and keep a reduced set of attributes (basically the main body of a resource)
- the bootstrap time will decrease a very little (depending on the amount of resources you have in your database)
- we still offer the option to disable url preloading (in your config `disableUrlPreload: true`) - this option will be removed as soon as the url service is connected. You can disable the service in case you encounter a problem
- **the url service is not yet connected, we will connect the service step by step. The first version should be released to pre-catch bugs. The next version will add 503 handling if the url service is not ready and it will consume urls for resources.**
----
- the url service generates urls based on resources (posts, pages, users, tags)
- the url service keeps track of resource changes
- the url service keeps track of resource removal/insert
- the architecture:
- each routing type is represented by a url generator
- a routing type is a collection, a taxonomiy or static pages
- a queue which ensures that urls are unique and can be owned by one url generator
- the hierarchy of registration defines that
- we query knex, because bookshelf is too slow
- removed old url service files + logic
- added temp channels alternative (Channels2) -> this file will look different soon, it's for now the temporary connector to the url service. Also the name of the file is not optimal, but that is not really important right now.
2018-04-17 12:29:04 +03:00
|
|
|
const _ = require('lodash');
|
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
2021-06-15 17:36:27 +03:00
|
|
|
const logging = require('@tryghost/logging');
|
2021-10-18 17:27:57 +03:00
|
|
|
const Queue = require('../../../../../core/server/services/url/Queue');
|
Rewrite url service (#9550)
refs https://github.com/TryGhost/Team/issues/65
We are currently work on dynamic routing (aka channels).
An important piece of this feature is the url service, which always knows the url of a resource at any time.
Resources can belong to collections or taxonomies, which can be defined in a [routing yaml file](https://github.com/TryGhost/Ghost/issues/9528). We are currently shipping portions, which will at end form the full dynamic routing feature.
### Key Notes
- each routing type (collections, taxonomies, static pages) is registered in order - depending on the yaml routes file configuration
- static pages are an internal concept - they sit at the end of the subscriber queue
- we make use of a temporary [`Channels2`](https://github.com/TryGhost/Ghost/pull/9550/files#diff-9e7251409844521470c9829013cd1563) file, which simulates the current static routing in Ghost (this file will be modified, removed or whatever - this is one of the next steps)
- two way binding: you can ask for a resource url based on the resource id, you can ask for the resource based on the url
- in theory it's possible that multiple resources generate the same url: we don't handle this with collision (because this is error prone), we handle this with the order of serving content. if you ask the service for a resource, which lives behind e.g. /test/, you will get the resource which is served
- loose error handling -> log errors and handle instead of throw error and do nothing (we log the errors with a specific code, so we can react in case there is a bug)
- the url services fetches all resources on bootstrap. we only fetch and keep a reduced set of attributes (basically the main body of a resource)
- the bootstrap time will decrease a very little (depending on the amount of resources you have in your database)
- we still offer the option to disable url preloading (in your config `disableUrlPreload: true`) - this option will be removed as soon as the url service is connected. You can disable the service in case you encounter a problem
- **the url service is not yet connected, we will connect the service step by step. The first version should be released to pre-catch bugs. The next version will add 503 handling if the url service is not ready and it will consume urls for resources.**
----
- the url service generates urls based on resources (posts, pages, users, tags)
- the url service keeps track of resource changes
- the url service keeps track of resource removal/insert
- the architecture:
- each routing type is represented by a url generator
- a routing type is a collection, a taxonomiy or static pages
- a queue which ensures that urls are unique and can be owned by one url generator
- the hierarchy of registration defines that
- we query knex, because bookshelf is too slow
- removed old url service files + logic
- added temp channels alternative (Channels2) -> this file will look different soon, it's for now the temporary connector to the url service. Also the name of the file is not optimal, but that is not really important right now.
2018-04-17 12:29:04 +03:00
|
|
|
|
|
|
|
describe('Unit: services/url/Queue', function () {
|
|
|
|
let queue;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
queue = new Queue();
|
|
|
|
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.spy(queue, 'run');
|
2020-05-25 11:49:38 +03:00
|
|
|
sinon.stub(logging, 'error');
|
Rewrite url service (#9550)
refs https://github.com/TryGhost/Team/issues/65
We are currently work on dynamic routing (aka channels).
An important piece of this feature is the url service, which always knows the url of a resource at any time.
Resources can belong to collections or taxonomies, which can be defined in a [routing yaml file](https://github.com/TryGhost/Ghost/issues/9528). We are currently shipping portions, which will at end form the full dynamic routing feature.
### Key Notes
- each routing type (collections, taxonomies, static pages) is registered in order - depending on the yaml routes file configuration
- static pages are an internal concept - they sit at the end of the subscriber queue
- we make use of a temporary [`Channels2`](https://github.com/TryGhost/Ghost/pull/9550/files#diff-9e7251409844521470c9829013cd1563) file, which simulates the current static routing in Ghost (this file will be modified, removed or whatever - this is one of the next steps)
- two way binding: you can ask for a resource url based on the resource id, you can ask for the resource based on the url
- in theory it's possible that multiple resources generate the same url: we don't handle this with collision (because this is error prone), we handle this with the order of serving content. if you ask the service for a resource, which lives behind e.g. /test/, you will get the resource which is served
- loose error handling -> log errors and handle instead of throw error and do nothing (we log the errors with a specific code, so we can react in case there is a bug)
- the url services fetches all resources on bootstrap. we only fetch and keep a reduced set of attributes (basically the main body of a resource)
- the bootstrap time will decrease a very little (depending on the amount of resources you have in your database)
- we still offer the option to disable url preloading (in your config `disableUrlPreload: true`) - this option will be removed as soon as the url service is connected. You can disable the service in case you encounter a problem
- **the url service is not yet connected, we will connect the service step by step. The first version should be released to pre-catch bugs. The next version will add 503 handling if the url service is not ready and it will consume urls for resources.**
----
- the url service generates urls based on resources (posts, pages, users, tags)
- the url service keeps track of resource changes
- the url service keeps track of resource removal/insert
- the architecture:
- each routing type is represented by a url generator
- a routing type is a collection, a taxonomiy or static pages
- a queue which ensures that urls are unique and can be owned by one url generator
- the hierarchy of registration defines that
- we query knex, because bookshelf is too slow
- removed old url service files + logic
- added temp channels alternative (Channels2) -> this file will look different soon, it's for now the temporary connector to the url service. Also the name of the file is not optimal, but that is not really important right now.
2018-04-17 12:29:04 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
Rewrite url service (#9550)
refs https://github.com/TryGhost/Team/issues/65
We are currently work on dynamic routing (aka channels).
An important piece of this feature is the url service, which always knows the url of a resource at any time.
Resources can belong to collections or taxonomies, which can be defined in a [routing yaml file](https://github.com/TryGhost/Ghost/issues/9528). We are currently shipping portions, which will at end form the full dynamic routing feature.
### Key Notes
- each routing type (collections, taxonomies, static pages) is registered in order - depending on the yaml routes file configuration
- static pages are an internal concept - they sit at the end of the subscriber queue
- we make use of a temporary [`Channels2`](https://github.com/TryGhost/Ghost/pull/9550/files#diff-9e7251409844521470c9829013cd1563) file, which simulates the current static routing in Ghost (this file will be modified, removed or whatever - this is one of the next steps)
- two way binding: you can ask for a resource url based on the resource id, you can ask for the resource based on the url
- in theory it's possible that multiple resources generate the same url: we don't handle this with collision (because this is error prone), we handle this with the order of serving content. if you ask the service for a resource, which lives behind e.g. /test/, you will get the resource which is served
- loose error handling -> log errors and handle instead of throw error and do nothing (we log the errors with a specific code, so we can react in case there is a bug)
- the url services fetches all resources on bootstrap. we only fetch and keep a reduced set of attributes (basically the main body of a resource)
- the bootstrap time will decrease a very little (depending on the amount of resources you have in your database)
- we still offer the option to disable url preloading (in your config `disableUrlPreload: true`) - this option will be removed as soon as the url service is connected. You can disable the service in case you encounter a problem
- **the url service is not yet connected, we will connect the service step by step. The first version should be released to pre-catch bugs. The next version will add 503 handling if the url service is not ready and it will consume urls for resources.**
----
- the url service generates urls based on resources (posts, pages, users, tags)
- the url service keeps track of resource changes
- the url service keeps track of resource removal/insert
- the architecture:
- each routing type is represented by a url generator
- a routing type is a collection, a taxonomiy or static pages
- a queue which ensures that urls are unique and can be owned by one url generator
- the hierarchy of registration defines that
- we query knex, because bookshelf is too slow
- removed old url service files + logic
- added temp channels alternative (Channels2) -> this file will look different soon, it's for now the temporary connector to the url service. Also the name of the file is not optimal, but that is not really important right now.
2018-04-17 12:29:04 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('fn: register', function () {
|
|
|
|
queue.register({
|
|
|
|
event: 'chocolate'
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
should.exist(queue.queue.chocolate);
|
|
|
|
queue.queue.chocolate.subscribers.length.should.eql(1);
|
|
|
|
|
|
|
|
queue.register({
|
|
|
|
event: 'chocolate'
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
queue.queue.chocolate.subscribers.length.should.eql(2);
|
|
|
|
|
|
|
|
queue.register({
|
|
|
|
event: 'nachos'
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
should.exist(queue.queue.chocolate);
|
|
|
|
should.exist(queue.queue.nachos);
|
|
|
|
|
|
|
|
queue.queue.chocolate.subscribers.length.should.eql(2);
|
|
|
|
queue.queue.nachos.subscribers.length.should.eql(1);
|
|
|
|
|
|
|
|
// events have not been triggered yet
|
|
|
|
queue.toNotify.should.eql({});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fn: start (no tolerance)', function () {
|
|
|
|
it('no subscribers', function (done) {
|
|
|
|
queue.addListener('ended', function (event) {
|
|
|
|
event.should.eql('nachos');
|
|
|
|
queue.run.callCount.should.eql(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('1 subscriber', function (done) {
|
|
|
|
let notified = 0;
|
|
|
|
|
|
|
|
queue.addListener('ended', function (event) {
|
|
|
|
event.should.eql('nachos');
|
|
|
|
queue.run.callCount.should.eql(2);
|
|
|
|
notified.should.eql(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.register({
|
|
|
|
event: 'nachos'
|
|
|
|
}, function () {
|
|
|
|
notified = notified + 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('x subscriber', function (done) {
|
|
|
|
let notified = 0;
|
|
|
|
let order = [];
|
|
|
|
|
|
|
|
queue.addListener('ended', function (event) {
|
|
|
|
event.should.eql('nachos');
|
|
|
|
|
|
|
|
// 9 subscribers + start triggers run
|
|
|
|
queue.run.callCount.should.eql(10);
|
|
|
|
notified.should.eql(9);
|
|
|
|
order.should.eql([0, 1, 2, 3, 4, 5, 6, 7, 8]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(_.range(9), function (i) {
|
|
|
|
queue.register({
|
|
|
|
event: 'nachos'
|
|
|
|
}, function () {
|
|
|
|
order.push(i);
|
|
|
|
notified = notified + 1;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('late subscriber', function (done) {
|
|
|
|
let notified = 0;
|
|
|
|
|
|
|
|
queue.addListener('ended', function (event) {
|
|
|
|
event.should.eql('nachos');
|
|
|
|
queue.run.callCount.should.eql(1);
|
|
|
|
notified.should.eql(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos'
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.register({
|
|
|
|
event: 'nachos'
|
|
|
|
}, function () {
|
|
|
|
notified = notified + 1;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-26 12:28:22 +03:00
|
|
|
it('subscriber throws error', function () {
|
Rewrite url service (#9550)
refs https://github.com/TryGhost/Team/issues/65
We are currently work on dynamic routing (aka channels).
An important piece of this feature is the url service, which always knows the url of a resource at any time.
Resources can belong to collections or taxonomies, which can be defined in a [routing yaml file](https://github.com/TryGhost/Ghost/issues/9528). We are currently shipping portions, which will at end form the full dynamic routing feature.
### Key Notes
- each routing type (collections, taxonomies, static pages) is registered in order - depending on the yaml routes file configuration
- static pages are an internal concept - they sit at the end of the subscriber queue
- we make use of a temporary [`Channels2`](https://github.com/TryGhost/Ghost/pull/9550/files#diff-9e7251409844521470c9829013cd1563) file, which simulates the current static routing in Ghost (this file will be modified, removed or whatever - this is one of the next steps)
- two way binding: you can ask for a resource url based on the resource id, you can ask for the resource based on the url
- in theory it's possible that multiple resources generate the same url: we don't handle this with collision (because this is error prone), we handle this with the order of serving content. if you ask the service for a resource, which lives behind e.g. /test/, you will get the resource which is served
- loose error handling -> log errors and handle instead of throw error and do nothing (we log the errors with a specific code, so we can react in case there is a bug)
- the url services fetches all resources on bootstrap. we only fetch and keep a reduced set of attributes (basically the main body of a resource)
- the bootstrap time will decrease a very little (depending on the amount of resources you have in your database)
- we still offer the option to disable url preloading (in your config `disableUrlPreload: true`) - this option will be removed as soon as the url service is connected. You can disable the service in case you encounter a problem
- **the url service is not yet connected, we will connect the service step by step. The first version should be released to pre-catch bugs. The next version will add 503 handling if the url service is not ready and it will consume urls for resources.**
----
- the url service generates urls based on resources (posts, pages, users, tags)
- the url service keeps track of resource changes
- the url service keeps track of resource removal/insert
- the architecture:
- each routing type is represented by a url generator
- a routing type is a collection, a taxonomiy or static pages
- a queue which ensures that urls are unique and can be owned by one url generator
- the hierarchy of registration defines that
- we query knex, because bookshelf is too slow
- removed old url service files + logic
- added temp channels alternative (Channels2) -> this file will look different soon, it's for now the temporary connector to the url service. Also the name of the file is not optimal, but that is not really important right now.
2018-04-17 12:29:04 +03:00
|
|
|
queue.register({
|
|
|
|
event: 'nachos'
|
|
|
|
}, function () {
|
2018-11-26 12:28:22 +03:00
|
|
|
throw new Error('oops');
|
Rewrite url service (#9550)
refs https://github.com/TryGhost/Team/issues/65
We are currently work on dynamic routing (aka channels).
An important piece of this feature is the url service, which always knows the url of a resource at any time.
Resources can belong to collections or taxonomies, which can be defined in a [routing yaml file](https://github.com/TryGhost/Ghost/issues/9528). We are currently shipping portions, which will at end form the full dynamic routing feature.
### Key Notes
- each routing type (collections, taxonomies, static pages) is registered in order - depending on the yaml routes file configuration
- static pages are an internal concept - they sit at the end of the subscriber queue
- we make use of a temporary [`Channels2`](https://github.com/TryGhost/Ghost/pull/9550/files#diff-9e7251409844521470c9829013cd1563) file, which simulates the current static routing in Ghost (this file will be modified, removed or whatever - this is one of the next steps)
- two way binding: you can ask for a resource url based on the resource id, you can ask for the resource based on the url
- in theory it's possible that multiple resources generate the same url: we don't handle this with collision (because this is error prone), we handle this with the order of serving content. if you ask the service for a resource, which lives behind e.g. /test/, you will get the resource which is served
- loose error handling -> log errors and handle instead of throw error and do nothing (we log the errors with a specific code, so we can react in case there is a bug)
- the url services fetches all resources on bootstrap. we only fetch and keep a reduced set of attributes (basically the main body of a resource)
- the bootstrap time will decrease a very little (depending on the amount of resources you have in your database)
- we still offer the option to disable url preloading (in your config `disableUrlPreload: true`) - this option will be removed as soon as the url service is connected. You can disable the service in case you encounter a problem
- **the url service is not yet connected, we will connect the service step by step. The first version should be released to pre-catch bugs. The next version will add 503 handling if the url service is not ready and it will consume urls for resources.**
----
- the url service generates urls based on resources (posts, pages, users, tags)
- the url service keeps track of resource changes
- the url service keeps track of resource removal/insert
- the architecture:
- each routing type is represented by a url generator
- a routing type is a collection, a taxonomiy or static pages
- a queue which ensures that urls are unique and can be owned by one url generator
- the hierarchy of registration defines that
- we query knex, because bookshelf is too slow
- removed old url service files + logic
- added temp channels alternative (Channels2) -> this file will look different soon, it's for now the temporary connector to the url service. Also the name of the file is not optimal, but that is not really important right now.
2018-04-17 12:29:04 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos'
|
|
|
|
});
|
2018-11-26 12:28:22 +03:00
|
|
|
|
2020-05-25 11:49:38 +03:00
|
|
|
logging.error.calledOnce.should.be.true();
|
2019-08-19 14:41:09 +03:00
|
|
|
queue.toNotify.nachos.notified.length.should.eql(0);
|
Rewrite url service (#9550)
refs https://github.com/TryGhost/Team/issues/65
We are currently work on dynamic routing (aka channels).
An important piece of this feature is the url service, which always knows the url of a resource at any time.
Resources can belong to collections or taxonomies, which can be defined in a [routing yaml file](https://github.com/TryGhost/Ghost/issues/9528). We are currently shipping portions, which will at end form the full dynamic routing feature.
### Key Notes
- each routing type (collections, taxonomies, static pages) is registered in order - depending on the yaml routes file configuration
- static pages are an internal concept - they sit at the end of the subscriber queue
- we make use of a temporary [`Channels2`](https://github.com/TryGhost/Ghost/pull/9550/files#diff-9e7251409844521470c9829013cd1563) file, which simulates the current static routing in Ghost (this file will be modified, removed or whatever - this is one of the next steps)
- two way binding: you can ask for a resource url based on the resource id, you can ask for the resource based on the url
- in theory it's possible that multiple resources generate the same url: we don't handle this with collision (because this is error prone), we handle this with the order of serving content. if you ask the service for a resource, which lives behind e.g. /test/, you will get the resource which is served
- loose error handling -> log errors and handle instead of throw error and do nothing (we log the errors with a specific code, so we can react in case there is a bug)
- the url services fetches all resources on bootstrap. we only fetch and keep a reduced set of attributes (basically the main body of a resource)
- the bootstrap time will decrease a very little (depending on the amount of resources you have in your database)
- we still offer the option to disable url preloading (in your config `disableUrlPreload: true`) - this option will be removed as soon as the url service is connected. You can disable the service in case you encounter a problem
- **the url service is not yet connected, we will connect the service step by step. The first version should be released to pre-catch bugs. The next version will add 503 handling if the url service is not ready and it will consume urls for resources.**
----
- the url service generates urls based on resources (posts, pages, users, tags)
- the url service keeps track of resource changes
- the url service keeps track of resource removal/insert
- the architecture:
- each routing type is represented by a url generator
- a routing type is a collection, a taxonomiy or static pages
- a queue which ensures that urls are unique and can be owned by one url generator
- the hierarchy of registration defines that
- we query knex, because bookshelf is too slow
- removed old url service files + logic
- added temp channels alternative (Channels2) -> this file will look different soon, it's for now the temporary connector to the url service. Also the name of the file is not optimal, but that is not really important right now.
2018-04-17 12:29:04 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fn: start (with tolerance)', function () {
|
|
|
|
it('late subscriber', function (done) {
|
|
|
|
let notified = 0;
|
|
|
|
|
|
|
|
queue.addListener('ended', function (event) {
|
|
|
|
event.should.eql('nachos');
|
|
|
|
notified.should.eql(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos',
|
|
|
|
tolerance: 20,
|
|
|
|
timeoutInMS: 20
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.register({
|
|
|
|
event: 'nachos',
|
|
|
|
tolerance: 20
|
|
|
|
}, function () {
|
|
|
|
notified = notified + 1;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('start twice', function (done) {
|
|
|
|
let notified = 0;
|
|
|
|
let called = 0;
|
|
|
|
|
|
|
|
queue.addListener('ended', function (event) {
|
|
|
|
event.should.eql('nachos');
|
|
|
|
notified.should.eql(1);
|
|
|
|
called.should.eql(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos',
|
|
|
|
tolerance: 20,
|
|
|
|
timeoutInMS: 20
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.register({
|
|
|
|
event: 'nachos',
|
|
|
|
tolerance: 70
|
|
|
|
}, function () {
|
|
|
|
if (called !== 0) {
|
|
|
|
return done(new Error('Should only be triggered once.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
called = called + 1;
|
|
|
|
notified = notified + 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos',
|
|
|
|
tolerance: 20,
|
|
|
|
timeoutInMS: 20
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('start twice', function (done) {
|
|
|
|
let notified = 0;
|
|
|
|
let called = 0;
|
|
|
|
|
|
|
|
queue.addListener('ended', function (event) {
|
|
|
|
event.should.eql('nachos');
|
|
|
|
notified.should.eql(0);
|
|
|
|
called.should.eql(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos',
|
|
|
|
tolerance: 20,
|
|
|
|
timeoutInMS: 20
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos',
|
|
|
|
tolerance: 20,
|
|
|
|
timeoutInMS: 20
|
|
|
|
});
|
|
|
|
});
|
2018-06-07 10:14:58 +03:00
|
|
|
|
|
|
|
it('late subscribers', function (done) {
|
|
|
|
let notified = 0;
|
|
|
|
let called = 0;
|
|
|
|
|
|
|
|
queue.addListener('ended', function (event) {
|
|
|
|
event.should.eql('nachos');
|
|
|
|
notified.should.eql(1);
|
|
|
|
called.should.eql(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
queue.register({
|
|
|
|
event: 'nachos',
|
|
|
|
tolerance: 100,
|
|
|
|
timeoutInMS: 20,
|
|
|
|
requiredSubscriberCount: 1
|
|
|
|
}, function () {
|
|
|
|
called = called + 1;
|
|
|
|
notified = notified + 1;
|
|
|
|
});
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
queue.start({
|
|
|
|
event: 'nachos',
|
|
|
|
tolerance: 60,
|
|
|
|
timeoutInMS: 20,
|
|
|
|
requiredSubscriberCount: 1
|
|
|
|
});
|
|
|
|
});
|
Rewrite url service (#9550)
refs https://github.com/TryGhost/Team/issues/65
We are currently work on dynamic routing (aka channels).
An important piece of this feature is the url service, which always knows the url of a resource at any time.
Resources can belong to collections or taxonomies, which can be defined in a [routing yaml file](https://github.com/TryGhost/Ghost/issues/9528). We are currently shipping portions, which will at end form the full dynamic routing feature.
### Key Notes
- each routing type (collections, taxonomies, static pages) is registered in order - depending on the yaml routes file configuration
- static pages are an internal concept - they sit at the end of the subscriber queue
- we make use of a temporary [`Channels2`](https://github.com/TryGhost/Ghost/pull/9550/files#diff-9e7251409844521470c9829013cd1563) file, which simulates the current static routing in Ghost (this file will be modified, removed or whatever - this is one of the next steps)
- two way binding: you can ask for a resource url based on the resource id, you can ask for the resource based on the url
- in theory it's possible that multiple resources generate the same url: we don't handle this with collision (because this is error prone), we handle this with the order of serving content. if you ask the service for a resource, which lives behind e.g. /test/, you will get the resource which is served
- loose error handling -> log errors and handle instead of throw error and do nothing (we log the errors with a specific code, so we can react in case there is a bug)
- the url services fetches all resources on bootstrap. we only fetch and keep a reduced set of attributes (basically the main body of a resource)
- the bootstrap time will decrease a very little (depending on the amount of resources you have in your database)
- we still offer the option to disable url preloading (in your config `disableUrlPreload: true`) - this option will be removed as soon as the url service is connected. You can disable the service in case you encounter a problem
- **the url service is not yet connected, we will connect the service step by step. The first version should be released to pre-catch bugs. The next version will add 503 handling if the url service is not ready and it will consume urls for resources.**
----
- the url service generates urls based on resources (posts, pages, users, tags)
- the url service keeps track of resource changes
- the url service keeps track of resource removal/insert
- the architecture:
- each routing type is represented by a url generator
- a routing type is a collection, a taxonomiy or static pages
- a queue which ensures that urls are unique and can be owned by one url generator
- the hierarchy of registration defines that
- we query knex, because bookshelf is too slow
- removed old url service files + logic
- added temp channels alternative (Channels2) -> this file will look different soon, it's for now the temporary connector to the url service. Also the name of the file is not optimal, but that is not really important right now.
2018-04-17 12:29:04 +03:00
|
|
|
});
|
|
|
|
});
|