1. Packages
  2. Cloudflare Provider
  3. API Docs
  4. WorkersCronTrigger
Cloudflare v5.39.1 published on Tuesday, Sep 24, 2024 by Pulumi

cloudflare.WorkersCronTrigger

Explore with Pulumi AI

cloudflare logo
Cloudflare v5.39.1 published on Tuesday, Sep 24, 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.WorkersScript("example_script", {
        accountId: "f037e56e89293a057740de681ac9abbe",
        name: "example-script",
        content: std.file({
            input: "path/to/my.js",
        }).then(invoke => invoke.result),
    });
    const exampleTrigger = new cloudflare.WorkersCronTrigger("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.WorkersScript("example_script",
        account_id="f037e56e89293a057740de681ac9abbe",
        name="example-script",
        content=std.file(input="path/to/my.js").result)
    example_trigger = cloudflare.WorkersCronTrigger("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.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.NewWorkersCronTrigger(ctx, "example_trigger", &cloudflare.WorkersCronTriggerArgs{
    			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.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.WorkersCronTrigger("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.WorkersScript;
    import com.pulumi.cloudflare.WorkersScriptArgs;
    import com.pulumi.cloudflare.WorkersCronTrigger;
    import com.pulumi.cloudflare.WorkersCronTriggerArgs;
    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 WorkersCronTrigger("exampleTrigger", WorkersCronTriggerArgs.builder()
                .accountId("f037e56e89293a057740de681ac9abbe")
                .scriptName(exampleScript.name())
                .schedules(            
                    "*/5 * * * *",
                    "10 7 * * mon-fri")
                .build());
    
        }
    }
    
    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:WorkersCronTrigger
        name: example_trigger
        properties:
          accountId: f037e56e89293a057740de681ac9abbe
          scriptName: ${exampleScript.name}
          schedules:
            - '*/5 * * * *'
            - 10 7 * * mon-fri
    

    Create WorkersCronTrigger Resource

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

    Constructor syntax

    new WorkersCronTrigger(name: string, args: WorkersCronTriggerArgs, opts?: CustomResourceOptions);
    @overload
    def WorkersCronTrigger(resource_name: str,
                           args: WorkersCronTriggerArgs,
                           opts: Optional[ResourceOptions] = None)
    
    @overload
    def WorkersCronTrigger(resource_name: str,
                           opts: Optional[ResourceOptions] = None,
                           account_id: Optional[str] = None,
                           schedules: Optional[Sequence[str]] = None,
                           script_name: Optional[str] = None)
    func NewWorkersCronTrigger(ctx *Context, name string, args WorkersCronTriggerArgs, opts ...ResourceOption) (*WorkersCronTrigger, error)
    public WorkersCronTrigger(string name, WorkersCronTriggerArgs args, CustomResourceOptions? opts = null)
    public WorkersCronTrigger(String name, WorkersCronTriggerArgs args)
    public WorkersCronTrigger(String name, WorkersCronTriggerArgs args, CustomResourceOptions options)
    
    type: cloudflare:WorkersCronTrigger
    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 WorkersCronTriggerArgs
    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 WorkersCronTriggerArgs
    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 WorkersCronTriggerArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args WorkersCronTriggerArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args WorkersCronTriggerArgs
    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 workersCronTriggerResource = new Cloudflare.WorkersCronTrigger("workersCronTriggerResource", new()
    {
        AccountId = "string",
        Schedules = new[]
        {
            "string",
        },
        ScriptName = "string",
    });
    
    example, err := cloudflare.NewWorkersCronTrigger(ctx, "workersCronTriggerResource", &cloudflare.WorkersCronTriggerArgs{
    	AccountId: pulumi.String("string"),
    	Schedules: pulumi.StringArray{
    		pulumi.String("string"),
    	},
    	ScriptName: pulumi.String("string"),
    })
    
    var workersCronTriggerResource = new WorkersCronTrigger("workersCronTriggerResource", WorkersCronTriggerArgs.builder()
        .accountId("string")
        .schedules("string")
        .scriptName("string")
        .build());
    
    workers_cron_trigger_resource = cloudflare.WorkersCronTrigger("workersCronTriggerResource",
        account_id="string",
        schedules=["string"],
        script_name="string")
    
    const workersCronTriggerResource = new cloudflare.WorkersCronTrigger("workersCronTriggerResource", {
        accountId: "string",
        schedules: ["string"],
        scriptName: "string",
    });
    
    type: cloudflare:WorkersCronTrigger
    properties:
        accountId: string
        schedules:
            - string
        scriptName: string
    

    WorkersCronTrigger 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 WorkersCronTrigger 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 WorkersCronTrigger 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 WorkersCronTrigger Resource

    Get an existing WorkersCronTrigger 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?: WorkersCronTriggerState, opts?: CustomResourceOptions): WorkersCronTrigger
    @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) -> WorkersCronTrigger
    func GetWorkersCronTrigger(ctx *Context, name string, id IDInput, state *WorkersCronTriggerState, opts ...ResourceOption) (*WorkersCronTrigger, error)
    public static WorkersCronTrigger Get(string name, Input<string> id, WorkersCronTriggerState? state, CustomResourceOptions? opts = null)
    public static WorkersCronTrigger get(String name, Output<String> id, WorkersCronTriggerState 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/workersCronTrigger:WorkersCronTrigger 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.39.1 published on Tuesday, Sep 24, 2024 by Pulumi