amplify-backend icon indicating copy to clipboard operation
amplify-backend copied to clipboard

feat: add support for scheduling functions

Open rtpascual opened this issue 1 year ago • 1 comments

Changes

Add the ability to schedule functions:

  • Natural language - starts with every then the rest is based on the unit of time
    • Minutes and Hours
      • every followed by a space then a positive whole number and either m for minute(s) or h for hour(s)
      • Examples: every 5m or every 1h
    • Days, Weeks, Months, Years
      • every followed by a space then either day, week, month, or year
      • Days will always start at 00:00
      • Weeks start on Sundays at 00:00
      • Months start on 1st day of the month at 00:00
      • Years start Jan 1st at 00:00
      • Examples: every day or every year
  • Cron expression - 5 or 6 cron "parts" (year is not required) which follow Amazon EventBridge cron expressions for possible values
    • What is not supported:
      • JAN-DEC for months
      • SUN-SAT for days of the week
      • The L wildcard
      • The # wildcard
      • The W wildcard
  • An array that contains either of the above.
export const everyFiveMinutes = defineFunction({
    name: 'everyFiveMinutes',
    schedule: 'every 5m',
});

export const everyHour = defineFunction({
    name: 'everyHour',
    schedule: 'every 1h',
});

export const cronFiveThirtyDaily = defineFunction({
    name: 'cronFiveThirtyDaily',
    schedule: '30 17 * * *',
});

export const cronWednesdayAtNine = defineFunction({
    name: 'cronWednesdayAtNine',
    schedule: '0 9 * * 3',
});

export const arrayEvery = defineFunction({
    name: 'arrayEvery',
    schedule: [
        'every 4h',
        'every 40m'
    ],
});

export const arrayCron = defineFunction({
    name: 'arrayCron',
    schedule: [
        '25 * * * *',
        '* 3 * * *',
        '0 1 * * * *',
    ],
});

export const arrayMixed = defineFunction({
    name: 'arrayMixed',
    schedule: [
        'every 6h',
        '* 5 * * *',
    ],
});

Validation

Unit tests to be added.

Checklist

  • [ ] If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • [ ] If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • [ ] If this PR requires a docs update, I have linked to that docs PR above.
  • [ ] If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

rtpascual avatar May 16 '24 01:05 rtpascual

🦋 Changeset detected

Latest commit: ca2d0bd1eb466fc5752cb4b830375af273372dec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/backend-function Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar May 16 '24 01:05 changeset-bot[bot]