Skip to content

Scheduled publishing

For use with Netlify Visual Editor only.

If your data source supports scheduled publishing, you can add logic for handling scheduled actions to your connector using connector.scheduledActions().

Netlify will check for the presence of all scheduled action methods to verify that scheduled publishing is supported with the visual editor.

Add support for scheduled actions

To support scheduled actions, you must implement mutation handlers using connector.scheduledActions(). Netlify will call these functions when users manage scheduled actions in the visual editor.

We recommend that you configure your connector to support updating scheduled actions using webhooks to help ensure updates propagate back into the connector.

For example:

const connector = extension.addConnector({
initState: () => {
const myCMSClient = new MyCMSClient();
myCMSClient.createWebhook({
url: `http://localhost:8000/__refresh`,
});
return { myCMSClient };
},
});
// If any of these methods fail, you may throw an error;
// we'll catch and log it appropriately.
connector.scheduledActions({
create: ({ scheduledAction, state: { myCMSClient } }) => {
const result = await state.apiClient.createScheduledAction({
action: scheduledAction.action,
documentIds: scheduledAction.documentIds,
executeAt: scheduledAction.executeAt,
name: scheduledAction.name,
});
return { id: result.id };
},
delete: ({ scheduledAction, state: { myCMSClient } }) => {
const result = await state.apiClient.deleteScheduledAction({
id: scheduledAction.id,
});
return { id: result.id };
},
update: ({ scheduledAction, state: { myCMSClient } }) => {
const result = await state.apiClient.updateScheduledAction({
id: scheduledAction.id,
documentIds: scheduledAction.documentIds,
executeAt: scheduledAction.executeAt,
name: scheduledAction.name,
});
return { id: result.id };
},
});

Sync scheduled actions data

To load scheduled actions data into the user’s site, use the models.ScheduledAction interface that is exposed to the connector.sync callback.

For example:

const connector = extension.addConnector({
initState: () => {
const myCMSClient = new MyCMSClient();
return { myCMSClient };
},
});
connector.sync(({, isInitialSync, models: { ScheduledAction }, state: { myCMSClient } }) => {
if (isInitialSync) {
const data = await myCMSClient.getAllScheduledActions();
ScheduledAction.insert(
data.map(({ id, documentIds, executeAt, name }) => {
return {
id,
documentIds,
executeAt,
name,
};
}),
);
}
});

If your data source supports webhooks, you may trigger updates to scheduled actions data using incoming webhooks. We’ll invoke the sync method in response to an incoming webhook:

const connector = extension.addConnector({
initState: () => {
const myCMSClient = new MyCMSClient();
myCMSClient.createWebhook({
url: `http://localhost:8000/__refresh`,
});
return { myCMSClient };
},
});
connector.sync(({ cache, isInitialSync, models, state: { myCMSClient } }) => {
if (!isInitialSync) {
const lastSyncTime = await cache.get("lastSync");
// Fetch data that changed since the last time we ran a sync
const cmsData = await myCMSClient.getData({ since: lastSyncTime });
for (const model of models) {
model.create(cmsData[model.name]);
}
// As a final step, we set the lastSync value to now.
await cache.set("lastSync", Date.now());
}
});

Got it!

Your feedback helps us improve our docs.