![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@therms/future-queue
Advanced tools
A MongoDB queue service for Node.js with scheduling, updating/removing queued items and retries
FutureQueue is a lightweight scheduling service built on Node.js and MongoDB that allows you to enqueue messages for future processing. It’s ideal for scenarios where you need to defer tasks—such as sending reminder emails or processing deferred jobs—while also handling retries, cancellations, and failures via a dead-letter queue.
Note: FutureQueue requires Node.js 20+ and a MongoDB instance.
Install FutureQueue via npm:
npm install future-queue
FutureQueue provides two main classes:
The Producer is used to schedule messages. Each message is defined by a unique key and contains custom data. You can specify when the message should be processed, set an expiration, or configure retry options.
import { Producer } from 'futurequeue';
const queueName = 'email-reminders';
const producer = new Producer(queueName, {
mongo: {
uri: 'mongodb://localhost:27017/your-db-name', // Or pass a connected MongoClient instance
},
});
// Schedule a reminder email to be sent in 3 days
const threeDaysFromNow = new Date();
threeDaysFromNow.setDate(threeDaysFromNow.getDate() + 3);
await producer.add(
{
key: 'reminder-email-user-123',
data: { email: 'user@example.com', subject: 'Reminder', body: 'Your subscription expires soon!' },
},
{
readyTime: threeDaysFromNow,
retries: 2, // Maximum retry attempts before moving to dead-letter queue
},
);
// Retrieve the scheduled message by its key
const message = await producer.getByKey('reminder-email-user-123');
console.log('Retrieved message:', message);
// Update message data if needed
await producer.updateByKey('reminder-email-user-123', {
data: { email: 'user@example.com', subject: 'Updated Reminder', body: 'Please check your subscription!' },
});
// Cancel the scheduled message
await producer.cancelByKey('reminder-email-user-123');
// Gracefully shut down the producer
await producer.shutdown();
The Consumer listens for messages that are ready to be processed. You define a handler function to process each message. The handler receives helper functions to extend the processing lock and update progress.
import { Consumer } from 'futurequeue';
const queueName = 'email-reminders';
const consumer = new Consumer(queueName, {
mongo: {
uri: 'mongodb://localhost:27017/your-db-name',
},
});
// Define the message processing handler
consumer.processMessages(async (message, { extendMsgHandlingLock, updateMsgHandlerProgress }) => {
// Simulate processing by updating progress
await updateMsgHandlerProgress({ percentComplete: 50 });
// Process the message (e.g., send an email)
console.log(`Processing message with key: ${message.key}`, message.data);
// Optionally extend the processing lock if processing takes longer than expected
// await extendMsgHandlingLock();
// Mark the processing as complete
await updateMsgHandlerProgress({ percentComplete: 100 });
});
// Optionally, register an idle callback
consumer.processMessages(
async (message) => {
console.log(`Processed: ${message.key}`);
},
{
onQueueIdle: () => {
console.log('The queue is currently idle.');
},
},
);
// When your application is shutting down, gracefully close the consumer
await consumer.shutdown();
new Producer(queueName: string, options: ProducerOptions)
add(message: QueueMessage | QueueMessage[], options?: { readyTime?: Date; expireTime?: Date; retries?: number; })
Adds one or more messages to the queue.
getByKey(key: string)
Retrieves a scheduled message by its unique key.
cancelByKey(key: string)
Cancels (deletes) a scheduled message from the queue.
updateByKey(key: string, update: Partial<QueueMessage>)
Updates properties of a scheduled message.
totalReadyMessages()
Returns the count of messages that are ready to be processed immediately.
totalFutureMessages()
Returns the count of messages scheduled for future processing.
shutdown()
Gracefully shuts down the producer and releases any held resources.
new Consumer(queueName: string, options: ConsumerOptions)
processMessages(handler: (message: ReadyQueueMessage, helpers?: MessageProcessingHelpers) => Promise<void>, options?: { onQueueIdle?: () => void; })
Registers a message processing handler.
The handler receives:
extendMsgHandlingLock()
: Function to extend the lock on the message.updateMsgHandlerProgress(progress: any)
: Function to update the progress of message processing.totalFutureMessages()
Returns the count of messages still scheduled for future processing.
shutdown()
Gracefully shuts down the consumer.
Schedule reminder emails to be sent at a future date. For example, schedule an email to be sent 3 days before a user's subscription expires.
Enqueue background tasks—such as data processing, notifications, or report generation—to run during off-peak hours.
Automatically retry tasks that fail during processing. If a task fails after the configured number of retries, it is moved to a dead-letter queue for further investigation.
Scale your application by deploying multiple consumer instances. The locking mechanism ensures that each message is processed only once, even when multiple consumers are polling the queue.
FAQs
A MongoDB queue service for Node.js with scheduling, updating/removing queued items and retries
We found that @therms/future-queue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.