I have a backend written in Adonis v4.1 (node.js) that I'm deploying on AWS ECS. Inside the Task Definition of my API I have Adonis and Redis, linked by bridge network.
I'm using adonis-scheduler to run a cronjob every 30 minutes. This cronjob makes a db query and for each row it creates a job (with adonis-queue-pro library). The job concurrency is 1 (so if I have 30 records will be processed one job at a time). Each job makes and external API call and updates the record in the db.
On localhost everything works fine, but on staging environment sometimes happens that my API Task has more than one instance and more than one cronjob starts at the same exact time. So instead of having on job for each record I have multiple jobs for each record that runs simultaneously. This is a big problem.
Is there a way to handle this situation and have only the cronjob of one instance to execute? Or maybe could I have a Task Definition with only the scheduler part in one single instance (always) and the API and redis with many instances?
The problem is that the code I wrote is deeply linked to my backend, so I cannot use something like lambda functions or other external services.