Open darfink opened 9 years ago
Looking at the code for Task, you should be able to do this, or something similar:
def install_app(name):
if application_exists(name):
return
install(name)
class MyTask(Task):
def __call__(self, ctx, *args, **kw):
return self.body(self.name)
ns = Collection()
ns.add_task(MyTask(install_app, name = "alfred"))
ns.add_atask(MyTask(install_app, name="asepsis"))
Although this in my mind brings up a couple thoughts for @bitprophet -
@task
decorators to point at custom subclasses of Task
? (this may be done or covered by another ticket already....)Context
object point to the specific Task
instance being used - so we could do something like ctx.task.name
in the above - this gets a bit hairy with all the other stuff being discussed, but it might be useful/needed. Hi!
@task
but I don't see one, nor is the code currently set up to do it already.
@task
, which works well for one-offs, and folks wanting to do a more blanket reassignment could reasonably do import task as _task; task = partial(_task, klass=MyTaskClass)
or whatnot.name
and eg pre
/post
into the Context
. However, this makes sense for other reasons (it jives well with including per-invocation data which wouldn't be present on the Task
itself, such as a copy of the CLI arg parse result).Think you can close this thanks to klass. Very handy feature!
Is it possible to get the name of the currently running task, if the task is context aware? I can give an example of by describing my current situation.
I want to have one task for each of my application installations, but the logic of these tasks are all identical. That means a lot of boilerplate code.
What I would prefer would be to do something like this:
Is this possible, or is there any workaround?