Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Dramatiq is a background task-processing library for Python with a focus on simplicity, reliability and performance.
This package, async-dramatiq, extends Dramatiq to provide the following:
To provide async support for your actors all you need to do is add the AsyncMiddleware
to your broker.
import dramatiq
from dramatiq.brokers.rabbitmq import RabbitmqBroker
rabbitmq_broker = RabbitmqBroker(host="rabbitmq")
rabbitmq_broker.add_middleware(AsyncMiddleware()) # <--- Here
dramatiq.set_broker(rabbitmq_broker)
import dramatiq
from dramatiq.brokers.redis import RedisBroker
redis_broker = RedisBroker(host="redis")
redis_broker.add_middleware(AsyncMiddleware()) # <--- Here
dramatiq.set_broker(redis_broker)
We leverage apscheduler as our scheduling system. Check out run_scheduler.py for an example of running this scheduler.
For more details check out the official guide to dramatiq or docker-compose.yaml for a specific example.
Play around with worker-heartbeat-example. A functioning and featured example implementation.
AsyncMiddleware
will start a AsyncWorker
which will be used to run the event loop. This event loop will be shared across the Worker threads.
To startup and shutdown any resources the AsyncMiddleware
provides two hooks:
from async_dramatiq.middleware import AsyncMiddleware
async def startup() -> None:
"""This function should contain your resource initialization code."""
pass
async def shutdown() -> None:
"""This function should contain your resource teardown code."""
pass
class MyAsyncMiddleware(AsyncMiddleware):
def before_async_worker_thread_startup(
self, _: RabbitmqBroker, thread: AsyncWorker, **kwargs: dict[str, Any]
) -> None:
thread.event_loop.run_until_complete(startup())
def after_async_worker_thread_shutdown(
self, _: RabbitmqBroker, thread: AsyncWorker, **kwargs: dict[str, Any]
) -> None:
thread.event_loop.run_until_complete(shutdown())
thread.event_loop.close()
The async actor, async_actor
, acts as a thin wrapper around the Dramatiq actor providing a variety of new functionality.
Run a job at some interval
@async_actor(interval=timedelta(seconds=5))
def run_every_5_seconds() -> None:
pass
Run a job on a crontab ( See https://crontab.guru/. )
@async_actor(interval="0 0 * * *")
def run_at_midnight() -> None:
pass
FAQs
Dramatiq with Asyncio support and some other goodies
We found that async-dramatiq demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.