I followed a tutorial of setting up the whenever
gem to schedule repetitive jobs. I created a rake task that I want to run and I configured the schedule.rb
file:
set :output, 'log/whenever.log'every 1.day, at: '1:00 pm' do runner "my_namespace:my_task"end
I do deploy the code to my server with git push my-dokku-rails-app main
. What I do know is where and how to execute the whenever --update-crontab --set environment='production'
command.
If I SSH to my server, go to my dokku directory (/home/dokku/my-dokku-rails-app main
) and run whenever --update-crontab --set environment='production'
, I get
Command 'whenever' not found, but can be installed with:apt install ruby-whenever
EDIT: When I run bundle exec whenever --update-crontab --set environment='production'
, I get:
Command 'bundle' not found, but can be installed with:snap install ruby # version 3.3.1, orapt install ruby-bundler # version 2.3.5-2See 'snap info ruby' for additional versions.
EDIT2 I added the whenever
command to the Dockerfile. The app is deployed to the server without any error, but when I run crontab -l
to verify the CRON jobs were created, then there are none - crontab is empty.
# syntax = docker/dockerfile:1ARG RUBY_VERSION=3.2.2FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as baseWORKDIR /railsENV RAILS_ENV="production" \ BUNDLE_DEPLOYMENT="1" \ BUNDLE_PATH="/usr/local/bundle" \ BUNDLE_WITHOUT="development" FROM base as buildRUN apt-get update -qq && \ apt-get install --no-install-recommends -y build-essential curl git libvips node-gyp pkg-config python-is-python3 libpq-dev cronCOPY Gemfile Gemfile.lock ./RUN bundle install && \ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ bundle exec bootsnap precompile --gemfileCOPY . .# Create empty crontab fileRUN crontab -l | { cat; echo ""; } | crontab -# Update crontab file using whenever commandRUN bundle exec whenever --update-crontabRUN bundle exec bootsnap precompile app/ lib/RAILS_MASTER_KEYRUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompileFROM baseRUN apt-get update -qq && \ apt-get install --no-install-recommends -y curl libvips postgresql-client && \ rm -rf /var/lib/apt/lists /var/cache/apt/archivesCOPY --from=build /usr/local/bundle /usr/local/bundleCOPY --from=build /rails /railsRUN useradd rails --create-home --shell /bin/bash && \ chown -R rails:rails db log storage tmpUSER rails:railsENTRYPOINT ["/rails/bin/docker-entrypoint"]EXPOSE 3000CMD ["./bin/rails", "server"]
How to configure whenever gem with dokku?