1. Packages
  2. Cloudflare
  3. API Docs
  4. WorkerCronTrigger
Cloudflare v5.23.0 published on Monday, Mar 25, 2024 by Pulumi

cloudflare.WorkerCronTrigger

Explore with Pulumi AI

cloudflare logo
Cloudflare v5.23.0 published on Monday, Mar 25, 2024 by Pulumi

    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 fs from "fs";
    
    const exampleScript = new cloudflare.WorkerScript("exampleScript", {
        accountId: "f037e56e89293a057740de681ac9abbe",
        name: "example-script",
        content: fs.readFileSync("path/to/my.js", "utf8"),
    });
    const exampleTrigger = new cloudflare.WorkerCronTrigger("exampleTrigger", {
        accountId: "f037e56e89293a057740de681ac9abbe",
        scriptName: exampleScript.name,
        schedules: [
            "*/5 * * * *",
            "10 7 * * mon-fri",
        ],
    });
    
    import pulumi
    import pulumi_cloudflare as cloudflare
    
    example_script = cloudflare.WorkerScript("exampleScript",
        account_id="f037e56e89293a057740de681ac9abbe",
        name="example-script",
        content=(lambda path: open(path).read())("path/to/my.js"))
    example_trigger = cloudflare.WorkerCronTrigger("exampleTrigger",
        account_id="f037e56e89293a057740de681ac9abbe",
        script_name=example_script.name,
        schedules=[
            "*/5 * * * *",
            "10 7 * * mon-fri",
        ])
    
    package main
    
    import (
    	"os"
    
    	"github.com/pulumi/pulumi-cloudflare/sdk/v5/go/cloudflare"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func readFileOrPanic(path string) pulumi.StringPtrInput {
    	data, err := os.ReadFile(path)
    	if err != nil {
    		panic(err.Error())
    	}
    	return pulumi.String(string(data))
    }
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		exampleScript, err := cloudflare.NewWorkerScript(ctx, "exampleScript", &cloudflare.WorkerScriptArgs{
    			AccountId: pulumi.String("f037e56e89293a057740de681ac9abbe"),
    			Name:      pulumi.String("example-script"),
    			Content:   readFileOrPanic("path/to/my.js"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = cloudflare.NewWorkerCronTrigger(ctx, "exampleTrigger", &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
    	})
    }
    
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using Pulumi;
    using Cloudflare = Pulumi.Cloudflare;
    
    return await Deployment.RunAsync(() => 
    {
        var exampleScript = new Cloudflare.WorkerScript("exampleScript", new()
        {
            AccountId = "f037e56e89293a057740de681ac9abbe",
            Name = "example-script",
            Content = File.ReadAllText("path/to/my.js"),
        });
    
        var exampleTrigger = new Cloudflare.WorkerCronTrigger("exampleTrigger", new()
        {
            AccountId = "f037e56e89293a057740de681ac9abbe",
            ScriptName = exampleScript.Name,
            Schedules = new[]
            {
                "*/5 * * * *",
                "10 7 * * mon-fri",
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.cloudflare.WorkerScript;
    import com.pulumi.cloudflare.WorkerScriptArgs;
    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 WorkerScript("exampleScript", WorkerScriptArgs.builder()        
                .accountId("f037e56e89293a057740de681ac9abbe")
                .name("example-script")
                .content(Files.readString(Paths.get("path/to/my.js")))
                .build());
    
            var exampleTrigger = new WorkerCronTrigger("exampleTrigger", WorkerCronTriggerArgs.builder()        
                .accountId("f037e56e89293a057740de681ac9abbe")
                .scriptName(exampleScript.name())
                .schedules(            
                    "*/5 * * * *",
                    "10 7 * * mon-fri")
                .build());
    
        }
    }
    
    resources:
      exampleScript:
        type: cloudflare:WorkerScript
        properties:
          accountId: f037e56e89293a057740de681ac9abbe
          name: example-script
          content:
            fn::readFile: path/to/my.js
      exampleTrigger:
        type: cloudflare:WorkerCronTrigger
        properties:
          accountId: f037e56e89293a057740de681ac9abbe
          scriptName: ${exampleScript.name}
          schedules:
            - '*/5 * * * *'
            - 10 7 * * mon-fri
    

    Create WorkerCronTrigger Resource

    new WorkerCronTrigger(name: string, args: WorkerCronTriggerArgs, opts?: CustomResourceOptions);
    @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)
    @overload
    def WorkerCronTrigger(resource_name: str,
                          args: WorkerCronTriggerArgs,
                          opts: Optional[ResourceOptions] = 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.
    
    
    name string
    The unique name of the resource.
    args WorkerCronTriggerArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args 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 string
    The unique name of the resource.
    args WorkerCronTriggerArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args WorkerCronTriggerArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args WorkerCronTriggerArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    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

    The WorkerCronTrigger resource accepts the following input properties:

    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.

    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)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    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
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    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
    The unique name of the resulting resource.
    id
    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
    The unique name of the resulting resource.
    id
    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>
    

    Package Details

    Repository
    Cloudflare pulumi/pulumi-cloudflare
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the cloudflare Terraform Provider.
    cloudflare logo
    Cloudflare v5.23.0 published on Monday, Mar 25, 2024 by Pulumi