JSPM

@backstage/backend-tasks

0.0.0-nightly-20240518021458
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 44118
  • Score
    100M100P100Q155556F
  • License Apache-2.0

Common distributed task management library for Backstage backends

Package Exports

  • @backstage/backend-tasks
  • @backstage/backend-tasks/dist/index.cjs.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@backstage/backend-tasks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@backstage/backend-tasks

Common distributed task management for Backstage backends.

Usage

Add the library to your backend package:

# From your Backstage root directory
yarn --cwd packages/backend add @backstage/backend-tasks

then make use of its facilities as necessary:

import { TaskScheduler } from '@backstage/backend-tasks';

const scheduler = TaskScheduler.fromConfig(rootConfig).forPlugin('my-plugin');

await scheduler.scheduleTask({
  id: 'refresh_things',
  frequency: { cron: '*/5 * * * *' }, // every 5 minutes, also supports Duration
  timeout: { minutes: 15 },
  fn: async () => {
    await entityProvider.run();
  },
});

Local Development

When working with the @backstage/backend-tasks library you may run into your task not running immediately at startup as expected if you are using a persistent database. This is by design - the library respects the previous state and does not run the task sooner than the specified frequency. If you want to get around this, there is a table called backstage_backend_tasks__tasks in the applicable plugin's database which will contain a record with the next run date and time. You can delete this record to get things back to what you expect.

Documentation