Ir para o conteúdo

Elastic Beanstalk cron job execution during the deployment

0

We are using AWS infrastructure and AWS Elastic Beanstalk as our orchestration service. In our SaaS application, many heavy-weight business tasks are built on cron jobs that run at various times.

Currently, when we deploy, the instances with running cron jobs are shut down immediately after the deployment process is finished, which causes problems with our business task execution. We need to configure our AWS deployment process so that instances with in-progress cron jobs remain running until those jobs are finished. All new cron jobs should be started on new instances.

We tried to use termination protection with EC2 Lifecycle Hooks but with this approach, we have a 3-4 minutes period when a new instances' group is not ready to run cron jobs but the old instances' group is already marked as blocked to run cron jobs. As a result, no cron jobs are run during this period that doesn't fit us.

Is it possible to manage our approach or are there other ways to solve it?

feita há 2 anos270 visualizações

1 Resposta
0

Use a Rolling Deployment with Batch Size = 1 (or small) By default, Elastic Beanstalk’s rolling deployments can terminate old instances before new ones are ready to run cron jobs. You want to invert that:

.ebextensions/rolling-deploy.config

option_settings:
  aws:elasticbeanstalk:command:
    DeploymentPolicy: Rolling
    # Launch 1 new instance, wait until healthy, then terminate 1 old one
    BatchSize: 1
    BatchSizeType: Count
    # Give ample time for your cron daemon to start & register “healthy”
    HealthCheckGracePeriod: 300

BatchSize: 1 + BatchSizeType: Count Launch exactly one new instance, wait for it to pass health checks (including your cron daemon startup), then terminate one old.

HealthCheckGracePeriod: 300 (5 minutes) Prevents EB from marking the new instance unhealthy just because cron hasn’t yet “woken up.”

With this in place, you won’t have a window where all old instances are blocked and no new instance is ready.

respondido há um ano

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.