rake-task

creating rake task for importing data from csv file

江枫思渺然 提交于 2019-12-12 04:43:03
问题 I am creating a rake task to import csv file data to my database (MySQL). Here is what I did but It is not working require 'csv' namespace :tech do desc "Import tech from csv file" task temp: :environment do file = "tech.csv" CSV.foreach(file, :headers => true) do |row| Temp.create ({ :current => row[1], :today => row[2], :week=> row[3], :month => row[4] }) end end end but when I run rake tech:temp it throws this error Don't know how to build task 'tech:temp' y/gems/2.0.0/gems/rake-10.3.2/lib

Heroku Scheduler - set up daily task

廉价感情. 提交于 2019-12-12 03:25:11
问题 I'm having trouble understanding Heroku's scheduler documentation. They give this as example code, but I'm not sure what's what: desc "This task is called by the Heroku scheduler add-on" task :update_feed => :environment do puts "Updating feed..." NewsFeed.update puts "done." end task :send_reminders => :environment do User.send_reminders end I am hoping to use this scheduler to call method from my NotificationsController on a daily basis. I've tried modifying their code to: desc "This task

Debugging why a create method is not saving to the model

ε祈祈猫儿з 提交于 2019-12-12 01:15:13
问题 I have this method which after a rake task should save my data to the model, I am trying to update 2 columns at a time, which shouldnt be a problem def update_fixtures #rake task method Fixture.destroy_all get_home_fixtures.each {|home| Fixture.create!(home_team: home )} get_away_fixtures.each {|away| Fixture.create!(away_team: away )} end In this instance only the away team will save, however if i do this def update_fixtures #rake task method Fixture.destroy_all get_away_fixtures.each {|away

elasticsearch stops indexing new documents after a while, using Tire

回眸只為那壹抹淺笑 提交于 2019-12-11 15:03:49
问题 I have my website running, with ElasticSearch, using Tire. In the background, I have a rake task that is looping over thousands of objects and creating one record for each of them. At first, the records are indexed, and every time I refresh my website, I can see the number of records found go up. But at some point, it just stops. It saves the records to mysql, but does not index them anymore. Note that the site and the search are still up and running. Why is that? Is there some kind of lock

Does invoking multiple tasks from a parent rake loads environment for each of them

拜拜、爱过 提交于 2019-12-11 13:54:06
问题 If I have one rake which invokes multiple other rakes. Once I initiate the parent rake rake myapp:main Then invokes done within the rake would load environment for each task or its just one time activity done while running rake myapp:main ? namespace :myapp do desc "Main Run" task :main => :environment do Rake::Task['myapp:task1'].invoke Rake::Task['myapp:task2'].invoke end task :task1 => :environment do # Does the first task end task :task2 => :environment do # Does the second task end end

Setting env variable to a cron scheduled task using whenever gem

雨燕双飞 提交于 2019-12-11 12:41:41
问题 In my code below, I wanted to set few environment variables stored in a file. Am I missing something? Printing env in production after 'bundle exec whenever' does not show the environment variables set. Using whenever gem for a scheduled cron task and spent hours figuring this. Any other way can be suggested too. every 1.day, :at => '2:30 am' do # Run shell script to assign variables and continue the rake task system "for line in `cat config/myEnvFile.env` ; do export $line ; done" rake "task

Load only part of environment for rake task?

放肆的年华 提交于 2019-12-11 11:29:31
问题 I've seen a bunch of articles relating to loading the entire Rails environment for a task. However, I'm concerned that this is unnecessary because I only use two models for my task (plus the 'resque' and 'resque/scheduler'). How can I only load certain parts of an environment for my task? Also, this question seems to be the same, but it's gotten old and no one seems to have sufficiently answered it... I'll ask now, ahead of time, that someone please give code rather than just an explanation.

Render a view from a rake task

此生再无相见时 提交于 2019-12-11 11:20:14
问题 I'm trying to send mail from a rake task. I've already manage to send email but the problem is the file I send. I want to send a view which will be modify each time that the mail will be send. I've install the gem render_anywhere to render a view from my rake task but I keep having this error : NoMethodError: undefined method `formats' for String:0x007ff1a1068b88> here is the part of my rake task that should do the job : require 'render_anywhere' include RenderAnywhere require Rails.root.join

Testing a method defined in a rake task

蹲街弑〆低调 提交于 2019-12-10 12:39:20
问题 I want to test a method defined in a rake task. rake file #lib/tasks/simple_task.rake namespace :xyz do task :simple_task => :environment do begin if task_needs_to_run? puts "Lets run this..." #some code which I don't wish to test ... end end end def task_needs_to_run? # code that needs testing return 2 > 1 end end Now, I want to test this method, task_needs_to_run? in a test file How do I do this ? Additional note: I would ideally want test another private method in the rake task as well...

Faker "Don't Know How to Build Task?

≯℡__Kan透↙ 提交于 2019-12-10 11:57:13
问题 I checked out the questions that have already been asked on this subject, "There are many", but I do not find a solution. I have a fairly large task and the files name is 'sample_employee_data.rake'... so here goes: namespace :db do desc "Fill database with sample Employee data" task populate: :environment do @gender = ["Male", "Female"] @role = ["Staff", "Support", "Team_Leader", "Manager", "Director"] @marital_status = ["Single", "Married"] @primary_position = ["Household", "Job Developer",