Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Losing context after using run_task #6

Open
jistr opened this issue Jan 19, 2012 · 5 comments
Open

Losing context after using run_task #6

jistr opened this issue Jan 19, 2012 · 5 comments

Comments

@jistr
Copy link
Contributor

jistr commented Jan 19, 2012

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.

@DAddYE
Copy link
Owner

DAddYE commented Jan 19, 2012

Mmm, nice catch, could you try with sudo gem do --pre ?

@jistr
Copy link
Contributor Author

jistr commented Jan 20, 2012

Yes, I wrote in the first post that this happens even with version 0.2.0.h (the latest prerelease), if this is what you mean. The stack trace shown above was produced using 0.2.0.h.

DAddYE added a commit that referenced this issue Jan 20, 2012
@DAddYE
Copy link
Owner

DAddYE commented Jan 20, 2012

Pushed the new version which should solve the problem. Thanks for submitting this!

DAddYE:lipsiastore DAddYE$ on srv2 tmp:foo
root@srv2 ~ # pwd
/root
going on bar task
root@srv2 ~ # cat /etc/redhat-release
CentOS release 5.7 (Final)
welcome back
root@srv2 ~ # pwd
/root
DAddYE:lipsiastore DAddYE$ 

@jistr
Copy link
Contributor Author

jistr commented Jan 20, 2012

Now on my real use case it seems to pass twice in the loop that is calling the inner task and then it throws the exception attached.

It seems not to be a problem of that particular one loop iteration (even when I mix up the data for the loop, it always crashes in the third iteration).

Let me know if you want to see more stuff (task definitions etc.).

do-0.2.0.i/lib/do/tasks.rb:55:in `method_defined?': #<DO::Server:0x00000002961980 ... a lot of stuff here ...> is not a symbol (TypeError)
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.i/lib/do/tasks.rb:55:in `task_run'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.i/lib/do/commands.rb:96:in `block (3 levels) in load_recipe'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.i/lib/do/commands.rb:80:in `each'
from /home/jistr/projects/archive/narubi/narubi_servers_tasks/vendor/ruby/1.9.1/gems/do-0.2.0.i/lib/do/commands.rb:80: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.i/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.i/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.i/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.i/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.i/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.i/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.i/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.i/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>'

@jistr
Copy link
Contributor Author

jistr commented Jan 21, 2012

Simple failing "test case":

namespace :test do
  task :test, on: :remote do
    2.times do
      run 'pwd'
      run_task :'test:inner'
    end
  end

  task :inner, on: :remote do
    run 'pwd'
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants