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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2075478f5997a10b069908397644e72d9e0f068
4
- data.tar.gz: e1769c55e457629231b824c4536c442b15c1660a
3
+ metadata.gz: 2cc32459446aa8a5db2648427b7491dd70a84a1e
4
+ data.tar.gz: edfb357081f7a956b8b7b35977024ae2c07d4a14
5
5
  SHA512:
6
- metadata.gz: beac40fe9872df8871d394a866083cb820736d0ed89ac69e70a276a37463519708f5961db0c7b469ec6ce8956ece435d2580468ebd5cf16878d1b7c0538ca5c9
7
- data.tar.gz: 36270aee384016cc3555f94ec2868108ed6c009f1af4e0873dab7b8029f41dc531068d37fe80e0ee5c416c17cd2e4b269e621c0ed9198fd2ab7849f22428be24
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 )
@@ -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
- @job.update_column(:progress_max, @progress_max)
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
@@ -1,3 +1,3 @@
1
1
  module ProgressJob
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-09-22 00:00:00.000000000 Z
11
+ date: 2014-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler