Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GKE kubernetes delayed_job pod logs

I have a deployment object with the following rake jobs:work command:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: staging-delayed-job-deployment
  namespace: staging
spec:
  template:
    metadata:
      labels:
        env: staging
        name: delayed-job
    spec:
      containers:
        - name: job
          image: gcr.io/ej-gc-dev/redacted:<%= ENV['IMAGE_TAG'] %>
          command: ["/bin/bash", "-l", "-c"]
          args: ["RAILS_ENV=production bundle exec rake jobs:work"]

When I run kubectl logs I get nothing. How do I get the rake jobs:work output to show in kubectl logs ? i.e if run directly in the pod it gives output like this:

[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Starting job worker
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job UpdateHubspotPersonaJob (id=67) RUNNING
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job UpdateHubspotPersonaJob (id=67) COMPLETED after 0.4903
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job Mailerjack.registration_created_user_welcome (id=68) RUNNING
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job Mailerjack.registration_created_user_welcome (id=68) COMPLETED after 0.9115
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job UpdateHubspotPersonaJob (id=69) RUNNING
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job UpdateHubspotPersonaJob (id=69) COMPLETED after 0.1752
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job Mailerjack.registration_created_user_welcome (id=70) RUNNING
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job Mailerjack.registration_created_user_welcome (id=70) COMPLETED after 0.4770
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] 4 jobs processed at 1.7649 j/s, 0 failed

I want that to show up when I run kubectl logs

like image 561
snowflakekiller Avatar asked Feb 16 '18 12:02

snowflakekiller


1 Answers

I needed to add an initializer: config/initializers/delayed_job.rb and set the worker's logger to stdout like so:

Delayed::Worker.logger = Logger.new(STDOUT)

like image 187
snowflakekiller Avatar answered Oct 16 '22 13:10

snowflakekiller