vendredi 18 septembre 2015

how to replace method name from Delayed::Job Handler?

In my old reports, I schedule the report through Delayed::Job which have the method name "execute_schedule_reports".

Now in my new reports, I have different method name "new_execute_schedule_reports".

I want to move all old schedule report to new one.

Old reports objects are:

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: "bcv@sdf.com", 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"

Now I need to modify the method name in Delayed::Job Handler with new one that is "new_execute_schedule_reports"

How can I modify this handler's method name?

Here What I am thinking by using the gsub!.

Is it a right approach?

Please suggest me.

Thank you.

Aucun commentaire:

Enregistrer un commentaire