Skip to main content

Cookie settings

We use cookies to ensure the basic functionalities of the website and to enhance your online experience. You can configure and accept the use of the cookies, and modify your consent options, at any time.

Essential

Preferences

Analytics and statistics

Marketing

Week 6 : Mautic Marketplace : scheduling the edge function

Avatar: Kgitman Kgitman

Welcome to week 6

This week we started discussing the cron job!

We are planning that we don't want to run the script every time.

By setting the cron job, our function is automatically invoked at a specific time

So I started exploring the cron job platform but my mentors suggested to me that supabase has its own scheduling option. So I started exploring how to use the supabase for cron jobs.

I found some initial steps :

So first we have to deploy our function and we can later use that deployed function to set the cron job.

So I used the supabase CLI to deploy the function. To deploy the function you can use the command like supabase functions deploy or if you want only specific function to deploy then you can use the function name like eg. supabase functions deploy my_function

for setting the cron job we have to make the cron job code with the sql editor, in docs they provide the format that we can use to set the cron job.

code:

select
cron.schedule(
'invoke-function-every-minute',
'* * * * *', -- every minute
$$
select
net.http_post(
url:='https://project-ref.supabase.co/functions/v1/function-name',
headers:='{"Content-Type": "application/json", "Authorization": "Bearer YOUR_ANON_KEY"}'::jsonb,
body:=concat('{"time": "', now(), '"}')::jsonb
) as request_id;
$$
);

You have to replace the deployed function URL (you can find it in the edge function section) of your deployed functions and YOUR_ANON_KEY.
you can schedule according to your requirement by changing the * (starts).

And run it you can see your scheduled cron job in cron schema

I successfully did the cron job part here

I'm continuing to explore the endpoints! and testing those

Next week:

The MautiCon is coming and I'm very excited for that

Because I'm sharing the experience and my project with the community

Anything you want to ask related to my project, please do comment below! 

Thanks for your valuable time!

Report inappropriate content

Is this content inappropriate?

Reason:

Loading comments ...

Log in or create an account to add your comment.

Confirm

Please log in

You can access with your Mautic Forums account or create an account here.

Share