How to use the @pulumi/cloud.Topic function in @pulumi/cloud

To help you get started, we’ve selected a few @pulumi/cloud 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 pulumi / pulumi-cloud / examples / countdown / index.ts View on Github external
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as pulumi from "@pulumi/cloud";

let countDown = new pulumi.Topic("examples-countDown");

countDown.subscribe("watcher", async (num) => {
    console.log(num);
    if (num > 0) {
        await countDown.publish(num - 1);
    }
});

pulumi.timer.interval("examples-heartbeat", {minutes: 3}, async () => {
    await countDown.publish(25);
});
github pulumi / pulumi-cloud / examples / crawler / index.ts View on Github external
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as cloud from "@pulumi/cloud";
import * as nodeFetchModule from "node-fetch";
import { canonicalUrl, hostname} from "./support";
import * as express from "express";

// Pending sites to be processed
let sites = new cloud.Topic("examples-sites-to-process");

// Documents and associated metadata for crawled sites
let documents = new cloud.Table("examples-documents");

// Front end API and console
let frontEnd = new cloud.HttpServer("examples-crawler-front-end", () => {
    const app = express();

    app.post("/queue", async (req, res) => {
        let url = req.body.toString();
        console.log(`Pushing ${url} to processing queue`);
        await sites.publish(url);
        res.status(200).json("success");
    });

    app.get("/documents/stats", async (_, res) => res.json({count: (await documents.scan()).length}));
github pulumi / pulumi-cloud / examples / integration / digest.ts View on Github external
constructor(name: string, stream: cloud.Stream) {
        this.topic = new cloud.Topic(name);
        this.table = new cloud.Table(name);

        stream.subscribe(name, async (item) => {
            let value = JSON.stringify(item);
            console.log(utils.toShortString(`Adding item to digest table: ${value}`));
            await this.table.insert({ id: value });
        });

        this.collect = async () => {
            console.log(`Collecting digest...`);

            let items = await this.table.scan();
            let ret: T[] = [];
            for (let item of items) {
                ret.push(JSON.parse(item.id));
                await this.table.delete({ id: item.id });
github pulumi / pulumi-cloud / examples / integration / poll.ts View on Github external
export function poll(name: string, rate: cloud.timer.IntervalRate, poller: PollFunction): cloud.Stream {
    let topic = new cloud.Topic(name);

    cloud.timer.interval(name, rate, async () => {
        console.log(`Starting polling...`);

        console.log(`Getting pollMarker for ${name}`);
        let pollMarker = await pollMarkers.get({id: name});
        console.log(`pollMarker is ${JSON.stringify(pollMarker, null, "")}`);

        let lastToken: string | undefined;
        if (pollMarker !== undefined) {
            lastToken = pollMarker.lastToken;
        }

        console.log(`lastToken is ${lastToken}`);

        console.log("Polling for results...");

@pulumi/cloud

A highly productive, cloud neutral programming model.

Apache-2.0
Latest version published 10 months ago

Package Health Score

72 / 100
Full package analysis