본문 바로가기
조회 수 1810 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
########################################
# deploying cron jobs with whenever gem
########################################
https://github.com/javan/whenever

1. gem install
gem install whenever

vi Gemfiles
------------------8<--------------------
gem 'whenever', :require => false
------------------8<--------------------
bundle

2. schedule.rb 파일 생성
wheneverize .
------------------8<--------------------
[add] writing `./config/schedule.rb'
[done] wheneverized!
------------------8<--------------------
Note: Mac에서는 path에 없으므로 bundle exec로 실행 (bundle exec wheneverize .)

3. schedule 설정 및 실행 (crontab syntax가 출력됨)
vi config/schedule.rb
------------------8<--------------------
set :output, "#{path}/log/cron_log.log"

every 1.minutes do
  command "echo 'abc'"
end
------------------8<--------------------
bundle exec whenever
--------- output ---------
* * * * * /bin/bash -l -c 'echo '\''abc'\'' >> /home/shareuser/html_public/log/cron_log.log 2>&1'

## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.


4. 위의 syntax로 crontab에 추가
crontab -e

5. 로그 확인
tail -f /home/shareuser/html_public/log/cron_log.log <------ cron으로 실행된 후의 출력값이 저장됨 (Rails 기반)
tail -f /var/log/cron <----- cron 실행 로그 (시스템 기반)


참고: 설정 예
------------------8<--------------------
every 3.hours do
  runner "MyModel.some_process" <--------- 모델클래스의 메소드 호출
  rake "my:rake:task" <------------------- rake 실행
  command "/usr/bin/my_great_command" <--- 시스템 호출
end

every 1.day, :at => '4:30 am' do
  runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
end

every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
  runner "SomeModel.ladeeda"
end

every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
  runner "Task.do_something_great"
end

every '0 0 27-31 * *' do
  command "echo 'you can use raw cron syntax too'"
end

# run this task only on servers with the :app role in Capistrano
# see Capistrano roles section below
every :day, :at => '12:20am', :roles => [:app] do
  rake "app_server:task"
end
------------------8<--------------------


Title
List of Articles
번호 제목 글쓴이 날짜 조회 수
31 Different Ways to Set Attributes in ActiveRecord (attribute, create, update, validation) Hojung 2015.05.24 1411
30 Ruby Style Guide Hojung 2015.02.05 1788
29 Refresh content automatically after some period time on Rails Hojung 2015.01.22 2382
28 Install ruby-filemagic on Mac (brew, libmagic) Hojung 2014.12.03 1618
27 Byte manipulation in Ruby Hojung 2014.12.03 1564
26 How to use Github for your project file Hojung 2014.09.24 1190
25 Ruby map, each, collect, inject, reject, select quick reference Hojung 2014.06.10 1919
24 Difference between collect, select, map and each in ruby Hojung 2014.06.10 1417
23 remove nil from array (compact, compact!) Hojung 2014.06.10 1700
22 remove child association model when parent removed (rails-dependent-destroy) Hojung 2014.06.03 1774
» deploying cron jobs with whenever gem Hojung 2014.06.01 1810
20 Get list of a class' instance methods Hojung 2014.06.01 1503
19 Optional method parameters in Ruby Hojung 2014.05.29 1586
18 Best Ruby On Rails Content Management Systems (CMS) Hojung 2014.04.26 2771
17 The simple way to print exceptions in Ruby Hojung 2014.04.07 1613
16 Ruby Symbols Hojung 2014.04.05 6380
15 What is the difference between a Symbol and String? Hojung 2014.04.05 1582
14 install Rbenv, ruby and rails Hojung 2014.03.22 1766
13 HTTP Posts in Ruby Hojung 2014.03.14 1766
12 optparse: mandatory and optional arguments example Hojung 2014.03.14 2453
Board Pagination ‹ Prev 1 2 Next ›
/ 2

Designed by sketchbooks.co.kr / sketchbook5 board skin

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5