Name: oncondition
Owner: Futurice
Description: null
Created: 2016-03-02 14:57:35.0
Updated: 2016-03-03 07:46:24.0
Pushed: 2016-08-04 15:02:27.0
Homepage: null
Size: 16
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Run actions based on conditions.
To provide transparency into 'What happens When?' and 'Is This working?' when bundling arbitrary logic into your application. For example creating email notifications based on the form filledness criterias is a good use-case.
RY_MODULE = "foo.app"
ODEL = "oncondition.Event"
AITMODEL = "oncondition.EventWaiting"
An Event, that fires when any User has changes:
oncondition.events import Event
s MyEvent(Event):
def condition(self, instance, changes):
return 5>4
def action(self, instance, context):
self.mail(subject='[EVENT] Breakthrough!', body="--", to=self.recipients())
self.log("My Event fired! Recipients: [%s]"%self.recipients())
Register the Event:
oncondition.events import event_model
t_model().objects.get_or_create(name="my-event", cls="project.MyEvent", model="auth.User", recipients="me@company.com,you@company.com")
On Condition supports any number of CONDITION_NAME -methods to run for a single Event, with their respective (optional) 'CONDITION_NAME_failure' -methods.
Out of the box `time_condition
has a respective ``
time_condition_failure```, that creates an EventWaiting -instance. This
allows to poll changes to an Event out of a request/response cycle. When the time_condition is met, it is marked as done.
CELERYBEAT_SCHEDULE = {
'waiting-events': {
'task': 'oncondition.tasks.handle_timed_events',
'schedule': timedelta(minutes=60),
}
}
To test against Celery, provide your own CELERY_CONFIG_MODULE (see app_test_runner.py), eg:
nage.py
if 'test' in sys.argv:
os.environ["CELERY_CONFIG_MODULE"] = "foo.tests.celeryconfig"
o.tests.celeryconfig
foo.celeryconfig import *
RY_ALWAYS_EAGER = True
RY_EAGER_PROPAGATES_EXCEPTIONS = True
Extend oncondition.models.Event and point `ET_MODEL
, ``
ET_WAITMODEL``` to these.