node.js – Google cloud scheduler for google cloud run using nodejs

I want to write a nodejs script which calls google cloud scheduler to schedule a cloud run service to be run only once (non recurring event). How can I do it?

I’ve checked out this library npmjs.com/package/@google-cloud/scheduler , but couldn’t find a way to create a non recurring job.

I’ve tried something like this

const { CloudSchedulerClient } = require('@google-cloud/scheduler');
const axios = require('axios');


const projectId = 'project-id';
const location = 'location'; 
const jobName="job-name";
const cloudRunURL = 'cloud-run-url';

async function createJob() {
  const client = new CloudSchedulerClient();

  const parent = `projects/${projectId}/locations/${location}`;
  const job = {
    name: `projects/${projectId}/locations/${location}/jobs/${jobName}`,
    httpTarget: {
      uri: cloudRunURL,
      httpMethod: 'GET',
    },
    schedule: '0 12 * * *',
    timeZone: 'UTC', 
  };

  try {
    const [createdJob] = await client.createJob({
      parent: parent,
      job: job,
    });

    console.log('Job created:', createdJob.name);
  } catch (err) {
    console.error('Error creating job:', err);
  }
}


createJob();

But I’m stuck How to make it non recurring?

Read more here: Source link