@contentstack/datasync-manager 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +63 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -162,7 +162,9 @@ const start = (config = {}) => {
162
162
  // start checking for inet 10 secs after the app has started
163
163
  (0, inet_1.init)();
164
164
  return listener.start(appConfig);
165
- }).then(() => {
165
+ }).then((webhookServer) => {
166
+ // Set up webhook listener monitoring and fallback mechanism
167
+ setupWebhookMonitoring(webhookServer);
166
168
  logger_1.logger.info(messages_1.MESSAGES.INDEX.SYNC_UTILITY_STARTED);
167
169
  return resolve('');
168
170
  }).catch(reject);
@@ -190,3 +192,63 @@ q_1.notifications
190
192
  .on('unpublish', (0, exports.debugNotifications)('unpublish'))
191
193
  .on('delete', (0, exports.debugNotifications)('delete'))
192
194
  .on('error', (0, exports.debugNotifications)('error'));
195
+ /**
196
+ * Set up webhook listener monitoring and fallback polling mechanism
197
+ * @param {object} webhookServer The webhook server instance
198
+ */
199
+ function setupWebhookMonitoring(webhookServer) {
200
+ const FALLBACK_POLL_INTERVAL = 60000; // 1 minute fallback polling
201
+ let fallbackTimer = null;
202
+ let webhookHealthy = true;
203
+ debug('Webhook monitoring initialized. Server:', !!webhookServer, 'Healthy:', webhookHealthy);
204
+ // Start fallback polling when webhook is unhealthy
205
+ const startFallbackPolling = () => {
206
+ if (fallbackTimer)
207
+ return; // Already running
208
+ logger_1.logger.info(`Starting fallback polling every ${FALLBACK_POLL_INTERVAL}ms`);
209
+ fallbackTimer = setInterval(() => {
210
+ debug('Fallback polling: triggering sync check');
211
+ try {
212
+ (0, index_1.poke)().catch((error) => {
213
+ debug('Fallback polling error:', error);
214
+ });
215
+ }
216
+ catch (error) {
217
+ debug('Fallback polling exception:', error);
218
+ }
219
+ }, FALLBACK_POLL_INTERVAL);
220
+ };
221
+ // Stop fallback polling when webhook is healthy
222
+ const stopFallbackPolling = () => {
223
+ if (fallbackTimer) {
224
+ clearInterval(fallbackTimer);
225
+ fallbackTimer = null;
226
+ logger_1.logger.info('Fallback polling stopped');
227
+ }
228
+ };
229
+ // Webhook activity is tracked via events, no need to wrap poke function
230
+ // Handle process cleanup
231
+ const cleanup = () => {
232
+ if (fallbackTimer) {
233
+ clearInterval(fallbackTimer);
234
+ fallbackTimer = null;
235
+ }
236
+ };
237
+ process.on('SIGINT', cleanup);
238
+ process.on('SIGTERM', cleanup);
239
+ process.on('exit', cleanup);
240
+ // Handle webhook server events if available
241
+ if (listener.getEventEmitter) {
242
+ const webhookEmitter = listener.getEventEmitter();
243
+ webhookEmitter.on('server-error', (error) => {
244
+ logger_1.logger.warn('Webhook server error detected:', error.message);
245
+ webhookHealthy = false;
246
+ startFallbackPolling();
247
+ });
248
+ webhookEmitter.on('reconnect-success', () => {
249
+ logger_1.logger.info('Webhook server reconnected successfully');
250
+ webhookHealthy = true;
251
+ stopFallbackPolling();
252
+ });
253
+ }
254
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/datasync-manager",
3
3
  "author": "Contentstack LLC <support@contentstack.com>",
4
- "version": "2.1.3",
4
+ "version": "2.2.0",
5
5
  "description": "The primary module of Contentstack DataSync. Syncs Contentstack data with your server using Contentstack Sync API",
6
6
  "main": "dist/index.js",
7
7
  "dependencies": {