Skip to content

Losing context after using run_task #6

@jistr

Description

@jistr

Hi Davide,

I attempted to run a task using run_task method inside another task. Both tasks use the download method to get data from remote server. After returning from the inner task back to the outer task, download method is undefined in the outer task. Running pwd commands shows that the outer task is performed locally from that point on, not on the remote server. Tested on versions 0.1.4 and 0.2.0.h, same results for both. Here's a simple testing code to show the problem:

namespace :test do
  task :outer, on: :remote do
    run 'pwd'
    puts 'downloading test1'
    download '/tmp/test1', 'test1'
    puts 'downloaded test1'

    run_task :'test:inner'

    run 'pwd'
    puts 'downloading test3'
    download '/tmp/test3', 'test3'
    puts 'downloaded test3'
  end

  task :inner, on: :remote do
    run 'pwd'
    puts 'downloading test2'
    download '/tmp/test2', 'test2'
    puts 'downloaded test2'
  end
end

After running test:outer, this is the output:

downloading test1
root@arya ~ # pwd
/root
root@arya ~ # sending: /tmp/test1 (100%)
downloaded test1
downloading test2
root@arya ~ # pwd
/root
root@arya ~ # sending: /tmp/test2 (100%)
downloaded test2
downloading test3
do@local ~ # pwd
/home/jistr/projects/archive/narubi/narubi_servers_tasks
/home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/lib/do/commands.rb:155:in `method_missing': undefined method `download' for DO::Commands:Module (NoMethodError)

from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/lib/do/commands.rb:86:in `block (2 levels) in load_recipe'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/lib/do/commands.rb:112:in `call'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/lib/do/commands.rb:112:in `block in server'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/lib/do/tasks.rb:61:in `call'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/lib/do/tasks.rb:61:in `block in task_run'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/lib/do/tasks.rb:56:in `each'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/lib/do/tasks.rb:56:in `task_run'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/lib/do/cli.rb:7:in `start'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.h/bin/doit:6:in `<top (required)>'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/bin/doit:19:in `load'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/bin/doit:19:in `<main>'

I cannot use simple task dependency in this case, in my real scenario I need to run the inner task in a loop, each time with different options, that's why I use run_task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions