Skip to content

Commit 16edca1

Browse files
authored
docs: update readme with for redundant services (#221)
1 parent 25187e4 commit 16edca1

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,53 @@ export default ({ env }: { env: (key: string, def?: any) => any }) => ({
123123

124124
The `cron.enabled` configuration option needs to be set to true in [Server Configuration](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/required/server.html#server-configuration) for the plugin to work.
125125

126+
### Multi-instance / clustered deployments
127+
128+
When Strapi runs on multiple containers or nodes (for example ECS, Kubernetes, or other redundant services), the same scheduled action may be executed more than once.
129+
This behavior is discussed in [issue #194](https://github.com/pluginpal/strapi-plugin-publisher/issues/194).
130+
131+
Common workarounds reported in that issue include:
132+
133+
- use `beforePublish` and `beforeUnpublish` to allow only one instance to execute the action
134+
- use a shared lock such as Redis
135+
- use database row locking on the `actions` table
136+
137+
Since `strapi-plugin-publisher@2.0.4`, returning `false` from `beforePublish` and `beforeUnpublish` cleanly aborts the action without throwing an error. This makes it possible to implement your own coordination logic in multi-instance deployments.
138+
139+
```javascript
140+
module.exports = ({ env }) => ({
141+
publisher: {
142+
enabled: true,
143+
config: {
144+
hooks: {
145+
beforePublish: async ({ strapi, uid, entity }) => {
146+
const shouldRunOnThisInstance = env.bool('PLUGIN_PUBLISHER_ENABLED', false);
147+
148+
if (!shouldRunOnThisInstance) {
149+
strapi.log.info(`Skipping publish for ${uid}:${entity.documentId} on this instance.`);
150+
return false;
151+
}
152+
153+
return true;
154+
},
155+
beforeUnpublish: async ({ strapi, uid, entity }) => {
156+
const shouldRunOnThisInstance = env.bool('PLUGIN_PUBLISHER_ENABLED', false);
157+
158+
if (!shouldRunOnThisInstance) {
159+
strapi.log.info(`Skipping unpublish for ${uid}:${entity.documentId} on this instance.`);
160+
return false;
161+
}
162+
163+
return true;
164+
},
165+
},
166+
},
167+
},
168+
});
169+
```
170+
171+
For example, some teams use an environment variable to let only one instance proceed, while others use Redis locking or transactional row locking (`FOR UPDATE NOWAIT`) on the `actions` table. See [issue #194](https://github.com/pluginpal/strapi-plugin-publisher/issues/194) for additional background and implementation details.
172+
126173
## Usage
127174

128175
Once the plugin has been installed, configured and enabled a `Publisher` section will be added to the `informations` section of the edit view for all content types (single + collection) that have `draftAndPublish` enabled. The `Publisher` section will provide the ability to schedule publishing and unpublishing of the content type. The content type publication status is checked every minute.

0 commit comments

Comments
 (0)