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

@qrvey/scheduler

v0.0.8

Published

Library to schedule the datasync cronjobs

Downloads

1,357

Readme

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 protected]","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();