Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@qrvey/scheduler

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qrvey/scheduler

Library to schedule the datasync cronjobs

  • 0.0.9
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Qrvey scheduler

This is a library to use AWS Eventbridge, k8s scheduler or K8s jobs.

Installation

npm install @qrvey/scheduler

Require environment variables

AWS_ACCOUNT_ID; //AWS AccountId to send EventBridge service
AWS_DEFAULT_REGION; //AWS Region for EventBridge service
PLATFORM_TYPE; //Platform type (possible value CONTAINER)
CRONJOB_NAMESPACE //This env variable is required for k8s scheduler

Usage

Sample usage for scheduler

const { SchedulerService } = require("@qrvey/scheduler");

(async () => {
    const scheduleParams = {
        cronJobName: "multicloud-testcron",
        scheduleExpression: "cron(*/1 * * * * *)",
        description:
            '{"userEmail":"email@useremail.com","datasetName":"DBName","appName":"AppName","readableCronExpr":"Every hour","owner":"ownerId","datasetId":"datasetId","userId":"userId","appId":"appId"}',
        targetParams: {
            Name: "demo_drScheduler_CJ_mra43sr0U",
            Input: {
                detail: {
                    appId: "appId",
                    userId: "userId",
                    owner: "owner",
                    datasetId: "datasetId",
                    cronSyncFrequency: "0 0/1 * * ? *",
                    version: 2.1,
                },
                source: "aws.events",
            },
        },
        tags: [
            {
                Key: "version",
                Value: "2.1",
            },
            {
                Key: "datasetId",
                Value: "datasetId",
            },
            {
                Key: "appId",
                Value: "appId",
            },
            {
                Key: "userId",
                Value: "userId",
            },
            {
                Key: "state",
                Value: "ENABLED",
            },
            {
                Key: "owner",
                Value: "userId",
            },
        ],
        targetResource: "arn:aws:lambda:{region}:{accountId}:function:{functionName}", //For ks8 scheduler the targetRosource will be the entire container url
        state: "DISABLED",
    };

    const schedulerClient = new schedulerService();
    const res = await schedulerClient.create(scheduleParams);
})();

Sample usage for tasks

Create task
const { TaskService } = require('@qrvey/scheduler');

const main = async () => {
    try {
        const namespace = 'service-app';
        const jobManifest = {
            taskName: 'task-name',
            containerName: 'container-name',
            description: 'this is to run a task',
            image: `image_service_registry_container/image_name:latest`, // image to pull from registry container service
            imagePullSecret: 'image-secret', // secret access to pull the image
            environmentVariables: [ // env variables to pass for the job container
                { name: 'SERVER', value: 'some_prefix' },
                { name: 'NUMBER_OF_TYPES', value: 5 },
                { name: 'PLATFORM', value: 'AZURE' },
            ],
            arguments: [ // arguments that you can get in the container 
                { name: '--operation', value: 'getNames' },
                { name: '--id', value: 'mdK23ds' },
                { name: '--version', value: 'published' },
            ],
            command: ['node', 'index.js'], // command to run
        };
        const newJob = new TaskService();
        return await newJob.create(namespace, jobManifest);
        /*  
            {
                'annotations'?: {
                    [key: string]: string;
                };
                'creationTimestamp'?: Date;
                'deletionGracePeriodSeconds'?: number;
                'deletionTimestamp'?: Date;
                'finalizers'?: Array<string>;
                'generateName'?: string;
                'generation'?: number;
                'labels'?: {
                    [key: string]: string;
                };
                'managedFields'?: Array<V1ManagedFieldsEntry>;
                'name'?: string;
                'namespace'?: string;
                'ownerReferences'?: Array<V1OwnerReference>;
                'resourceVersion'?: string;
                'selfLink'?: string;
                'uid'?: string;
            }
        */
    } catch (error) {
        console.error(error);
    }
}

main();
Get Task
const { TaskService } = require('@qrvey/scheduler');

const main = async () => {
    try {

        const namespace = 'namespace';
        const jobName = 'remove-something';

        const getJob = new TaskService();
        return await getJob.get(namespace, jobName);
        /*
        {
            statusCode: 200,
            metadata: {
                'annotations'?: {
                    [key: string]: string;
                };
                'creationTimestamp'?: Date;
                'deletionGracePeriodSeconds'?: number;
                'deletionTimestamp'?: Date;
                'finalizers'?: Array<string>;
                'generateName'?: string;
                'generation'?: number;
                'labels'?: {
                    [key: string]: string;
                };
                'managedFields'?: Array<V1ManagedFieldsEntry>;
                'name'?: string;
                'namespace'?: string;
                'ownerReferences'?: Array<V1OwnerReference>;
                'resourceVersion'?: string;
                'selfLink'?: string;
                'uid'?: string;
            },
            status: {
                'active'?: number;
                'completedIndexes'?: string;
                'completionTime'?: Date;
                'conditions'?: Array<V1JobCondition>;
                'failed'?: number;
                'failedIndexes'?: string;
                'ready'?: number;
                'startTime'?: Date;
                'succeeded'?: number;
                'terminating'?: number;
                'uncountedTerminatedPods'?: V1UncountedTerminatedPods;
            },
        }
        */
    } catch (error) {
        console.error(error);
    }
}
main();
List Tasks
const { TaskService } = require('@qrvey/scheduler');

const main = async () => {
    try {
        const namespace = 'namespace';
        const listJobs = new TaskService();
        return await listJobs.list(namespace);
        /*
            [
                "remove-orphan-data",
                "migrate-database-data",
                "api-data",
            ]
        */
    } catch (error) {
        console.error(error);
    }
}
main();
Delete Task
const { TaskService } = require('@qrvey/scheduler');

const main = async () => {
    try {
        const namespace = 'namespace';
        const jobName = 'remove-something';

        const deleteJob = new TaskService();
        return await deleteJob.delete(namespace, jobName);
        /*
            {
                'apiVersion'?: string;
                'code'?: number;
                'details'?: V1StatusDetails;
                'kind'?: string;
                'message'?: string;
                'metadata'?: V1ListMeta;
                'reason'?: string;
                'status'?: string;
            }
        */
    } catch (error) {
        console.error(error);
    }
}
main();

FAQs

Package last updated on 14 Nov 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc