Last updated Oct 30, 2024

Extending your app with a scheduled trigger

You can configure a scheduled trigger for your existing app to repeatedly invoke a function on a scheduled interval.

This guide assumes you have an app with a function that you would like to trigger on a schedule. If you haven’t already created a function, see Getting started for step-by-step instructions on setting up Forge and creating your first app.

Forge invocation limits also apply to web triggers (scheduled and unscheduled). Refer to our platform invocation limits for more details.

Add a web trigger

To develop your function, create a temporary web trigger to invoke your function manually while testing. Add a web trigger to your manifest.yml as follows:

1
2
modules:
  webtrigger:
    - key: temporary-development-webtrigger
      function: '<your-function-key>'

For more information about web triggers in Forge, see Web triggers.

Deploy and install your app

You'll need to redeploy your app to add the web trigger module. If this is the first time you're deploying your app, you'll also need to install the app on an Atlassian site.

  1. Navigate to the app's top-level directory and deploy your app by running:

    1
    2
    forge deploy
    
  2. Install your app by running:

    1
    2
    forge install
    
  3. Select your Atlassian product using the arrow keys and press the enter key.

  4. Enter the URL for your development site. For example, example.atlassian.net. View a list of your active sites at Atlassian administration.

Once the successful installation message appears, your app is installed and ready to use on the specified site. You can always delete your app from the site by running the forge uninstall command.

Running the forge install command only installs your app onto the selected product. To install onto multiple products, repeat these steps again, selecting another product each time. Note that the Atlassian Marketplace does not support cross-product apps yet.

You must run forge deploy before running forge install in any of the Forge environments.

Develop your app using the web trigger

Iterate through your function’s development by invoking the function using the web trigger.

The event parameter does not have a value for scheduled triggers, so you should avoid referencing it in your function.

  1. In the terminal, navigate to the app directory and get the app's installation ID by running:

    1
    2
    forge install list
    
  2. Copy the Installation ID for the site and product you want the web trigger URL for.

  3. Get the web trigger URL by running:

    1
    2
    forge webtrigger
    
    1. Enter the installation ID you copied in step 2.
    2. Select the web trigger that you want the URL for. The options come from the manifest.

    You'll be provided with a URL that you can use to invoke the web trigger. See webtrigger for more information about the forge webtrigger command.

    By default, the URLs provided by forge webtrigger have no built-in authentication. As such, anyone can use the URL (and, by extension, invoke its related function) without providing an authentication token. You should keep these URLs secure.

    Alternatively, you can also implement authentication inside the trigger itself. For example, you can add a check for an Authorization header in the request and validate any provided token.

  4. Start your app using the tunnel to get fast feedback without needing to redeploy. Run the following command:

    1
    2
    forge tunnel
    
  5. Make a request to the URL provided by forge webtrigger in a web browser or using the curl utility.

forge tunnel is only available in the development environment. See the environment restrictions on the environments and versions page for details.

Add a scheduled trigger and remove the web trigger

Once you have completed development of the function, you can add a scheduled trigger to your manifest.yml:

1
2
modules:
  scheduledTrigger:
    - key: my-scheduled-trigger
      function: '<your-function-key>'
      interval: hour

While debugging, you can keep using the web trigger and scheduled trigger. When you’re done, you can remove the web trigger module from the manifest file.

To make your changes permanent, redeploy your app using the forge deploy command.

Rate this page: