2015-09-18 32 views
0

在我的舊報告中,我通過Delayed :: Job安排了具有方法名稱「execute_schedule_reports」的報告。如何從Delayed :: Job Handler中替換方法名稱?

現在在我的新報告中,我有不同的方法名稱「new_execute_schedule_reports」。

我想將所有舊的計劃報告移至新的計劃報告。

舊報告的對象是:

ScheduleReport.last 
    ScheduleReport Load (0.5ms) SELECT `schedule_reports`.* FROM `schedule_reports` ORDER BY `schedule_reports`.`id` DESC LIMIT 1 
=> #<ScheduleReport id: 208, vendor_id: 116211, scheduled_report_store_type: "Club", scheduled_report_store_id: 116524, team_id: nil, product_id: "46067", abbreviate_product_name: nil, payment_status: nil, report_organizations: nil, date_filter: nil, report_name: 3, report_type: 0, email_to: "[email protected]", day: 2, repeat: nil, time: "12:15 AM", last_run_at: "2015-09-18 06:55:07", next_run_at: "2015-09-19 16:15:00", next_run_job_id: 1546516, created_at: "2015-09-18 06:51:33", updated_at: "2015-09-18 06:55:15", skip_items_with_zero_sale: false, club_id: nil, spirit_id: nil, from_date: "", to_date: "", standard_or_custom_report_id: nil, standard_or_custom_report: nil> 

d = Delayed::Job.last 
    Delayed::Backend::ActiveRecord::Job Load (0.5ms) SELECT `delayed_jobs`.* FROM `delayed_jobs` ORDER BY `delayed_jobs`.`id` DESC LIMIT 1 
=> #<Delayed::Backend::ActiveRecord::Job id: 1546516, priority: 20, attempts: 0, handler: "--- !ruby/object:Delayed::PerformableMethod\nobject...", last_error: nil, run_at: "2015-09-19 16:00:00", locked_at: nil, failed_at: nil, locked_by: nil, created_at: "2015-09-18 06:55:15", updated_at: "2015-09-18 06:55:15", queue: "schedule_report"> 

d.handler 
=> "--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/class 'ScheduleReport'\nmethod_name: :execute_schedule_reports\nargs:\n- 208\n" 

現在我需要用新的一個是「new_execute_schedule_reports」

我怎麼能修改此處理程序的方法名修改延遲::工作處理程序的方法名稱?

這裏我在用gsub來思考!

這是一個正確的方法嗎?

請給我建議。

謝謝。

回答

0

grep -rl'execute_schedule_reports'./ | xargs的SED -i「S/execute_schedule_reports/new_execute_schedule_reports/G」

這將搜索所有文件相對於當前目錄字符串「execute_schedule_reports」和替換「execute_schedule_reports」與「new_execute_schedule_reports」爲的每次出現每個文件中的字符串。