progress_job 0.0.2 → 0.0.3
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 +27 -0
- data/lib/progress_job/base.rb +16 -2
- data/lib/progress_job/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2cc32459446aa8a5db2648427b7491dd70a84a1e
         | 
| 4 | 
            +
              data.tar.gz: edfb357081f7a956b8b7b35977024ae2c07d4a14
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c7c85d6a4c09a49671a0f7e418690b5eb734ced0556cc9b02a41d20c4c029dd1445c20764e1075003ec2b2c54346d2d65496fc5eecceffa0c8ed511f494596a2
         | 
| 7 | 
            +
              data.tar.gz: d4d02f82ca6d8251db750102edceafe1c3ab7f3e80b8fbd8433fc922a4105d4c4737195d8447dff553cc0f101aec77cfd6775f1b0fb4ac5b7d58dfee0a6c19ce
         | 
    
        data/README.md
    CHANGED
    
    | @@ -43,6 +43,33 @@ There is also a controller which returns the delayed job with calculated percent | |
| 43 43 |  | 
| 44 44 | 
             
                GET 'progress-jobs/:job_id/'
         | 
| 45 45 |  | 
| 46 | 
            +
            ## Ajax usage
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            Example of ajax calls:
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                $('.button').click(function(){
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  var interval;
         | 
| 53 | 
            +
                  $.ajax({
         | 
| 54 | 
            +
                    url: '/start',
         | 
| 55 | 
            +
                    success: function(job){
         | 
| 56 | 
            +
                      interval = setInterval(function(){
         | 
| 57 | 
            +
                        $.ajax({
         | 
| 58 | 
            +
                          url: '/progress-jobs/' + job.id,
         | 
| 59 | 
            +
                          success: function(job){
         | 
| 60 | 
            +
                            $('.progress-bar').css('width', job.progress + '%').text(job.progress + '%')
         | 
| 61 | 
            +
                          },
         | 
| 62 | 
            +
                          error: function(){
         | 
| 63 | 
            +
                            $('.progress-bar').css('width', '100%').text('100%')
         | 
| 64 | 
            +
                            clearInterval(interval);
         | 
| 65 | 
            +
                          }
         | 
| 66 | 
            +
                        })
         | 
| 67 | 
            +
                      },1000)
         | 
| 68 | 
            +
                    }
         | 
| 69 | 
            +
                  });
         | 
| 70 | 
            +
                });
         | 
| 71 | 
            +
             | 
| 72 | 
            +
             | 
| 46 73 | 
             
            ## Contributing
         | 
| 47 74 |  | 
| 48 75 | 
             
            1. Fork it ( http://github.com/<my-github-username>/progress_job/fork )
         | 
    
        data/lib/progress_job/base.rb
    CHANGED
    
    | @@ -1,17 +1,31 @@ | |
| 1 1 | 
             
            module ProgressJob
         | 
| 2 2 | 
             
              class Base
         | 
| 3 | 
            +
             | 
| 3 4 | 
             
                def initialize(progress_max)
         | 
| 4 5 | 
             
                  @progress_max = progress_max
         | 
| 5 | 
            -
                  super()
         | 
| 6 6 | 
             
                end
         | 
| 7 7 |  | 
| 8 8 | 
             
                def before(job)
         | 
| 9 9 | 
             
                  @job = job
         | 
| 10 | 
            -
                   | 
| 10 | 
            +
                  job.update_column(:progress_max, @progress_max)
         | 
| 11 | 
            +
                  job.update_column(:progress_current, 0)
         | 
| 11 12 | 
             
                end
         | 
| 12 13 |  | 
| 13 14 | 
             
                def update_progress(step: 1)
         | 
| 14 15 | 
             
                  @job.update_column(:progress_current, @job.progress_current + step)
         | 
| 15 16 | 
             
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def update_stage(stage)
         | 
| 19 | 
            +
                  @job.update_column(:progress_stage, stage)
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def update_stage_progress(stage, step: 1)
         | 
| 23 | 
            +
                  update_stage(stage)
         | 
| 24 | 
            +
                  update_progress(step: step)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def error(job, exception)
         | 
| 28 | 
            +
                  job.update_column(:progress_stage, exception.message)
         | 
| 29 | 
            +
                end
         | 
| 16 30 | 
             
              end
         | 
| 17 31 | 
             
            end
         | 
    
        data/lib/progress_job/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: progress_job
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Stjepan Hadjic
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-10-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         |