Skip to main content

UI for darq async task manager - https://github.com/seedofjoy/darq

Darq UI

Installation

PyPI package

pip install darq-ui

Or with extra dependencies:

pip install darq-ui[aiohttp]
# or
pip install darq-ui[fastapi]

Integration

Use setup function like this from darq_ui.integration.<framework> import setup to integrate darq-ui with your application.

For example, to integrate with FastAPI:

from fastapi import FastAPI
from darq.app import Darq
from darq_ui.integration.fastapi import setup

app = FastAPI()
darq = Darq()

setup(app, darq)

Web UI

Once you have your server running, you can access the web UI at http://host:port/darq.

You can pass the base_path parameter to the setup function in order to change the base path of the UI.

setup(app, darq, base_path="/my-path")

You can disable the web UI by passing web_ui=False to the setup function (it can be usefull if you want to embed darq_ui and use it only that way).

Embedding

If you already have a UI (admin UI for example) and you can embed darq-ui into it using <iframe />.

setup(app, darq, base_path="/admin/darq", embed=True)

embed=True will enable special endpoint /admin/darq/embed (if you set base_path="/admin/darq").

Then you can use it in an iframe:

export const Tasks = () => {
  const url = "http://localhost:3000/admin/darq/embed";
  return <iframe title='Darq UI' style={{ border: '0px' }} src={url} height='100%' width='100%' />;
}

If you have a logging system (kibana for example), you can pass logs_url to setup function. One requirement is that the url should have the ${taskName} placeholder which will be replaced with the task name.

setup(app, darq, logs_url="https://mylogserver.com/taskname=${taskName}")

Kibana url example

If you have kibana, you can use the following url:

https://kibana.corp/app/discover#/?_g=(time:(from:now-15m,to:now))&_a=(filters:!((('$state':(store:appState),meta:(key:task_name,params:(query:'%22${taskName}%22')),query:(match_phrase:(task_name:’${taskName}')))))

In this url, task_name is a field name and ${taskName} will be replaced with the task name value. (This is just an example. You may need to adjust it according to your kibana configuration.)

Securing the UI

Since darq-ui is a part of your application, and can run any task, you should consider protecting it with authorization middleware or firewall.

Dropping tasks

Darq UI allows you to drop running tasks. You can only drop a task that is written to work in batches and calls itself at the end.

For now we can not drop currently running task, only the next one.

BATCH_SIZE = 10

@darq.task
async def notify_users(last_id: int = 0) -> None:
    users = await session.scalars(select(User).where(User.id > last_id).limit(BATCH_SIZE))
    for user in users:
        notify_user(user)

    if len(users) == BATCH_SIZE:
      await notify_users(users[-1].id)
    else:
      log.info("All users notified")

In this example, after you drop the task, on the next run worker won't run it again by raising an exception.

In order to enable task dropping, you need to call special function from darq_ui lib in on_job_prerun darq callback.

from darq.app import Darq
from darq_ui.darq import maybe_drop_task

darq = Darq(... on_job_prerun=on_job_prerun)

async def on_job_prerun(
    ctx: dict[str, Any],
    arq_function: Any,
    args: Sequence[Any],
    kwargs: Mapping[str, Any],
) -> None:
    # your code here
    await maybe_drop_task(darq, arq_function.name)

In the example above, maybe_drop_task will check if the task is in the drop list and if so, it will raise DarqTaskDroppedError exception.

When you are ready, remove task from droplist in the UI and run task again.

Examples

In order to run examples you need to install the dependencies:

cd examples
pdm install

And then run the server from the repo root:

lets run-fastapi 
# or 
lets run-aiohttp

Development

Run client build

In root directory run:

build-ui will build production version of assets and copy them to src/darq_ui/static directory.

lets build-ui

build-ui-dev will build and watch development version of assets and copy them to src/darq_ui/static directory.

lets build-ui-dev

Now you can run the server and it will serve the UI from the src/darq_ui/static directory.

lets run-fastapi

Run linters, formatters and other checks

pdm run ruff
pdm run ruff-fmt
pdm run mypy

Changelog

When developing, add notes to CHANGELOG.md to Unreleased section.

After we decided to release new version, we must rename Unreleased to new tag version and add new Unreleased section.

Publishing

darq-ui supports semver versioning.

  • Update the version number in the src/darq_ui/__init__.py file.
  • Update the changelog in the CHANGELOG.md file.
  • Merge changes into master.
  • Create a tag git tag -a v0.0.X -m 'your tag message'.
  • Push the tag git push origin --tags.

All of the above steps can be done with the following command:

lets release <version> -m 'your release message'

When new tag pushed, new release action on GitHub will publish new package to pypi.

Metadata

Release files for darq-ui 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for darq-ui 0.0.5
File Size Uploaded Provenance
darq_ui-0.0.5.tar.gz 328.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for darq-ui 0.0.5
File Interpreter ABI Platform
darq_ui-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 656.8 kB

Release files / darq_ui-0.0.5.tar.gz

Download URL darq_ui-0.0.5.tar.gz
Size 328.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7e76f4a05a1b94e53eec685b7d15a1a3fe5edb2cfcb6c1ca2a7a1e02ce73c43a
BLAKE2b-256 checksum
How to use checksums
9a61f43c5b072e7eb104aec9ca1ee075f4937f0205adc306849229c010a1421a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.19.1 CPython/3.10.18 Linux/6.11.0-1015-azure

Release files / darq_ui-0.0.5-py3-none-any.whl

Download URL darq_ui-0.0.5-py3-none-any.whl
Size 328.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b89eb490d1e01d514bebb39d01983850b9f3ba6dd88878f901920e1dbfa5d09a
BLAKE2b-256 checksum
How to use checksums
8e9cc72a6949f1ae50bfeb0a00c9329ed65e14782263720e3639339d848d5c0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.19.1 CPython/3.10.18 Linux/6.11.0-1015-azure

Security for darq-ui 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page