1. Packages
  2. Cloudflare Provider
  3. API Docs
  4. WorkerCronTrigger
Cloudflare v5.49.1 published on Tuesday, Feb 18, 2025 by Pulumi

cloudflare.WorkerCronTrigger

Explore with Pulumi AI

Worker Cron Triggers allow users to map a cron expression to a Worker script using a ScheduledEvent listener that enables Workers to be executed on a schedule. Worker Cron Triggers are ideal for running periodic jobs for maintenance or calling third-party APIs to collect up-to-date data.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as cloudflare from "@pulumi/cloudflare";
import * as std from "@pulumi/std";

const exampleScript = new cloudflare.WorkersScript("example_script", {
    accountId: "f037e56e89293a057740de681ac9abbe",
    name: "example-script",
    content: std.file({
        input: "path/to/my.js",
    }).then(invoke => invoke.result),
});
const exampleTrigger = new cloudflare.WorkerCronTrigger("example_trigger", {
    accountId: "f037e56e89293a057740de681ac9abbe",
    scriptName: exampleScript.name,
    schedules: [
        "*/5 * * * *",
        "10 7 * * mon-fri",
    ],
});
Copy
import pulumi
import pulumi_cloudflare as cloudflare
import pulumi_std as std

example_script = cloudflare.WorkersScript("example_script",
    account_id="f037e56e89293a057740de681ac9abbe",
    name="example-script",
    content=std.file(input="path/to/my.js").result)
example_trigger = cloudflare.WorkerCronTrigger("example_trigger",
    account_id="f037e56e89293a057740de681ac9abbe",
    script_name=example_script.name,
    schedules=[
        "*/5 * * * *",
        "10 7 * * mon-fri",
    ])
Copy
package main

