Skip to content

Commit

Permalink
automate rake task using whenever gem
Browse files Browse the repository at this point in the history
  • Loading branch information
npauzenga committed Nov 4, 2015
1 parent a3f02f7 commit 0cc7c4e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -13,6 +13,7 @@ gem "puma"
gem "bootstrap-sass"
gem "bcrypt"
gem "responders", "~>2.0"
gem "whenever"

group :test do
gem "coveralls"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -70,6 +70,7 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
chronic (0.10.2)
coderay (1.1.0)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -284,6 +285,8 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
whenever (0.9.4)
chronic (>= 0.6.3)
xpath (2.0.0)
nokogiri (~> 1.3)

Expand Down Expand Up @@ -325,6 +328,7 @@ DEPENDENCIES
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)
whenever

BUNDLED WITH
1.10.6
31 changes: 31 additions & 0 deletions config/schedule.rb
@@ -0,0 +1,31 @@
# Use this file to easily define all of your cron jobs.
#
# It's helpful, but not entirely necessary to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron

# Example:
#
# set :output, "/path/to/my/cron_log.log"
#
# every 2.hours do
# command "/usr/bin/some_great_command"
# runner "MyModel.some_method"
# rake "some:great:rake:task"
# end
#
# every 4.days do
# runner "AnotherModel.prune_old_records"
# end

# Learn more: http://github.com/javan/whenever

# for testing:
# set :environment, "test"
#
# every 1.minutes do
# rake "todo:delete_items"
# end

every 1.day, at: "12:00 am" do
rake "todo:delete_items"
end
9 changes: 2 additions & 7 deletions spec/features/todos_automatically_delete_spec.rb
@@ -1,19 +1,14 @@
# require "rails_helper"
# require "rake"
#
# feature "Todos are automatically purged" do
# include TestFactories
#
# rake = Rake.application
# rake.init
# rake.load_rakefile
#
# let(:todo) { valid_todo }
#
# # set whenever to work in test
# scenario "Successfully after 7 days" do
# old_todo = todo
# old_todo.update_attribute(:created_at, (Time.now.utc - 7.days))
# rake["todo:delete_items"].invoke
# Time.now.change(hour: 0)
# expect(Todo.find_by(id: old_todo.id)).to be nil
# end
# end

0 comments on commit 0cc7c4e

Please sign in to comment.