How to use the faastjs.faast function in faastjs

To help you get started, we’ve selected a few faastjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github faastjs / faast.js / examples / map-buckets.ts View on Github external
export async function mapBucket(Bucket: string, keyFilter: (key: string) => boolean) {
    const faastModule = await faast("aws", m, {
        memorySize: 2048,
        timeout: 300,
        mode: "queue",
        concurrency: 2000,
        childProcess: true,
        gc: "off"
        // awsLambdaOptions: { TracingConfig: { Mode: "Active" } }
    });
    console.log(`Logs: ${faastModule.logUrl()} `);
    faastModule.on("stats", s => {
        console.log(`${s}`);
    });

    const bandwidth = new Statistics();

    try {
github faastjs / faast.js / examples / cost-estimate.ts View on Github external
(async () => {
    const m = await faast("aws", funcs);
    await m.functions.hello("world");
    const cost = await m.costSnapshot();
    console.log(`hello world cost: $${cost.total()}`);
    // hello world cost: $0.0000030596957398557663
    await m.cleanup();
})();
github faastjs / faast.js / examples / invoke-1000.ts View on Github external
(async () => {
    const m = await faast("aws", funcs);
    const promises = [];
    // Summon 1000 cores
    for (let i = 0; i < 1000; i++) {
        promises.push(m.functions.hello("world " + i));
    }
    await Promise.all(promises);
    await m.cleanup();
})();
github faastjs / examples / aws-sharp-ts / index.ts View on Github external
async function main() {
    const m = await faast("aws", funcs, {
        packageJson: {
            dependencies: {
                sharp: "latest"
            }
        }
    });
    try {
        const rv = await m.functions.runSharp();
        writeFileSync("output.png", rv);
        console.log(`wrote output.png`);
    } finally {
        await m.cleanup();
    }
}
github faastjs / examples / hello-world-js / index.js View on Github external
async function main() {
    const m = await faast("local", funcs);
    try {
        const result = await m.functions.hello("world");
        console.log(result);
    } finally {
        await m.cleanup();
    }
}
github faastjs / faast.js / examples / map-buckets.ts View on Github external
export async function emptyBucket(Bucket: string) {
    const faastModule = await faast("aws", m, {
        memorySize: 256,
        timeout: 300,
        mode: "https",
        concurrency: 1
    });
    const objects = await listAllObjects(Bucket);
    console.log(`Emptying Bucket ${Bucket} with ${objects.length} keys`);
    const promises: Promise[] = [];
    while (true) {
        const keys = objects.splice(0, 100).map(obj => obj.Key!);
        if (keys.length === 0) {
            break;
        }
        promises.push(faastModule.functions.deleteObjects(Bucket, keys));
    }
    await Promise.all(promises);
github faastjs / faast.js / examples / map-buckets.ts View on Github external
export async function mapObjects(Bucket: string, Keys: string[]) {
    const faastModule = await faast("aws", m, {
        memorySize: 1728,
        timeout: 300,
        mode: "https",
        concurrency: 1
    });
    for (const Key of Keys) {
        await faastModule.functions
            .processBucketObject(Bucket, Key)
            .catch(err => console.error(err));
        console.log(`Processed ${Bucket}/${Key}`);
    }
    await faastModule.cleanup();
}