cron - What's the best approach to schedule tasks across docker cluster? -


currently, have app running on 1 server. there's crontab set according specified rules, there tasks being run @ times.

now, i'm thinking migrating app docker container i'm able run multiple instances of app independently. thing i'm wondering how how schedule tasks across multiple docker containers.

let's have php command every hour fetches new data 3rd party app via api. currently, use cron schedule this: 0 */1 * * * php /some/path/index.php mycommand. there can multiple similar commands launched @ different frequencies.

i cannot pack crontab docker image command launched 5 times when there 5 containers running. want launch once independently on running containers count.

what ideal solution achieve this?

you use locking mechanism, using redis. work this.

script wakes up, first thing does, try , lock. if gets lock, moves forward, if else has lock, exit. script does, , release lock.

since 1 script can lock @ time, allow script run once.

it important remove lock when script done, , add ttl lock if script dies before releasing lock, lock automatically open after ttl expires.

here docs on how use redis distributed lock. https://redis.io/topics/distlock


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -