Zayyana Khoir

Joined

10 Experience
0 Lessons Completed
0 Questions Solved

Activity

Hey,
I have implement schedule tasks to existing project using rails 4, when i rake tasks on development mode works and database updated, but when i rake tasks on production server it's work but database not updated.
Here is my code

// schedule.rb

every :hour do
  rake "profile_update:inactive"
end
//profile_update.rake

namespace :profile_update do
  desc "Update gps status profiles"
  task inactive: :environment do
    @profile_short = Heartrate.select('Date_Format(TIMEDIFF(now(), MAX(heartrates.start_time)), "%H") selisih_date, profiles.id, MAX(heartrates.start_time) start_time').joins(:profile).where('heartrates.start_time BETWEEN ? AND ?', DateTime.now.end_of_day-1, DateTime.now.end_of_day).where('profiles.gps_status = 1').group(:profile_id).order('profiles.id ASC')
      if @profile_short.present?
      @profile_short.each do |profile|
        if profile.selisih_date.to_i < 1
          cek_safety =  SafetyAlert.select('Date_Format(TIMEDIFF(now(), created_at), "%H") selisih_date_safety').where(profile_id: profile.id).where('created_at BETWEEN ? AND ?', profile.start_time, DateTime.now.end_of_day).last
          if cek_safety.present?
          else
            if profile.selisih_date.to_i >= 1
              Profile.where(id: profile.profile_id).update_all(gps_status: 0)
            end
          end
        else
          cek_safety =  SafetyAlert.select('Date_Format(TIMEDIFF(now(), created_at), "%H") selisih_date_safety').where(profile_id: profile.id).where('created_at BETWEEN ? AND ?', profile.start_time, DateTime.now.end_of_day).last
          if cek_safety.present?
            if cek_safety.selisih_date_safety.to_i >= 1
              Profile.where(id: profile.id).update_all(gps_status: 0)
            end
          else
            Profile.where(id: profile.id).update_all(gps_status: 0)
          end
        end
      end
    end
  end

end
logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.