npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gromo-fintech/task-scheduler

v1.2.0

Published

A library to schedule task

Downloads

139

Readme

@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.