2
votes

I am using delayed_job and in a page I am showing all the information related to the job.

listing jobs as:

<% @jobs.each do |item| %>   
  <%= item.inspect %> 
<% end %>

I am getting details as:

#<Delayed::Backend::ActiveRecord::Job id: 57, priority: 0, attempts: 0, handler: "--- !ruby/object:Delayed::PerformableMailer\nobject...", last_error: nil, run_at: "2016-08-30 00:47:46", locked_at: nil, failed_at: nil, locked_by: nil, created_at: "2016-08-30 00:47:46", updated_at: "2016-08-30 00:47:46", queue: nil> #<Delayed::Backend::ActiveRecord::Job id: 55, priority: 0, attempts: 0, handler: "--- !ruby/object:Delayed::PerformableMailer\nobject...", last_error: nil, run_at: "2016-08-29 09:46:44", locked_at: nil, failed_at: nil, locked_by: nil, created_at: "2016-08-29 09:46:44", updated_at: "2016-08-29 09:46:44", queue: nil> 

With the above data I am able to show the id, priority, attempts etc; But incase of handler, there is a big string consists of object, method_name etc; How can I show this handler.object and handler.method_name in rails view? Please help:

This is my handler string:

--- !ruby/object:Delayed::PerformableMailer object: !ruby/class 'SubscriptionNotifier' method_name: :welcome args: - !ruby/object:User raw_attributes: deleted_at: name: in test email: [email protected] encrypted_password: "$2a$10$IUOp.QkdIPauTnVyBRQQXOD0nA.cUc1og/pIEQneBx3nWVY/94Hti" phone: '' website: '' designations: '' id: 25 reset_password_token: reset_password_sent_at: remember_created_at: sign_in_count: '0' current_sign_in_at: last_sign_in_at: current_sign_in_ip: last_sign_in_ip: confirmation_token: created_at: &1 2016-08-30 00:47:46.390321885 Z updated_at: *1 contact_id: location: username: photo_file_name: photo_content_type: photo_file_size: photo_updated_at: time_zone: beta_code: account_id: 26 admin: true logo_file_name: logo_content_type: logo_file_size: logo_updated_at: company_name: license_number: spark_id: attributes: !ruby/object:ActiveRecord::AttributeSet attributes: !ruby/object:ActiveRecord::LazyAttributeHash types: id: &6 !ruby/object:ActiveRecord::Type::Integer precision: scale: limit: range: !ruby/range begin: -2147483648 end: 2147483648 excl: true email: &2 !ruby/object:ActiveRecord::Type::String precision: scale: limit: encrypted_password: *2 reset_password_token: *2 reset_password_sent_at: &7 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: &3 !ruby/object:ActiveRecord::Type::DateTime precision: scale: limit: remember_created_at: &8 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 sign_in_count: &4 !ruby/object:ActiveRecord::Type::Integer precision: scale: limit: range: !ruby/range begin: -2147483648 end: 2147483648 excl: true current_sign_in_at: &9 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 last_sign_in_at: &10 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 current_sign_in_ip: *2 last_sign_in_ip: *2 confirmation_token: *2 created_at: &11 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 updated_at: &12 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 contact_id: *4 location: *2 username: *2 photo_file_name: *2 photo_content_type: *2 photo_file_size: *4 photo_updated_at: &13 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 designations: *2 name: *2 phone: *2 website: *2 time_zone: *2 beta_code: *2 account_id: *4 admin: &14 !ruby/object:ActiveRecord::Type::Boolean precision: scale: limit: deleted_at: &5 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 logo_file_name: *2 logo_content_type: *2 logo_file_size: *4 logo_updated_at: &15 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 company_name: *2 license_number: *2 spark_id: *2 values: id: email: '' encrypted_password: '' reset_password_token: reset_password_sent_at: remember_created_at: sign_in_count: '0' current_sign_in_at: last_sign_in_at: current_sign_in_ip: last_sign_in_ip: confirmation_token: created_at: updated_at: contact_id: location: username: photo_file_name: photo_content_type: photo_file_size: photo_updated_at: designations: name: phone: website: time_zone: beta_code: account_id: admin: f deleted_at: logo_file_name: logo_content_type: logo_file_size: logo_updated_at: company_name: license_number: spark_id: additional_types: {} materialized: true delegate_hash: deleted_at: !ruby/object:ActiveRecord::Attribute::FromUser name: deleted_at value_before_type_cast: type: *5 value: name: !ruby/object:ActiveRecord::Attribute::FromUser name: name value_before_type_cast: in test type: *2 value: in test email: !ruby/object:ActiveRecord::Attribute::FromUser name: email value_before_type_cast: [email protected] type: *2 value: [email protected] encrypted_password: !ruby/object:ActiveRecord::Attribute::FromUser name: encrypted_password value_before_type_cast: "$2a$10$IUOp.QkdIPauTnVyBRQQXOD0nA.cUc1og/pIEQneBx3nWVY/94Hti" type: *2 value: "$2a$10$IUOp.QkdIPauTnVyBRQQXOD0nA.cUc1og/pIEQneBx3nWVY/94Hti" phone: !ruby/object:ActiveRecord::Attribute::FromUser name: phone value_before_type_cast: '' type: *2 value: '' website: !ruby/object:ActiveRecord::Attribute::FromUser name: website value_before_type_cast: '' type: *2 value: '' designations: !ruby/object:ActiveRecord::Attribute::FromUser name: designations value_before_type_cast: '' type: *2 value: '' id: !ruby/object:ActiveRecord::Attribute::FromUser name: id value_before_type_cast: 25 type: *6 value: 25 reset_password_token: !ruby/object:ActiveRecord::Attribute::FromDatabase name: reset_password_token value_before_type_cast: type: *2 reset_password_sent_at: !ruby/object:ActiveRecord::Attribute::FromDatabase name: reset_password_sent_at value_before_type_cast: type: *7 remember_created_at: !ruby/object:ActiveRecord::Attribute::FromDatabase name: remember_created_at value_before_type_cast: type: *8 sign_in_count: !ruby/object:ActiveRecord::Attribute::FromDatabase name: sign_in_count value_before_type_cast: '0' type: *4 current_sign_in_at: !ruby/object:ActiveRecord::Attribute::FromDatabase name: current_sign_in_at value_before_type_cast: type: *9 last_sign_in_at: !ruby/object:ActiveRecord::Attribute::FromDatabase name: last_sign_in_at value_before_type_cast: type: *10 current_sign_in_ip: !ruby/object:ActiveRecord::Attribute::FromDatabase name: current_sign_in_ip value_before_type_cast: type: *2 last_sign_in_ip: !ruby/object:ActiveRecord::Attribute::FromDatabase name: last_sign_in_ip value_before_type_cast: type: *2 confirmation_token: !ruby/object:ActiveRecord::Attribute::FromDatabase name: confirmation_token value_before_type_cast: type: *2 created_at: !ruby/object:ActiveRecord::Attribute::FromUser name: created_at value_before_type_cast: *1 type: *11 value: *1 updated_at: !ruby/object:ActiveRecord::Attribute::FromUser name: updated_at value_before_type_cast: *1 type: *12 value: *1 contact_id: !ruby/object:ActiveRecord::Attribute::FromDatabase name: contact_id value_before_type_cast: type: *4 location: !ruby/object:ActiveRecord::Attribute::FromDatabase name: location value_before_type_cast: type: *2 username: !ruby/object:ActiveRecord::Attribute::FromDatabase name: username value_before_type_cast: type: *2 photo_file_name: !ruby/object:ActiveRecord::Attribute::FromDatabase name: photo_file_name value_before_type_cast: type: *2 value: photo_content_type: !ruby/object:ActiveRecord::Attribute::FromDatabase name: photo_content_type value_before_type_cast: type: *2 value: photo_file_size: !ruby/object:ActiveRecord::Attribute::FromDatabase name: photo_file_size value_before_type_cast: type: *4 value: photo_updated_at: !ruby/object:ActiveRecord::Attribute::FromDatabase name: photo_updated_at value_before_type_cast: type: *13 time_zone: !ruby/object:ActiveRecord::Attribute::FromDatabase name: time_zone value_before_type_cast: type: *2 beta_code: !ruby/object:ActiveRecord::Attribute::FromDatabase name: beta_code value_before_type_cast: type: *2 account_id: !ruby/object:ActiveRecord::Attribute::FromUser name: account_id value_before_type_cast: 26 type: *4 value: 26 admin: !ruby/object:ActiveRecord::Attribute::FromUser name: admin value_before_type_cast: true type: *14 value: true logo_file_name: !ruby/object:ActiveRecord::Attribute::FromDatabase name: logo_file_name value_before_type_cast: type: *2 value: logo_content_type: !ruby/object:ActiveRecord::Attribute::FromDatabase name: logo_content_type value_before_type_cast: type: *2 value: logo_file_size: !ruby/object:ActiveRecord::Attribute::FromDatabase name: logo_file_size value_before_type_cast: type: *4 value: logo_updated_at: !ruby/object:ActiveRecord::Attribute::FromDatabase name: logo_updated_at value_before_type_cast: type: *15 company_name: !ruby/object:ActiveRecord::Attribute::FromDatabase name: company_name value_before_type_cast: type: *2 license_number: !ruby/object:ActiveRecord::Attribute::FromDatabase name: license_number value_before_type_cast: type: *2 spark_id: !ruby/object:ActiveRecord::Attribute::FromDatabase name: spark_id value_before_type_cast: type: *2 new_record: false active_record_yaml_version: 0 - !ruby/object:Account raw_attributes: deleted_at: id: 26 created_at: &16 2016-08-30 00:47:46.181857956 Z updated_at: *16 name: full_domain: attributes: !ruby/object:ActiveRecord::AttributeSet attributes: !ruby/object:ActiveRecord::LazyAttributeHash types: id: *6 name: *2 created_at: &18 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 updated_at: &19 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 full_domain: *2 deleted_at: &17 !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter subtype: *3 values: id: name: created_at: updated_at: full_domain: deleted_at: additional_types: {} materialized: true delegate_hash: deleted_at: !ruby/object:ActiveRecord::Attribute::FromUser name: deleted_at value_before_type_cast: type: *17 value: id: !ruby/object:ActiveRecord::Attribute::FromUser name: id value_before_type_cast: 26 type: *6 value: 26 created_at: !ruby/object:ActiveRecord::Attribute::FromUser name: created_at value_before_type_cast: *16 type: *18 value: *16 updated_at: !ruby/object:ActiveRecord::Attribute::FromUser name: updated_at value_before_type_cast: *16 type: *19 value: *16 name: !ruby/object:ActiveRecord::Attribute::FromDatabase name: name value_before_type_cast: type: *2 full_domain: !ruby/object:ActiveRecord::Attribute::FromDatabase name: full_domain value_before_type_cast: type: *2 new_record: false active_record_yaml_version: 0

