How can I get the episode info dict from the on_sample_end callback? - ray

I need to get the episode info dict from the on_sample_end callback so that I can display some custom metrics every time a rollout has finished. How can I do that?
Ray Version: 0.7.3
Thank you in advance!

Related

How to record all tasks information with Django and Celery?

In my Django project I'm using Celery with a RabbitMQ broker for asynchronous tasks, how can I record the information of all of my tasks (e.g. created time (task appears in queue), worker consume task time, execution time, status, ...) to monitor how Celery is doing?
I know there are solutions like Flower but that seems to much for what I need, django-celery-results looks like what I want but it's missing a few information I need like task created time.
Thanks!
It seems like you often find the answer yourself after asking on SO. I settled with using celery signals to do all the recording I want and store the results in a database table.

Django: Send reminder email

my app has list of events with start time (date and time). I want to make a scheduled task to send reminder via email to all user participate in event 1 hour before event start. (Note: Admin can change time of event).
I currently use celery to send email to list of participants when admin change the time of event.
Please suggest me some solution for this. Thanks.
Here's a recent(ish) discussion where a potential solution is proposed for celery: https://github.com/celery/celery/issues/4522.
I built Posthook to make solving these kinds of problems easier for developers. In your case, when a new event is created or the event time changes you can schedule a request back to your app for 1 hour before the start time. Then when you get the request from Posthook you can send out the reminder after validating that it still needs to be sent out.

How will I know if celery background process is successful inside django code. If it is successful I want render a html page

I am not able to do because I don't have the status of the currently running background process in the django code.
Request:
I need to know the status of the celery background task and render the html page from there
#task_success.connect
def task_sent_handler3(sender=None,result=None,**kwargs):
# information about task are located in headers for task messages
# using the task protocol version 2.
#info = headers if 'task' in headers else body
tester()
#print('after_task_publish for task id {info[id]}'.format(info="hhhi",))
I tried the above celery annotation but i did not return anything.
If it return also will i be able to access the local variables and return the render function
render(request,'page.html') from that success decoration function
How can I tackle this?
when you run the task for every task there will be unique id for that. from that id you can track the status of the task. on front side you can just check the status of sending the ajax call for that id. when it gets complete you can display the whatever you want to display.
http://thoslin.github.io/async-download-with-celery/

Celery inspect worker tasks and retrieve the task docstrings

I'm working with a celery worker node and developing a Django Rest API to handle celery task submission. I can get a list of tasks through inspect()
i = app.control.inspect()
i.registerd()
But need to get the docstring from worker node tasks. This will be used for the GET request to display useful helpful information to end user. The Celery task code is not install within the django rest api application. So how to inspect tasks on worker and return the docstring for task. Any help would be greatly appreciated.
The prototype of registered is
def registered(self, *taskinfoitems):
return self._request('dump_tasks', taskinfoitems=taskinfoitems)
You could specify __doc__ in the taskinfoitems parameter

Redirect to template after celery task complete

I use Celery with Django to put my pdf generation in background, while I display a loading page.
But when the task is complete (i.e. my pdf is generated), I want to redirect to the next view which is responsible to send mail and display a friendly confirmation message to the user.
I know i can get the task_postrun or task_success signal, but I can't redirect from there.
I searched for hours but didn't find any solution, any ideas ?
Thanks !
There are two ways:
Ask the server: save the task_id in the model where you are storing the PDF, and create an ajax view to check every X seconds if task is completed, the result of this view will determine if it should redirect or still wait for the PDF.
result = MyTask.AsyncResult(task_id)
result.get()
Real-time web: another way is using pusher with pusher_client_python, when PDF generation is completed (in your PDF creation rutine), make a api call to pusher who will send a notification to the connected client (that one waiting for the result) and will redirect, this approach is more convenient because you don't have to be asking the server every X seconds. You will need to learn about sockets paradigm, but its very easy to implement.
Hope this helps.