Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function exampleTwitter2() {
console.log("Running Twitter example 2...");
// Get a stream of all tweets matching this query, forever...
let tweets: cloud.Stream = twitter.search("pulumi", "vscode");
// Collect them into bunches
let digest = new Digest("tweetdigest", tweets);
// Every night, take all of the tweets collected since the
// last digest and publish that as a group to the digest stream.
cloud.timer.daily("nightly", { hourUTC: 7 }, async () => {
await digest.collect();
});
// For every group of tweets published to the digest stream (nightly)
// send an email.
digest.subscribe("digest", async (dailyTweets) => {
if (dailyTweets.length === 0) {
console.log("No new tweets...");
return;
}
console.log(`Received ${dailyTweets.length} new tweets. Sending email...`);
// Arbitrary code to compose email body - could use templating system or
// any other programmatic way of constructing the text.
let text = "Tweets:\n";
// 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);
});
found = await documents.get({id: link});
if (!found) {
console.log(`${url}: Publishing new url: ${link}`);
await sites.publish(link);
}
}
// Register that we completed publishing all referened URLs from this site. We can recover from
// failures by re-crawling any sites with `crawlInProgress == true`.
await documents.update({ id: url }, { crawlInProgress: false, crawlFinishedDate: Date.now() });
console.log("Succeed url: " + url);
});
// Periodically check for any URLs which did not complete processing
// and try them again (for example, in case they failed due to throttling).
cloud.timer.interval("cleanup", {minutes: 5}, async () => {
console.log(`Cleanup: starting cleanup.`);
let cleanupCount = 0;
let alldocs = await documents.scan();
console.log(`Cleanup: scan returned ${alldocs.length} documents.`);
for (let doc of alldocs) {
if (doc.crawlInProgress) {
await sites.publish(doc.id);
cleanupCount++;
}
}
console.log(`Cleanup: restarted ${cleanupCount} items.`);
});
//
// 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 pulumi from "@pulumi/pulumi";
let config = new pulumi.Config("timers:config");
let message = config.require("message");
cloud.timer.interval("examples-test-interval1", { minutes: 1 }, async () => {
console.log(`test-interval[${Date.now()}]: ${message}`);
});
cloud.timer.interval("examples-test-interval2", { minutes: 59 }, async () => {
console.log(`test-interval[${Date.now()}]: ${message}`);
});
cloud.timer.interval("examples-test-interval3", { minutes: 120 }, async () => {
console.log(`test-interval[${Date.now()}]: ${message}`);
});
cloud.timer.interval("examples-test-interval4", { minutes: 120, hours: 2 }, async () => {
console.log(`test-interval[${Date.now()}]: ${message}`);
});
cloud.timer.interval("examples-test-interval5", { days: 24 }, async () => {
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...");
let results = await poller(lastToken);
console.log(`test-interval[${Date.now()}]: ${message}`);
});
cloud.timer.interval("examples-test-interval7", { hours: 23, minutes: 59 }, async () => {
console.log(`test-interval[${Date.now()}]: ${message}`);
});
cloud.timer.cron("examples-test-cron", "* * * * ? *", async () => {
console.log(`test-cron[${Date.now()}]: ${message}`);
});
cloud.timer.daily("examples-test-daily", { hourUTC: 7, minuteUTC: 30 }, async () => {
console.log(`test-daily[${Date.now()}]: ${message}`);
});
cloud.timer.hourly("examples-test-hourly", { minuteUTC: 45 }, async () => {
console.log(`test-hourly[${Date.now()}]: ${message}`);
});