Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user facing task queues #25138

Draft
wants to merge 17 commits into
base: develop
Choose a base branch
from

Conversation

akhilnarang
Copy link
Member

WIP

Resolves #23008

Copy link

stale bot commented May 11, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed within 3 days if no further activity occurs, but it only takes a comment to keep a contribution alive :) Also, even if it is closed, you can always reopen the PR when you're ready. Thank you for contributing.

@stale stale bot added the inactive label May 11, 2024
@akhilnarang akhilnarang force-pushed the user-facing-task-queues branch 3 times, most recently from 5b1a251 to dc0a2b2 Compare May 21, 2024 06:29
Basically a combination of callable.__module__ + . + callable.__qualname__

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Make use of `rq.Job`'s `meta` field instead of relying on
`kwargs` -> `Job._kwargs` - doesn't seem to be reliable when a job is
killed

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Cleanup some code
Set status to started when starting

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Ensure that the status is set even if an exception occurs

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Display a dialog, allow users to customize the values before retrying

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
if task_id:
frappe.db.set_value(
"Background Task",
{"task_id": task_id.split("::")[-1]},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets avoid site name here. Should be possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also move this up so before_job doesn't get commited.

:param message: Message for the user
:return: Nothing
"""
from frappe.core.doctype.background_task.background_task import publish_task_progress
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to make this an API (and other functions in the same file) it should probably be moved / re-exported somewhere else.

],
"fields": [
{
"fieldname": "task_id",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just use name for this?

frappe.msgprint(_("Job is not running."), title=_("Invalid Operation"))


@frappe.whitelist(methods=["POST"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@frappe.whitelist(methods=["POST"])

"read_only": 1
},
{
"fieldname": "stopped_callback",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets remove all the callbacks. No one uses it afaik. Also it's elegant to handle this stuff in job itself.

@ankush
Copy link
Member

ankush commented May 28, 2024

Dev facing APIs that this should have:

Queuing the task:

  1. Enqueue task and get task ID to track
  2. Automatically subscribe realtime on client

While running the task:

  1. Publish progress (numerical progress with description)
  2. Publish status (?)
  3. Set artefacts or success URL / "Actions"

@ankush
Copy link
Member

ankush commented May 28, 2024

We should auto-subscribe all ongoing tasks so updates are sent even if user reloads the page.

E.g. prepared report completion should be notified ALWAYS.

Another case to consider:

  • User enqueued
  • job started, user left
  • job completed
  • user came back
  • We should notify about the completed job now

This should behave like notification

Copy link

stale bot commented Jun 13, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed within 3 days if no further activity occurs, but it only takes a comment to keep a contribution alive :) Also, even if it is closed, you can always reopen the PR when you're ready. Thank you for contributing.

@stale stale bot added the inactive label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User facing task queues
2 participants