On Mon, Oct 27, 2008 at 1:11 AM, Benjamin LAN-SUN-LUK
<benjamin.lan-sun-luk(a)supinfo.com> wrote:
Now, the time of schedules are configurable.
Signed-off-by: Benjamin LAN-SUN-LUK <benjamin.lan-sun-luk(a)supinfo.com>
ACK, with conditions that need to be addressed in the code. Please see
comments inline below and fix them before pushing.
---
app/models/product.rb | 1 +
app/models/user_mailer.rb | 10 ++++++
.../user_mailer/sprints_products_status.html.erb | 9 +++++
config/initializers/schedules.rb | 34 ++++++++++++++++++-
config/schedules.yml | 7 ++++
We should probably follow our prvious pattern and make this
config/schedules.yml.example.
5 files changed, 59 insertions(+), 2 deletions(-)
create mode 100644 app/views/user_mailer/sprints_products_status.html.erb
create mode 100644 config/schedules.yml
diff --git a/app/models/product.rb b/app/models/product.rb
index 1cd3035..78cff45 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -30,6 +30,7 @@ class Product < ActiveRecord::Base
has_many :backlog, :class_name => 'UserStory', :order => 'priority
ASC'
has_many :product_roles
has_many :users, :through => :product_roles
+ has_many :sprints
# Returns whether the user can create sprints for this product.
#
diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb
index 896a688..9c70473 100644
--- a/app/models/user_mailer.rb
+++ b/app/models/user_mailer.rb
@@ -36,4 +36,14 @@ class UserMailer < ActionMailer::Base
subject "No task has been detected"
body :user => user, :backlog_items => backlog_items
end
+
+ # Send an email to a user to notify him the status of each sprint of his
+ # products.
+ #
+ def sprints_products_status(user, products)
+ recipients user.email
+ from MAIL_CONFIG[:from]
+ subject "Status of sprints"
+ body :user => user, :products => products
+ end
end
diff --git a/app/views/user_mailer/sprints_products_status.html.erb
b/app/views/user_mailer/sprints_products_status.html.erb
new file mode 100644
index 0000000..9ae07c9
--- /dev/null
+++ b/app/views/user_mailer/sprints_products_status.html.erb
@@ -0,0 +1,9 @@
+Dear <%= @user.display_name %>,
+
+Here the sprint's status of every product.
+<% @products.each do |product| %>
+- <%= product.name %>
+<% product.sprints.each do |sprint| %>
+ - <%= sprint.title %> => <%= Sprint::STATUS_TEXT.collect { |s|
s.first if (s.last == sprint.status) }.compact %>
This line has mixed spaces and tabs at the beginning of the line.
Please fix that.
+<% end %>
+<% end %>
diff --git a/config/initializers/schedules.rb b/config/initializers/schedules.rb
index fb58101..aa8a515 100644
--- a/config/initializers/schedules.rb
+++ b/config/initializers/schedules.rb
@@ -2,6 +2,10 @@ require 'fastthread'
require 'openwfe/util/scheduler'
include OpenWFE
+# Load the schedules configuration
+schedules_file_path = "#{RAILS_ROOT}/config/schedules.yml"
+SCHEDULES_CONFIG = YAML.load(File.open(schedules_file_path))
+
# Initialize a threads array
threads = []
@@ -9,8 +13,10 @@ threads << Thread.new do
scheduler = Scheduler.new
scheduler.start
- # Do this everyday at 05:00 am
- scheduler.schedule('0 5 * * *') do # TODO Time must be configurable
+ hours = SCHEDULES_CONFIG[:no_activity_or_no_task_recorded_time][:hours]
+ minutes = SCHEDULES_CONFIG[:no_activity_or_no_task_recorded_time][:minutes]
+
+ scheduler.schedule("#{minutes} #{hours} * * *") do
user_no_activity_on_backlog_items = {}
user_no_tasks_on_backlog_items = {}
@@ -50,5 +56,29 @@ threads << Thread.new do
scheduler.join
end
+threads << Thread.new do
+ scheduler = Scheduler.new
+ scheduler.start
+
+ hours = SCHEDULES_CONFIG[:sprints_products_status_time][:hours]
+ minutes = SCHEDULES_CONFIG[:sprints_products_status_time][:minutes]
+
+ scheduler.schedule("#{minutes} #{hours} * * *") do
+ user_with_products = {}
+
+ Product.find(:all).each do |product|
+ product_owner = product.owner
+ user_with_products[product_owner] ||= []
+ user_with_products[product_owner] << product
+ end
+
+ user_with_products.each do |owner, products|
+ UserMailer.deliver_sprints_products_status(owner, products)
+ end
+ end
+
+ scheduler.join
+end
+
# Run all threads
threads.each { |thread| thread.run }
\ No newline at end of file
Need to add a newline to the end of this file.
diff --git a/config/schedules.yml b/config/schedules.yml
new file mode 100644
index 0000000..7883c15
--- /dev/null
+++ b/config/schedules.yml
@@ -0,0 +1,7 @@
+---
+ :no_activity_or_no_task_recorded_time:
+ :hours: 5
+ :minutes: 0
+ :sprints_products_status_time:
+ :hours: 5
+ :minutes: 0
\ No newline at end of file
Need to add a new line to the end of the file.
--
1.6.0.2
_______________________________________________
projxp-devel mailing list
projxp-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/projxp-devel
--
Darryl L. Pierce <mcpierce(a)gmail.com>
Visit the Infobahn Offramp: <
http://mcpierce.multiply.com>
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant