Using Hasura cron schedule as env variable

25 Views Asked by At

I'm trying to configure "cron schedule" in Hasura Events as an env variable instead of hard-coding it. This is because we need to run different schedules for different environments.

However, using {{CRON_SCHEDULE}} env variable is throwing this error:

Something went wrong while updating cron trigger: Failed reading: takeWhile1

I do have CRON_SCHEDULE env variable available in my env file

enter image description here

1

There are 1 best solutions below

0
Bete Goshme On

I was just in need of same thing and asked on discord and got not satisfying answer below.

" To set a cron trigger value from an environment variable like {{CRON_SCHEDULE}} instead of a hardcoded cron expression, you would typically need to ensure that the environment variable is correctly set in the environment where Hasura is running. However, based on the provided documentation and search results, there isn't a direct mention of using environment variables specifically for cron schedules in the creation of cron triggers through the Hasura Console, CLI, or Metadata API.

In general, Hasura allows the use of environment variables for various configurations, especially when defining webhook URLs for event triggers, which can be set to use environment variables directly in the console or through the Hasura metadata files. For cron triggers, the documentation primarily focuses on specifying the cron schedule directly in the configuration.

If your goal is to dynamically set the cron schedule based on different environments (e.g., development, staging, production), you might consider a couple of approaches:

Use Hasura Metadata API or CLI for Automation: You could automate the deployment or update of your cron triggers using the Hasura Metadata API or CLI. In your CI/CD pipeline, you can have a step that replaces a placeholder in your metadata definition files with the appropriate value from an environment variable before applying the metadata. This way, you can maintain different cron schedules for different environments outside of Hasura's configuration.

External Configuration Management: Manage your cron trigger configurations externally. You can have a script or a small service that reads the cron schedule from environment variables and then uses the Hasura Metadata API to create or update the cron triggers accordingly. This script or service can be part of your deployment process.

As of my last update, directly using environment variables to specify the cron schedule in the Hasura Console or through metadata files without some form of preprocessing or external management isn't documented. It's always a good idea to check the latest Hasura documentation or reach out to the Hasura community for new features or workarounds that might have been introduced."

Related Questions in HASURA-API