Create a Task
A task automates the syncing of one or more keys. Depending on the task, you can either recache exact keys or use a key pattern to query the keys. More on this later. There are three types of tasks:
-
On Demand: On-demand tasks can be run from the Tasks screen.
-
Scheduled: BadgerCache can run a task hourly, daily, and weekly as a scheduled job. The daily sync happens at 8 am EST every day. The weekly sync is on every Tuesday at 3 EST.
-
Webhook: A webhook can be setup with your data source to hit BadgerCache whenever there is a key to sync. We provide a webhook URL from the control panel that can be used for this purpose. With webhooks specifically, you can also take the payload from the webhook to decide which cache keys to sync. This allows you to sync only keys that have changed. Once the task is created, you can find the webhook URL from the edit screen for that task.
Name the task. If you don't want it to be enabled, uncheck the box.
Choose a task type. There can be tasks covering multiple keys or single keys. It's up to your use case.
Choose to use exact keys or use a key pattern. Exact keys can be searched for in the box. A key pattern is a partial search term to find similar keys. For example, if you wanted to cache all the keys named product-category
(product-category-1
, product-category-2
, product-category-3
, ect.) - you could use product-category
as the key pattern. When the task is run, all the keys containing that search pattern will be resynced. There are no wildcard characters considered in the key pattern.
For webhook tasks using key patterns:
Use webhook variables in the key pattern. Additionally, with webhook tasks utilizing the key pattern, there are webhook variables. Example: If a webhook payload came back with an ID for the product category, BadgerCache could use that ID in the key pattern to pull that specific key. Just like data source variables, webhook variables use handlebars syntax: product-category-{{CATEGORY_ID}}
. Be sure to namespace keys so they don't overlap. For example, product-category-1
and product-category-11
would be resynced with product-category-1
as the key pattern. It would make sense to have some kind of deliminator after the ID in the key pattern like another dash to solve issue. More later on using webhook transforms to pass variables.
For all tasks utilizing key patterns:
Test the key pattern. Test the key pattern if applicable, from the create and edit screens. A successful return result is a JSON array of key names. Enter a correct value to test this if there are handlebars variables.
For webhook tasks:
Setup the webhook payload transform. The webhook's JSON body can be parsed to pass variables to the key pattern. For example, if the key pattern contained a variable called {{categoryId}}
, JavaScript could pull that ID from the webhook's JSON body. BadgerCache allows you to paste an example webhook body to test this. Keep in mind, if the actual webhook payload doesn't contain the correct object keys being queried in the JavaScript, the job could fail. The transform should always return a variables object with an array of key-value pairs.
For all tasks:
Save the task to test. From the list of tasks, choose the task you'd like to test. Hit the Run
button. If the task is a webhook and requires a transform, use an example JSON body payload from the webhook. Hit the Run Task
button from the modal to test the task. Tasks execute asyncronously and are retried up to 3 times in an incremental backoff.
Check the task logs after a few moments. The Logs button is available from the specific task on the Tasks screen. A log is recorded for each specific cache key that's synced whether it succeeds or fails. BadgerCache keeps the logs for 30 days.