diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index 09faecfe..9b59b2bf 100644 --- a/app/controllers/jobs_controller.rb +++ b/app/controllers/jobs_controller.rb @@ -281,8 +281,15 @@ def unwatch flash[:notice] = 'Job is now unwatched. You can find a list of your watched jobs on the dashboard.' redirect_to :back end + + def close_jobs + jobs = Job.where('latest_start_date < ?', Time.now) - + jobs.each do |job| + job.update_attribute(:status, 1) + job.save(validate: false) + end + end protected diff --git a/app/models/job.rb b/app/models/job.rb index 40264427..2518f297 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -341,6 +341,15 @@ def self.human_attribute_name(attr, options = {}) end return super end + + def self.close_jobs + jobs = Job.where('latest_start_date < ?', Time.now) + + jobs.each do |job| + job.update_attribute(:status, 1) + job.save(validate: false) + end + end # Returns a string containing the category names taken by this Job # e.g. "robotics,signal processing" @@ -434,15 +443,19 @@ def resend_email(send_email = false) end end + + protected + #delete this? def earliest_start_date_must_be_before_latest - errors[:earliest_start_date] << "cannot be later than the latest start date" if + errors[:start_date] << "cannot be later than the latest start date" if latest_start_date.present? && earliest_start_date.present? && earliest_start_date > latest_start_date + end def latest_start_date_must_be_before_end_date - errors.add(:latest_start_date, "cannot be later than the end date") if + errors.add(:apply_by_date, "cannot be later than the end date") if latest_start_date.present? && !open_ended_end_date && latest_start_date > end_date end diff --git a/app/views/jobs/_form.html.haml b/app/views/jobs/_form.html.haml index bc6e6692..3ddbb34d 100644 --- a/app/views/jobs/_form.html.haml +++ b/app/views/jobs/_form.html.haml @@ -43,11 +43,11 @@ %dd = text_field :proglang, :name, :value => @job.proglang_list_of_job(true), :class => 'form-control', :id => 'proglangs-input', :placeholder => "(e.g. Python, machine shop)" %dt - = f.label :earliest_start_date, 'Earliest start date *' + = f.label :earliest_start_date, 'Start date *' %dd = f.text_field :earliest_start_date, :class => 'datepicker form-control', value: @job.earliest_start_date.present? ? @job.earliest_start_date.strftime("%Y-%m-%d") : nil %dt - = f.label :latest_start_date, 'Latest start date *' + = f.label :latest_start_date, 'Application Deadline*' %dd = f.text_field :latest_start_date, :class => 'datepicker form-control', value: @job.latest_start_date.present? ? @job.latest_start_date.strftime("%Y-%m-%d") : nil %dt diff --git a/app/views/jobs/show.html.haml b/app/views/jobs/show.html.haml index b1866374..3c1ea9dc 100644 --- a/app/views/jobs/show.html.haml +++ b/app/views/jobs/show.html.haml @@ -76,10 +76,10 @@ = h @job.proglang_list_of_job(true) - else (none) - %dt Earliest start date + %dt Start date %dd = @job.earliest_start_date.strftime("%b %e, %Y") - %dt Latest start date + %dt Application Deadline %dd = @job.latest_start_date.strftime("%b %e, %Y") %dt Position end date diff --git a/lib/tasks/scheduler.rake b/lib/tasks/scheduler.rake new file mode 100644 index 00000000..3bfb6045 --- /dev/null +++ b/lib/tasks/scheduler.rake @@ -0,0 +1,4 @@ +desc "This task is called by the Heroku scheduler add-on" +task :close_jobs => :environment do + Jobs.close_jobs +end