doable 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -2
- data/lib/doable/job.rb +2 -2
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 354051228fd6d5c41f7f79f8b75b171139549b2a
         | 
| 4 | 
            +
              data.tar.gz: 914dae4667be4a6ef4f06d6a4633a31b9943c19a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: de16e3550956ae75ec4f4d1a8a25870667ea89157fc1fb01300a62fcd121de6e7153d243358ecf9f8751da85ca29fa9175a008dd88b529a2d79309c45df3fe16
         | 
| 7 | 
            +
              data.tar.gz: 8c3d29bdcf1330c17fc07d139a1a434b7cf71497d11df9de8cf577479660fe6bac93dbe8ad925f91215e48c9f1663e8eecd3dbd1b8254a2774011032fa4c41c6
         | 
    
        data/README.md
    CHANGED
    
    | @@ -98,11 +98,13 @@ Here is an example job: | |
| 98 98 | 
             
                    check_disk_space @app_dir, (500 * 1024 * 1024)
         | 
| 99 99 | 
             
                  }
         | 
| 100 100 |  | 
| 101 | 
            +
                  # Create our user
         | 
| 101 102 | 
             
                  j.step    { 
         | 
| 102 103 | 
             
                    @user  = "cooluser"
         | 
| 103 104 | 
             
                    find_or_create_user @user, File.dirname(@app_dir)
         | 
| 104 105 | 
             
                  }
         | 
| 105 106 |  | 
| 107 | 
            +
                  # Unpack our software, and define a way to rollback this step
         | 
| 106 108 | 
             
                  j.step    {
         | 
| 107 109 | 
             
                    find_or_create_directory @app_dir
         | 
| 108 110 |  | 
| @@ -115,18 +117,38 @@ Here is an example job: | |
| 115 117 | 
             
                    remove(@app_dir)
         | 
| 116 118 | 
             
                  }
         | 
| 117 119 |  | 
| 120 | 
            +
                  # Rnn the software as our user
         | 
| 118 121 | 
             
                  j.step     {
         | 
| 119 122 | 
             
                    run_as_user @user, File.join(@app_dir, "/bin", "start.sh")
         | 
| 120 123 | 
             
                  }
         | 
| 121 124 | 
             
                end
         | 
| 122 125 |  | 
| 123 | 
            -
                job3.run
         | 
| 126 | 
            +
                job3.run # and... go!
         | 
| 124 127 |  | 
| 125 128 | 
             
            Hopefully this demonstrates how to get access to additional helper methods. Also, you may have noticed the `rollback` method added to the step for uncompressing the tarball. If things go wrong, rollbacks can be run to revert changes. To do so, just do this:
         | 
| 126 129 |  | 
| 127 130 | 
             
                job3.rollback!
         | 
| 128 131 |  | 
| 129 | 
            -
            The `Job` instance also has many other methods available for accessing its internals.
         | 
| 132 | 
            +
            The `Job` instance also has many other methods available for accessing its internals. For instance, it is possible to query a job to determine if it is running multiple threads:
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                job3.multitasking?
         | 
| 135 | 
            +
             | 
| 136 | 
            +
            Or queries its steps for their status and whether they were successful:
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                #!ruby
         | 
| 139 | 
            +
                job3.steps.collect {|s| puts "Status: #{s.status}; Success: #{s.successful?}" }
         | 
| 140 | 
            +
             | 
| 141 | 
            +
            If an individual step failed, it can be retried simply:
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                #!ruby
         | 
| 144 | 
            +
                job3.steps[2].retry
         | 
| 145 | 
            +
             | 
| 146 | 
            +
            It's also possible to trigger named hooks externally. Let's say we have a defined a hook called "cleanup":
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                #!ruby
         | 
| 149 | 
            +
                some_job_with_hooks.trigger(:cleanup)
         | 
| 150 | 
            +
             | 
| 151 | 
            +
            There are a lot of options for interacting with the internals of jobs, both within the definition of a job, and after.
         | 
| 130 152 |  | 
| 131 153 | 
             
            RubyDoc
         | 
| 132 154 | 
             
            -------
         | 
    
        data/lib/doable/job.rb
    CHANGED
    
    | @@ -73,7 +73,7 @@ module Doable | |
| 73 73 | 
             
                def attempt(options = {}, &block)
         | 
| 74 74 | 
             
                  @steps << Step.new(self, options) do
         | 
| 75 75 | 
             
                    begin
         | 
| 76 | 
            -
                      block | 
| 76 | 
            +
                      self.instance_exec(&block)
         | 
| 77 77 | 
             
                    rescue SkipStep => e
         | 
| 78 78 | 
             
                      raise e # We'll rescue this somewhere higher up the stack
         | 
| 79 79 | 
             
                    rescue => e
         | 
| @@ -89,7 +89,7 @@ module Doable | |
| 89 89 | 
             
                # @return [Step]
         | 
| 90 90 | 
             
                def background(options = {}, &block)
         | 
| 91 91 | 
             
                  @steps << Step.new(self, options) do
         | 
| 92 | 
            -
                    @threads << Thread.new { block | 
| 92 | 
            +
                    @threads << Thread.new { self.instance_exec(&block) }
         | 
| 93 93 | 
             
                  end
         | 
| 94 94 | 
             
                  @steps.last # return the last step (the one we just defined)
         | 
| 95 95 | 
             
                end # background()
         |