2

Trying to setup whenever cron jobs on my app that runs on a docker setup with redis and sidekiq in separate containers, but haven't been able to set them to fire on a time schedule, manually it works fine.

schedule.rb file

env :PATH, ENV['PATH']
set :output, "log/cron.log"

every 1.minutes do
  runner "SampleJob.perform_async"
end

Test job I am trying to run:

class SampleJob
  include Sidekiq::Worker
  
  def perform(*args)
    p 'Job is running'
  end
end

my Dockerfile

FROM ruby:2.7.1

ENV LANG C.UTF-8
ENV NODE_VERSION 12
ENV NODE_ENV production
ENV INSTALL_PATH /home/app/app/current

RUN curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update -qq
RUN apt-get install -y --no-install-recommends nodejs postgresql-client yarn build-essential vim
RUN apt-get install -y cron

RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH

COPY Gemfile Gemfile.lock ./
RUN gem install bundler
RUN bundle install

COPY . $INSTALL_PATH

RUN rm -rf tmp

RUN useradd -Ms /bin/bash api -u 1001
RUN chown -R api:api /home/app /usr/local/bundle
USER root

RUN touch /home/app/app/current/log/cron.log
RUN bundle exec whenever --update-crontab --set environment='development' 
CMD cron && bundle exec puma

RUN service cron start 


EXPOSE 3100
CMD rails server -p 3100 -b 0.0.0.0

running crontab -l inside my app's container gives me:

# Begin Whenever generated tasks for: /home/app/limpar-api/current/config/schedule.rb at: 2021-05-05 17:42:43 +0000
PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/b
.
. (many path variables)
.

* * * * * /bin/bash -l -c 'cd /home/app/limpar-api/current && bundle exec bin/rails runner -e development '\''SampleJob.perform_async'\'' >> log/cron.log 2>&1'

# End Whenever generated tasks for: /home/app/limpar-api/current/config/schedule.rb at: 2021-05-05 17:42:43 +0000

Any step I might be missing from the mix?

queroga_vqz
  • 1,031
  • 3
  • 11
  • 25

0 Answers0