Feature request: pass name and/or network to scheduled Autotasks

I have two separate Autotasks set up with the exact same code; one is for Kovan and the other for Mainnet. Because scheduled Autotasks don’t get the sentinel event schema that webhook Autotasks get, they have no context of the network they’re running on. This might be useful for fetching key-value pairs or secrets from within the Autotask that can be associated with the relevant network.

Currently, it seems I have to either manually change network-specific values in the Autotask code before each deploy (which is unsafe and may lead to incorrect values) or keep multiple network-specific files for each Autotask despite having the same code.

Interesting! We could allow having multiple schedules per Autotask, each of them tied to a different Relayer and with some env vars that get injected so the code can recognize in which schedule it is running.

Now, I get the sense that it’s a common use case having the same code for testnet and mainnet. However, do you update the code for both networks at the same time? Or do you first update testnet, run it for a little while, and then run the code update on mainnet?

In the meantime, keep in mind you can use the defender-autotask-client to programmatically update your autotask’s code, reducing the number of manual steps and the chance of entering incorrect values.

I first update testnet, run it for a while, and then update mainnet. I do use defender-autotask-client, but the zipped Autotasks don’t have access to env vars made available at runtime, so updating code may be tricky.

Have you considered using Autotask Secrets as a replacement for runtime env vars?

Yes, but if the scheduled Autotask has no context of whether it’s meant for Kovan or Mainnet, then it cannot pick out a network-specific secret.

When invoked by a Sentinel, however, the Autotask has access to the request.body.sentinel.network, which can be used to get a network-specific secret. For example:

export async function handler(event: AutotaskEvent) {
    const network = event.request?.body?.sentinel?.network;
    if (network) {
        const secret = event.secrets!['secret_for_the_${network}_network']

Got it! I’ll take this to the drawing board and see what we can come up with. Thanks for the feedback!!

1 Like