rq / django-rq

A simple app that provides django integration for RQ (Redis Queue)
MIT License
1.82k stars 286 forks source link

Allow linebreaks and/or HTML in Job result #337

Open pbysh opened 5 years ago

pbysh commented 5 years ago

Just got done setting everything up with django-rq and I have to say I am a huge fan of the project so far. My favorite thing, by far, is the integration with the Django admin panel that gives me a very nice interface to be able to look through my queues, jobs, and results.

I don't know if this is a misuse of the "result" of a Job, but I am using it to give me a relatively brief "log" of the events that transpired within the job. I know there are some services for this sort of thingbut I don't need anything too involved. Ultimately I end up returning a string of events separated by newlines. Unfortunately while the stacktrace of exceptions has the linebreaks template tag applied to it, the results do not:

    <div class="form-row">
        <div>
            <label class="required">Exception:</label>
            <div class="data"><pre>{% if job.exc_info %}{{ job.exc_info|linebreaks }}{% endif %}</pre></div>
        </div>
    </div>

    <div class="form-row">
        <div>
            <label class="required">Result:</label>
            <div class="data">{{ job.result }}</div>
        </div>
    </div>

So, all that is to say, I think it would be pretty harmless to add |linebreaks to {{ job.result }} if at all possible. I have already done this but have had to copy job_result.html which is not ideal.

Thanks.

selwin commented 5 years ago

linebreaks is added to job.exc_info because exc_info is a string. I'm not sure how linebreaks behave if you feed it data type that's not string (for example if the job is not finished, it returns None).

Depending on the function being executed, the return types could also be other Python data structures.

pbysh commented 5 years ago

linebreaks casts whatever is passed to it to a string, which is what is happening anyways because it's being printed, so I don't see how it would hurt?

selwin commented 5 years ago

You're right. Please open a PR for this :)

taewookim commented 4 years ago

Ditto @selwin

selwin commented 4 years ago

Ming opening a PR for this?