This is the error log I am getting when I used @kiddorails answer:

ArgumentError - undefined class/module Account:
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/class_loader.rb:54:in resolve'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/class_loader.rb:46:in
find'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/class_loader.rb:28:in load'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:396:in
resolve_class'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:208:in visit_Psych_Nodes_Mapping'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:16:in
visit'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:6:in accept'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in
accept'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:330:in block in register_empty'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:330:in
register_empty'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:141:in visit_Psych_Nodes_Sequence'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:16:in
visit'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:6:in accept'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in
accept'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:338:in block in revive_hash'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:336:in
revive_hash'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:374:in revive'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:208:in
visit_Psych_Nodes_Mapping'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:16:in visit'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:6:in
accept'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in accept'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:311:in
visit_Psych_Nodes_Document'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:16:in visit'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:6:in
accept'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in accept'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych/nodes/node.rb:38:in
to_ruby'
/home/abcuser/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:253:in load' app/views/admin/_jobs_table.html.erb:17:inblock in _app_views_admin__jobs_html_erb___466009326523590843_337924780' activerecord (4.2.6) lib/active_record/relation/delegation.rb:46:in each' app/views/admin/_jobs_table.html.erb:15:in _app_views_admin__jobs_table_html_erb___466009326523590843_337924780' actionview (4.2.6) lib/action_view/template.rb:145:in `block in render'

1

1 Answers

1
votes

That is yaml format. You need to parse it as following to get the data.

job = Delayed::Job.last
data = YAML.load job.handler # parse the yaml
puts data.method_name #=> :welcome args
puts data.object #=> Delayed::PerformableMailer

You can iterate like:

<% @jobs.each do |item| %>   
  <% data = YAML.load item.handler %> 
  <%= item.id %>
  <%= data.method_name %>
  <%= data.object %>
<% end %>