1.2.0 • Published 2 years ago

@jackdbd/cloud-scheduler-utils v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@jackdbd/cloud-scheduler-utils

npm version Snyk Vulnerabilities for npm package

Utility functions to work with Cloud Sheduler.

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 })
1.2.0

2 years ago

1.1.0

2 years ago

1.2.0-canary.2

2 years ago

1.2.0-canary.1

2 years ago

1.1.0-canary.1

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.3

2 years ago

1.0.0

2 years ago