@jackdbd/cloud-scheduler-utils
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

@jackdbd/cloud-scheduler-utils

npm version Snyk Vulnerabilities for npm package

Utility functions to work with Cloud Sheduler.

Table of Contents

Installation

npm install @jackdbd/cloud-scheduler-utils

⚠️ Warning:

This library declares @google-cloud/scheduler and debug as peer dependencies.

Why?

I find the Cloud Scheduler client a bit awkward to work with, so I decided to make a tiny set of utilities for my needs.

API

API docs generated with TypeDoc

Usage

import { CloudSchedulerClient } from '@google-cloud/scheduler'
import { createHttpJob, deleteJob, randomSchedule } from '@jackdbd/cloud-scheduler-utils'

// Instantiate your Cloud Scheduler client as you prefer:
// - Application Default Credentials (ADC)
// - environment variable GOOGLE_APPLICATION_CREDENTIALS
// - JSON key of a service account
const cloud_scheduler = new CloudSchedulerClient()

// Spaces are not possible, apostrophes are not possible (e.g. `new year's eve` is not a valid job name)
const name = 'call-google-on-a-schedule'

const location_id = 'europe-west3'

// Set a fixed schedule...
const schedule = '59 23 31 12 *' // Tip: use https://crontab.guru/
// ...or a random one:
// const schedule = randomSchedule()

const config = {
  cloud_scheduler, // Note that you have to pass your Cloud Scheduler client as configuration for the job.
  description: 'this is a test HTTP job',
  location_id,
  name,
  project_id: '<YOUR GOOGLE CLOUD PLATFORM PROJECT ID>',
  schedule,
  service_account_email: '<YOUR SERVICE ACCOUNT EMAIL>',
  timezone: 'Europe/Rome',
  url_to_call: 'https://www.google.com/'
}

const job = await createHttpJob(config)

await deleteJob({ cloud_scheduler, location_id, name })

await deleteAllJobs({ cloud_scheduler, location_id, name })

Readme

Keywords

Package Sidebar

Install

npm i @jackdbd/cloud-scheduler-utils

Weekly Downloads

0

Version

1.2.0

License

MIT

Unpacked Size

42.9 kB

Total Files

55

Last publish

Collaborators

  • jackdbd