A library for creating background threads that can talk to the ZODB and use local site components.
We’re probably reinventing Celery.
Example
Let’s assume we have a DMS with a simple publication workflow. We have two states “DRAFT” and “PUBLISH”. The Problem in this example is: that the transition form “DRAFT” to “PUBLISH” takes some minutes, and we don’t want the user to be waiting.
First we have create a WorkflowTransition-BackgroundThread:
class MyWorkflowTransition(BackgroundWorkerThread):
execute = True
description = "background worker thread (%(class_name)s) for %(site_name)s User %(user_name)s"
def __init__(self, site_db, site_oid, site_name, user_name, daemon=True, object_oid=None):
self.object_oid = object_oid
super(MyWorker, self).__init__(site_db, site_oid, site_name, user_name, daemon=True)
def scheduleNextWork(self):
return self.execute
def getObjectFromOID(self):
conn = getSite()._p_jar
return conn.get(self.object_oid)
def doWork(self):
sleep(15) # This is our long TASK
self.execute = False
document = self.getObjectFromOID()
document.wf_status = "PUBLISHED"
We have a simple Document with an initial Workflow-State draft.
class Document(Persistent):
wf_state = "DRAFT"
Now we have to call our WorkflowTransition.
def setWorkflow(site, document_oid, user_name):
worker = MyWorkflowTransition(
site_db = site._p_jar.db(),
site_oid = site._p_oid,
site_name = site.__name__,
user_name = user_name,
object_oid = document_oid,
)
worker.start()
When calling worker.start() the thread goes into “Background” and the user don’t have to wait until the Transition is finished.
CHANGES
1.0.2 (2012-07-31)
Refactor BackgroundWorkerThread to have the site returned from getSite()
1.0.1 (2012-04-05)
1.0.0 (2012-02-10)
Initial release as a separate package.
Metadata
Release files for cipher.background 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cipher.background-1.0.2.tar.gz | 14.6 kB | Without provenance | Details for cipher.background-1.0.2.tar.gz |
Release files / cipher.background-1.0.2.tar.gz
| Download URL | cipher.background-1.0.2.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
067f1bc9377689be5304bf69643555a31aa9c3b4d82dfe964cd3aee0ce468184
|
|
BLAKE2b-256 checksum How to use checksums |
a0c452e17b517981e66a62b249cffcd820055c0660b9477bb3cfb5b4af598e8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for cipher.background 1.0.2
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.