import (
	"github.com/pulumi/pulumi-cloudflare/sdk/v5/go/cloudflare"
	"github.com/pulumi/pulumi-std/sdk/go/std"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		invokeFile, err := std.File(ctx, &std.FileArgs{
			Input: "path/to/my.js",
		}, nil)
		if err != nil {
			return err
		}
		exampleScript, err := cloudflare.NewWorkersScript(ctx, "example_script", &cloudflare.WorkersScriptArgs{
			AccountId: pulumi.String("f037e56e89293a057740de681ac9abbe"),
			Name:      pulumi.String("example-script"),
			Content:   pulumi.String(invokeFile.Result),
		})
		if err != nil {
			return err
		}
		_, err = cloudflare.NewWorkerCronTrigger(ctx, "example_trigger", &cloudflare.WorkerCronTriggerArgs{
			AccountId:  pulumi.String("f037e56e89293a057740de681ac9abbe"),
			ScriptName: exampleScript.Name,
			Schedules: pulumi.StringArray{
				pulumi.String("*/5 * * * *"),
				pulumi.String("10 7 * * mon-fri"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Cloudflare = Pulumi.Cloudflare;
using Std = Pulumi.Std;

return await Deployment.RunAsync(() => 
{
    var exampleScript = new Cloudflare.WorkersScript("example_script", new()
    {
        AccountId = "f037e56e89293a057740de681ac9abbe",
        Name = "example-script",
        Content = Std.File.Invoke(new()
        {
            Input = "path/to/my.js",
        }).Apply(invoke => invoke.Result),
    });

    var exampleTrigger = new Cloudflare.WorkerCronTrigger("example_trigger", new()
    {
        AccountId = "f037e56e89293a057740de681ac9abbe",
        ScriptName = exampleScript.Name,
        Schedules = new[]
        {
            "*/5 * * * *",
            "10 7 * * mon-fri",
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.cloudflare.WorkersScript;
import com.pulumi.cloudflare.WorkersScriptArgs;
import com.pulumi.cloudflare.WorkerCronTrigger;
import com.pulumi.cloudflare.WorkerCronTriggerArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var exampleScript = new WorkersScript("exampleScript", WorkersScriptArgs.builder()
            .accountId("f037e56e89293a057740de681ac9abbe")
            .name("example-script")
            .content(StdFunctions.file(FileArgs.builder()
                .input("path/to/my.js")
                .build()).result())
            .build());

        var exampleTrigger = new WorkerCronTrigger("exampleTrigger", WorkerCronTriggerArgs.builder()
            .accountId("f037e56e89293a057740de681ac9abbe")
            .scriptName(exampleScript.name())
            .schedules(            
                "*/5 * * * *",
                "10 7 * * mon-fri")
            .build());

    }
}
Copy
resources:
  exampleScript:
    type: cloudflare:WorkersScript
    name: example_script
    properties:
      accountId: f037e56e89293a057740de681ac9abbe
      name: example-script
      content:
        fn::invoke:
          function: std:file
          arguments:
            input: path/to/my.js
          return: result
  exampleTrigger:
    type: cloudflare:WorkerCronTrigger
    name: example_trigger
    properties:
      accountId: f037e56e89293a057740de681ac9abbe
      scriptName: ${exampleScript.name}
      schedules:
        - '*/5 * * * *'
        - 10 7 * * mon-fri
Copy

Create WorkerCronTrigger Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new WorkerCronTrigger(name: string, args: WorkerCronTriggerArgs, opts?: CustomResourceOptions);
@overload
def WorkerCronTrigger(resource_name: str,
                      args: WorkerCronTriggerArgs,
                      opts: Optional[ResourceOptions] = None)

@overload
def WorkerCronTrigger(resource_name: str,
                      opts: Optional[ResourceOptions] = None,
                      account_id: Optional[str] = None,
                      schedules: Optional[Sequence[str]] = None,
                      script_name: Optional[str] = None)
func NewWorkerCronTrigger(ctx *Context, name string, args WorkerCronTriggerArgs, opts ...ResourceOption) (*WorkerCronTrigger, error)
public WorkerCronTrigger(string name, WorkerCronTriggerArgs args, CustomResourceOptions? opts = null)
public WorkerCronTrigger(String name, WorkerCronTriggerArgs args)
public WorkerCronTrigger(String name, WorkerCronTriggerArgs args, CustomResourceOptions options)
type: cloudflare:WorkerCronTrigger
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. WorkerCronTriggerArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. WorkerCronTriggerArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. WorkerCronTriggerArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. WorkerCronTriggerArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. WorkerCronTriggerArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var workerCronTriggerResource = new Cloudflare.WorkerCronTrigger("workerCronTriggerResource", new()
{
    AccountId = "string",
    Schedules = new[]
    {
        "string",
    },
    ScriptName = "string",
});
Copy
example, err := cloudflare.NewWorkerCronTrigger(ctx, "workerCronTriggerResource", &cloudflare.WorkerCronTriggerArgs{
	AccountId: pulumi.String("string"),
	Schedules: pulumi.StringArray{
		pulumi.String("string"),
	},
	ScriptName: pulumi.String("string"),
})
Copy
var workerCronTriggerResource = new WorkerCronTrigger("workerCronTriggerResource", WorkerCronTriggerArgs.builder()
    .accountId("string")
    .schedules("string")
    .scriptName("string")
    .build());
Copy
worker_cron_trigger_resource = cloudflare.WorkerCronTrigger("workerCronTriggerResource",
    account_id="string",
    schedules=["string"],
    script_name="string")
Copy
const workerCronTriggerResource = new cloudflare.WorkerCronTrigger("workerCronTriggerResource", {
    accountId: "string",
    schedules: ["string"],
    scriptName: "string",
});
Copy
type: cloudflare:WorkerCronTrigger
properties:
    accountId: string
    schedules:
        - string
    scriptName: string
Copy

WorkerCronTrigger Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The WorkerCronTrigger resource accepts the following input properties:

AccountId This property is required. string
The account identifier to target for the resource.
Schedules This property is required. List<string>
Cron expressions to execute the Worker script.
ScriptName This property is required. string
Worker script to target for the schedules.
AccountId This property is required. string
The account identifier to target for the resource.
Schedules This property is required. []string
Cron expressions to execute the Worker script.
ScriptName This property is required. string
Worker script to target for the schedules.
accountId This property is required. String
The account identifier to target for the resource.
schedules This property is required. List<String>
Cron expressions to execute the Worker script.
scriptName This property is required. String
Worker script to target for the schedules.
accountId This property is required. string
The account identifier to target for the resource.
schedules This property is required. string[]
Cron expressions to execute the Worker script.
scriptName This property is required. string
Worker script to target for the schedules.
account_id This property is required. str
The account identifier to target for the resource.
schedules This property is required. Sequence[str]
Cron expressions to execute the Worker script.
script_name This property is required. str
Worker script to target for the schedules.
accountId This property is required. String
The account identifier to target for the resource.
schedules This property is required. List<String>
Cron expressions to execute the Worker script.
scriptName This property is required. String
Worker script to target for the schedules.

Outputs

All input properties are implicitly available as output properties. Additionally, the WorkerCronTrigger resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing WorkerCronTrigger Resource

Get an existing WorkerCronTrigger resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: WorkerCronTriggerState, opts?: CustomResourceOptions): WorkerCronTrigger
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        account_id: Optional[str] = None,
        schedules: Optional[Sequence[str]] = None,
        script_name: Optional[str] = None) -> WorkerCronTrigger
func GetWorkerCronTrigger(ctx *Context, name string, id IDInput, state *WorkerCronTriggerState, opts ...ResourceOption) (*WorkerCronTrigger, error)
public static WorkerCronTrigger Get(string name, Input<string> id, WorkerCronTriggerState? state, CustomResourceOptions? opts = null)
public static WorkerCronTrigger get(String name, Output<String> id, WorkerCronTriggerState state, CustomResourceOptions options)
resources:  _:    type: cloudflare:WorkerCronTrigger    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
AccountId string
The account identifier to target for the resource.
Schedules List<string>
Cron expressions to execute the Worker script.
ScriptName string
Worker script to target for the schedules.
AccountId string
The account identifier to target for the resource.
Schedules []string
Cron expressions to execute the Worker script.
ScriptName string
Worker script to target for the schedules.
accountId String
The account identifier to target for the resource.
schedules List<String>
Cron expressions to execute the Worker script.
scriptName String
Worker script to target for the schedules.
accountId string
The account identifier to target for the resource.
schedules string[]
Cron expressions to execute the Worker script.
scriptName string
Worker script to target for the schedules.
account_id str
The account identifier to target for the resource.
schedules Sequence[str]
Cron expressions to execute the Worker script.
script_name str
Worker script to target for the schedules.
accountId String
The account identifier to target for the resource.
schedules List<String>
Cron expressions to execute the Worker script.
scriptName String
Worker script to target for the schedules.

Import

$ pulumi import cloudflare:index/workerCronTrigger:WorkerCronTrigger example <account_id>/<script_name>
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Cloudflare pulumi/pulumi-cloudflare
License
Apache-2.0
Notes
This Pulumi package is based on the cloudflare Terraform Provider.