Skip to content

Commit

Permalink
Added rake tasks to do migrations and deliver messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Jul 23, 2009
1 parent a50d3e2 commit 8e2a6a3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/apn_on_rails.rb
@@ -1,3 +1,4 @@
Dir.glob(File.join(File.dirname(__FILE__), 'apn_on_rails', '**/*.rb')).each do |f| Dir.glob(File.join(File.dirname(__FILE__), 'apn_on_rails', '**/*.rb')).sort.each do |f|
require File.expand_path(f) require File.expand_path(f)
end end

17 changes: 17 additions & 0 deletions lib/apn_on_rails/tasks/apn.rake
@@ -0,0 +1,17 @@
namespace :apn do

namespace :notifications do

desc "Deliver all unsent APN notifications."
task :deliver => [:environment] do
notifications = APN::Notification.all(:conditions => {:sent_at => nil})
unless notifications.empty?
include ActionView::Helpers::TextHelper
RAILS_DEFAULT_LOGGER.info "APN: Attempting to deliver #{pluralize(notifications.size, 'notification')}."
APN::Notification.send_notifications(notifications)
end
end

end # notifications

end # apn
13 changes: 13 additions & 0 deletions lib/apn_on_rails/tasks/db.rake
@@ -0,0 +1,13 @@
namespace :apn do

namespace :db do

desc 'Runs the migrations for apn_on_rails.'
task :migrate => [:environment] do
puts File.join(File.dirname(__FILE__), '..', '..', 'apn_on_rails', 'db', 'migrate')
ActiveRecord::Migrator.up(File.join(File.dirname(__FILE__), '..', '..', 'apn_on_rails', 'db', 'migrate'))
end

end # db

end # apn
3 changes: 3 additions & 0 deletions lib/apn_on_rails_tasks.rb
@@ -0,0 +1,3 @@
Dir.glob(File.join(File.dirname(__FILE__), 'apn_on_rails', 'tasks', '**/*.rake')).each do |f|
load File.expand_path(f)
end

0 comments on commit 8e2a6a3

Please sign in to comment.