1.2.0 • Published 3 months ago

@gromo-fintech/task-scheduler v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

@gromo-fintech/task-scheduler

@gromo-fintech/task-scheduler is a powerful and scalable task scheduling library designed specifically for the fintech industry. It utilizes Amazon Simple Queue Service (SQS) to manage and process tasks, ensuring robustness and flexibility.

Features

  • SQS-Based Scheduling: Leveraging the power of Amazon SQS, it offers reliable and efficient task management.
  • Scalability: Built with scalability in mind, capable of handling large volumes of tasks without compromise.
  • Flexibility: Easily configurable to suit various fintech applications and workflows.
  • Monitoring and Logging: In-depth monitoring and logging capabilities to keep track of all the scheduled tasks.

Installation

You can install the package using npm:

npm install @gromo-fintech/task-scheduler

Usage

You can use this package by importing it into your project as follows:

const { Scheduler, TaskSchedulerConfiguration } = require('@gromo-fintech/task-scheduler/build');

const config = {
  // Your SQS configuration here
  QUEUE_URL: 'your-queue-url',
  QUEUE_NAME: 'your-queue-name',
  TASK_STORAGE: 'your-task-storage',
  AWS_ACCESS_KEY_ID: 'your-access-key-id',
  AWS_ACCESS_KEY: 'your-access-key',
  AWS_REGION: 'your-region',
};

const taskScheduler = Scheduler.getInstance("sqs", TaskSchedulerConfiguration.getInstance(config));

Make sure to replace the placeholders with your actual AWS and SQS configuration.

Creating a Task

First we would need to define a task. We are taking Initiate Money Transfer Task.

const initiateMoneyTransferTask = new InitiateMoneyTransferTask({
    name: "initiate-money-transfer",
    config: {
        task_type: "initiate-money-transfer-task",
        status: "OPEN",
        retry_count: 0,
        max_retry_limit: 10,
        idempotency_key: "woooo",
        execution_delay: 0,
        interval_type: "linear",
        interval_period_in_sec: 9,
        request: Date().toString(),
    },
    request: {
        fromAccount: 'A123456789',
        toAccount: 'B987654321',
        amount: 1000.00,
        currency: 'INR',
        transferDate: '2023-08-02T12:30:00',
        note: 'Monthly Rent Payment',
    },
    registerExecute: "call-back-function-name",
    registerExecutePath: "call-back-function-path.js",
})
try {
    await taskScheduler.createTask(initiateMoneyTransferTask);
} catch (e) {
    console.log('Unable to create task')
}

Starting the Task Consumer

The SQSConsumerTask class provides an interface to consume tasks from an SQS queue and execute them. It encapsulates all the necessary configuration and handling logic.

Configuration

You can set up the SQSConsumerTask by creating an instance and passing the necessary configuration through the TaskSchedulerConfiguration class. You can write this in bootstrap() function NestJs, eny function which is the entry point of the app.

import TaskSchedulerConfiguration from "./config/config";
import SQSConsumerTask from "./path/to/SQSConsumerTask";

const config = new TaskSchedulerConfiguration({
  QUEUE_URL: 'your-queue-url',
  QUEUE_NAME: 'your-queue-name',
  AWS_REGION: 'your-region',
  AWS_ACCESS_KEY_ID: 'your-access-key-id',
  AWS_ACCESS_KEY: 'your-secret-access-key',
});

const consumerTask = new SQSConsumerTask(config);

Starting the Consumer

Once you've configured the SQSConsumerTask, you can start consuming tasks by calling the start method:

consumerTask.start();

This method sets up an SQS consumer, defines the handling logic for incoming tasks, and starts listening to the configured queue. Messages that are successfully processed are deleted from the queue. Handling Tasks

The handleMessage method within SQSConsumerTask defines how each task is executed. It extracts the task details from the incoming message and invokes the corresponding executor function:

  • Parse the incoming message and instantiate the appropriate task executor.
  • Determine the file path for the executor function and dynamically import it.
  • Call the imported execute method with the required task registration request.
  • If an error occurs, the task is postponed for re-execution based on the defined interval type (LINEAR or EXPONENTIAL).

Task Execution Logic

To define the actual logic of a specific task, you will need to provide the appropriate execute method in the corresponding file referenced by getRegisterExecutePath. The logic inside this function will depend on the specific requirements of the task being handled.

This documentation provides an overview of how to start the task consumer and outlines the processing flow for consuming and executing tasks. It may be extended further with additional details and examples as needed for your specific application or use case.

Support

If you encounter any issues, please file an issue on our GitHub repository or contact our support.

Gromo Fintech

Gromo Fintech is a leading innovator in financial technology solutions. Our task-scheduler library is part of our commitment to providing robust and scalable solutions for the fintech industry.

Contributions to this project are welcome! For inquiries and support, please reach out to us using the above contact details.

Authors

Anand Keshri

Head of Technology
Anand Keshri leads the technology division, steering the design and architecture of the solution. His vision and expertise have been instrumental in shaping the robust and scalable nature of @gromo-fintech/task-scheduler.

Saket Anand

Lead Engineer
Saket Anand is the lead engineer behind the @gromo-fintech/task-scheduler. With a deep focus on leveraging Amazon SQS, his work has been central to the efficient task management provided by this library.

Paramdeep

Senior Engineer
Paramdeep, a Senior Engineer on the team, has played a significant role in optimizing the solution. His engineering skills have ensured the tool's reliability and high performance.

Rajan Walia

Software Development Engineer 1 (SDE 1)
Rajan Walia, as an SDE 1, has contributed to the development, testing, and improvement of the package. His dedication and effort have helped maintain the high standards of the codebase.


Feel free to reach out with questions, issues, or contributions related to this project.

1.2.0

3 months ago

1.1.5

3 months ago

1.1.4

3 months ago

1.1.3

3 months ago

1.1.2

4 months ago

1.1.1

7 months ago

1.1.0

8 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago