1. Packages
  2. Cloudflare
  3. API Docs
  4. WorkerCronTrigger
Cloudflare v5.34.0 published on Friday, Jul 12, 2024 by Pulumi

cloudflare.WorkerCronTrigger

Explore with Pulumi AI

cloudflare logo
Cloudflare v5.34.0 published on Friday, Jul 12, 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 std from "@pulumi/std";
    
    const exampleScript = new cloudflare.WorkerScript("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",
        ],
    });
    
    import pulumi
    import pulumi_cloudflare as cloudflare
    import pulumi_std as std
    
    example_script = cloudflare.WorkerScript("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",
        ])
    
    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.NewWorkerScript(ctx, "example_script", &cloudflare.WorkerScriptArgs{
    			AccountId: pulumi.String("f037e56e89293a057740de681ac9abbe"),
    			Name:      pulumi.String("example-script"),
    			Content:   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
    	})
    }
    
    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.WorkerScript("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",
            },
        });
    
    });
    
    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(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());
    
        }
    }
    
    resources:
      exampleScript:
        type: cloudflare:WorkerScript
        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
    

    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 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.

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

    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>
    

    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.
    cloudflare logo
    Cloudflare v5.34.0 published on Friday, Jul 12, 2024 by Pulumi