Realtime Evenet Not working in Background job

I am trying to send realtime events just after the job is completed or after a function call is done. But in the client side it doesn’t display the alert which is mentioned over event_notify.js. I also un-commented hooks.py:
app_include_js = "/assets/my_app/js/event_notify.js"
But still I am not able to receive any alert. This issue was also raised in :
realtime-not-working-queues-2021
Some code for refrences:
custom function code:

    frappe.enqueue(
        method="my_app.media-queues.tasks_pipe.language_detection",
        queue="default",
        audio_filename= audio_filename,
        processed_docname=processed_doc.name,
        video_filename=video_filename,
        user=frappe.session.user
    )   

def language_detection(audio_filename: str, processed_docname: str, video_filename: str, user: str):
    print("user: ", user)
    print("before lang detection function call ")
    src_language=lang_detection(audio_filename, processed_docname)
    print("source language after lang detection is : ", src_language)
    print("before publishing real time event for lang detection")
    frappe.publish_realtime(
        event="language_detection_completed",
        message={"text":f"source language detected :  {src_language}"},
        user=user
    )    

public/js/event_notify.js:

frappe.ready(()=>{
    frappe.realtime.on("language_detection_completed", (data) => {
        frappe.show_alert({
            message: data.text,
            indicator: "green"
        })
    })
    
    frappe.realtime.on("hindi_dubbing_completed", (data) => {
        frappe.show_alert({
            message: data.text,
            indicator: "green"
        }, 5)
    })

})

@Lakakanon instead of sending and event and capturing it in js you can directly send a msgprint event from the server and remove all js code :

frappe.publish_realtime(event=‘msgprint’,message=“your message here”,user=“Administrator”)

it is not an alert but it will notify the user by a pop up msgprint .

1 Like

msgprint event works from server scripts, but if I want to do from custom api scripts then I can’t. I figured that using Notification doctype is the plausible approach until realtime events can be captured.