mercredi 1 janvier 2020

active job not saving data in the database rails

i want to save this message five time from active jobs not from controller. is there anyway to that ? here message.save just returning true and its not saving the message in databas.


class MessageBroadcastJob < ApplicationJob
  queue_as :default

  def perform(message)
    for i in 0..5
      message.save!
      ActionCable.server.broadcast 'chat', {message: render_message(message)}
    end
  end

  private

  def render_message(message)
    MessagesController.render(
        partial: 'message',
        locals: {
            message: message
        }

    )
  end
end

this code is from model.

class Message < ApplicationRecord
  belongs_to :user
  after_create_commit {
    MessageBroadcastJob.perform_later(self)
  }
end

Aucun commentaire:

Enregistrer un commentaire