Comments (4)
So some possible places to look for implementing this:
@jobtastic_task
via shared_task
celery.app.shared_task shows a way to register a task that will be available to all celery app instances. This gives us a way to avoid doing something nasty like monkeypatching the Celery object to add a celery.jobtastic_task
or some such.
Steal relevant stuff from _task_from_fun
celery.app.base:Celery._task_from_fun has all of the magic needed to create your task object from a function.
from jobtastic.
Back of the envelope possible solution:
def _jobtastic_task_from_fun(app, fun, **options):
if 'base' in options:
raise Exception("'base' can't be used on a JobtasticTask")
T = type(fun.__name__, (JobtasticTask, ), dict({
'app': app,
'accept_magic_kwargs': False,
'calculate_result': staticmethod(fun),
'__doc__': fun.__doc__,
'__module__': fun.__module__}, **options))()
task = app._tasks[T.name] # return global instance.
task.bind(self)
return task
def jobtastic_task(*args, **kwargs):
def create_jobtastic_task(**options):
def __inner(fun):
name = options.get('name')
_shared_task(lambda app: _jobtastic_task_from_fun(app, fun, **options))
for app in _get_active_apps():
if app.finalized:
with app._finalize_mutex:
_jobtastic_task_from_fun(app, fun, **options)
def task_by_cons():
app = current_app()
return app.tasks[
name or gen_task_name(app, fun.__name__, fun.__module__)
]
return Proxy(task_by_cons)
return __inner
if len(args) == 1 and isinstance(args[0], Callable):
return create_jobtastic_task(**kwargs)(args[0])
return create_jobtastic_task(*args, **kwargs)
from jobtastic.
Hi, I'm investigating how to do the same thing. Could you please give a full example of using this kind of pattern.
Thanks!
from jobtastic.
Hi Viacheslav,
Unfortunately, that back of the envelope example is the closest I've come. If I had a full example, it would already be merged in :P If you give this a try and you run in to specific problems, I'd be happy to help with some debugging, but I haven't yet been able to prioritize building this out completely. Decorators would be awesome, though.
-Wes
from jobtastic.
Related Issues (20)
- Add option to skip herd avoidance check, but still trigger avoidance for other tasks HOT 19
- compatibility with Celery 4.0? HOT 3
- Project configuration HOT 4
- celery.conf deprecated HOT 2
- License mismatch HOT 1
- Python core dump or memcached/redis I/O error can cause other-process `apply_async` to loop for `thundering_herd_timeout` HOT 4
- Add option to retry a task later if the task is already running HOT 1
- Add ability to ensure only 1 version of a task is running at a time, but still actually run subsequent jobs: Simultaneous Execution Prevention HOT 3
- Add support for Celery >= 4.0 HOT 11
- How do you handle POST -> REDIRECT -> GET sequence to pass task_id? HOT 2
- groups or subtask HOT 1
- old requirements of psutil clashes
- Herd Avoidance and Task Retry HOT 1
- Jobtastic tasks waits even CELERY_TASK_ALWAYS_EAGER is True
- Magic value (-1) for cache TTL is not compatible with cachelib RedisCache.
- Expose method to extend lock timeout HOT 1
- jquery-celery is dead ...
- Caching task even though cache_duration = -1 HOT 7
- cache locking allows bypassing herd avoidance
- Support for celery 5.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jobtastic.