Run server action based on row in table

I have multiple server actions which basically “syncs” an API of the software that we use, to our database. So all data from their API to our database. I want to run each sync on different time schedules, for instance sync1 every hour, and sync2 every 10 minutes. I can obviously achieve this using an action scheduler, but how can I fire an action scheduler (and change it’s interval) based on a database table like this:

Each row is should fire an action scheduler, which fires a server action every x minutes/hours. I’m not sure how to “link” the table rows to the scheduler. Any idea how to do this?

Hi Nevil,
So you need a separate instance of the scheduler per every row, is that right?

So you can add the action scheduler in your dynamic table, in the row > td (cell) and it will be repeated per record:

Then add the dynamic delay to it:

dmx-bind:delay="your_expression"

Where you replace your_expression with the dynamic expression which returns the seconds.

The code will look like:

<td>
    <dmx-scheduler id="scheduler1" dmx-bind:delay="your_expression" dmx-on:tick="your_dynamic_action"></dmx-scheduler>
</td>

I’m just not sure what to use in the “your_dynamic_action” expression. Because the action scheduler should run a different server action, based on the row.

These are my server actions (in the folder sync):

image "

And these are the server connect that run those server actions:

image

But I’m not sure how to dynamically bind those server connects to the dmx-on:tick ?

Are these the names of the server actions that need to be run?

Yes, I can match those names to the server connect/action names.

Why you dont use cron job ? @nevil

That’s basically what the action scheduler does right? I prefer not to use anything that involves a lot of code or having to use command line.

No, the action scheduler needs your page running open in your browser to execute the tasks. Once you close the page, it won’t run.

I am afraid in the current action scheduler implementation it’s only possible to call static server action names and dynamic ones (what you need here) are not supported.

Too bad, can it be implemented in the future? It basically allows me to build a CRON like user interface for all our API sync’s.

2 Likes

If you have full control of your server you can create a page or app than runs action scheduler. Of Course the page or app needs to be open and running all the time.