Skip to content
Newer
Older
100644 44 lines (36 sloc) 1.33 KB
8ec14d3 script to run as a cron job.
Jason Adam Young authored
1 #!/usr/bin/env ruby
2 require 'getoptlong'
3
4 ### Program Options
5 progopts = GetoptLong.new(
6 [ "--environment","-e", GetoptLong::OPTIONAL_ARGUMENT ]
7 )
8
9 @environment = 'production'
10 progopts.each do |option, arg|
11 case option
12 when '--environment'
13 @environment = arg
14 else
15 puts "Unrecognized option #{opt}"
16 exit 0
17 end
18 end
19 ### END Program Options
20
21 if !ENV["RAILS_ENV"] || ENV["RAILS_ENV"] == ""
22 ENV["RAILS_ENV"] = @environment
23 end
24
25 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
26
27
28 # find sessions starting tomorrow within the hour that this script is running
29 tomorrow_learn_sessions = LearnSession.find_tomorrow_sessions
30 if(!tomorrow_learn_sessions.blank?)
31 tomorrow_learn_sessions.each do |learn_session|
32 interested_users = learn_session.connected_users(LearnConnection::INTERESTED)
33 if(!interested_users.blank?)
34 interested_users.each do |person|
35 Notification.create(:notifytype => Notification::LEARN_UPCOMING_SESSION, :user => person, :creator => User.systemuser, :additionaldata => {:learn_session_id => learn_session.id})
36 end
37 puts "Created #{pluralize(interested_users.size,'notifications')} for tomorrow's Learn Session (ID: #{learn_session.id})"
38 else
39 puts "No notifications for tomorrow's Learn Session (ID: #{learn_session.id})"
40 end
41 end
42 end
43
44
Something went wrong with that request. Please try again.