so we are refactoring a big app into an extendable set of apps, a la pinax project
the issue now is how to customize and override behavior and fields on models
what's your experience using django on this issue?
mattmcc
There isn't a clean way to replace fields on arbitrary models.
But you can add your own models that link to other app's models.
kezabelle
abstract models containing the non-replaceable ones, concrete models for replaceable ones, possibly using swappable models if necessary, or onetoones if appropriate
escanda
mattmcc, yep, but in that case I couldn't customize behavior at the model level; let's say I want a custom manager in an entity for a project. I'd need to swap the default one
mattmcc
kezabelle: But the app(s) in question have to be written to support that.
kezabelle
mattmcc: sure sure
escanda
interesting approach kezabelle, what do you mean by swappable?
mattmcc
Honestly if you need to extensively modify models in third party apps, fork them.
A lock would normally block queueing additional reindexes, rather than delay/serialize them.
plfiorini joined the channel
AtomicSpark
Sentry link is 404.
nazarewk
mattmcc: i am aware that somewhere else there can be a change that requires reindexing, i just want to prevent scheduling bazillion tasks for the same thing for example in a for loop
tulioz joined the channel
jarshwah
yes, that is correct.. but you can readd yourself to the queue if the lock is locked
nazarewk
in a single transaction
mattmcc
AtomicSpark: Huh. Didn't know the docs linked there. That's a docu bug, then.
jarshwah
ahh but that won't prevent adding a new one to the scheduler
escanda
nazarewk that sounds like bad design, but if you are up to it, I'd wrap the thing into a transaction. you create a context for it, once the context is consumed, you schedule the task
jarshwah
there's also the on_commit signal, no?
goldfish_ joined the channel
nazarewk
yeah, but on_commit is not preventing duplicates
it would be ideal if it did
jarshwah
no, it'd only prevent multiple per request
mattmcc
nazarewk: If it were me, what I'd do is write my Celery task such that whenever it gets called, it looks for the latest reindex time. If that time is 'too long ago', run. Else, bail.
jarshwah
and check again when it's actually scheduled that it's not already running :D
mattmcc
Right.
nazarewk
mattmcc: i already incorporated non-blocking lock into the task
i am not sure if celery provides efficient way to check whether task is already in queue
have a separate queue which only allows one task/worker at a time :o)
tulioz has quit
jarshwah
and be super careful not to schedule time sensitive tasks there hehe
mattmcc
nazarewk: Celery doesn't have a singleton enforcer, no.
mreznik has quit
kezabelle
jarshwah: indeed :)
mattmcc
Eh, that wasn't really your question.
eperzhand joined the channel
But still, I would use my own mechanism to determine if a task should be queued again vs 'is already in the queue' because that would seem to depend on business rules.
nazarewk
basically i have 3 models that should fire reindex on save
they could all get saved in a single transaction
escanda
instead of Redis, if you are using just one machine a file lock should be enough
kezabelle
can always just use a sentinel lock, whether that be a file or a redis key or whatever
but you'd have to lock eagerly in-band, and then have the celery task remove the lock on successful completion
nazarewk
well, going this way in-memory lock should be enough
jarshwah: skimmed over it, gonna read more in-depth
kezabelle
in memory where? you can't remove the lock from the worker unless it's shared via memcached or redis or whatever
if you lock inside a Django process, and need to unlock inside a worker on successful complete, it needs to be accessible to both via a shared mechanism, which LocMem would not be (for example)
Debnet joined the channel
AtomicSpark
If one uses sentry for a small host, should I go with the free account or self host? The documentation kind of warns against the latter in an almost sales man way.
nazarewk
i don't really care about multipler workers scheduling tasks, i just don't want a single worker to schedule tasks multiple times in a single context
phinxy joined the channel
hutch34 joined the channel
sol1x joined the channel
eperzhand has quit
Muchoz joined the channel
escanda
then be able to attach the context to the request, be it a threadlocal or whatever, and make a transaction out of it
escanda runs away, threadlocals are evil xd
nazarewk
are they? :)
escanda
the most common sense solution, imho, is mattmcc, mixed with kezabelle suggestion of a shared lock
mattmcc
"Don't use threadlocals, like we do everywhere" -Django
AtomicSpark
Most errors should be caught at dev level anyways. The only actual errors I've gotten so far were from Python version mismatch or Apache permission issues. Both of which just means the site is down.
kezabelle
mattmcc: not *everywhere* ... sometimes there's just a global ;)