progress_job 0.0.1 → 0.0.2

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: 9fa00d536a7cc9174017b2da5cd5ed5ccd13448d
4
- data.tar.gz: e3e0c22864ce39cd6a90a16209d485b1c0c232d0
3
+ metadata.gz: f2075478f5997a10b069908397644e72d9e0f068
4
+ data.tar.gz: e1769c55e457629231b824c4536c442b15c1660a
5
5
  SHA512:
6
- metadata.gz: dc69a0c2796e2842f8704e646cbd8f86924d635407a79ca5ec68740e85b604d09b79ad61e487245a8e95f0611b20bb674528eac895b422765798627cad4392f8
7
- data.tar.gz: b7577822a770ee098240046b00b02a04648b47485cfbbab07821abbd2bfb3d6d4826acb78c748aeada9c8b1e3386494667fd70b644176d7a3019b96361575479
6
+ metadata.gz: beac40fe9872df8871d394a866083cb820736d0ed89ac69e70a276a37463519708f5961db0c7b469ec6ce8956ece435d2580468ebd5cf16878d1b7c0538ca5c9
7
+ data.tar.gz: 36270aee384016cc3555f94ec2868108ed6c009f1af4e0873dab7b8029f41dc531068d37fe80e0ee5c416c17cd2e4b269e621c0ed9198fd2ab7849f22428be24
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # ProgressJob
2
2
 
3
- TODO: Write a gem description
3
+ This gem add a couple of colums to delayed job table, and gives u a basic class for working with progress
4
4
 
5
5
  ## Installation
6
6
 
7
+ You need to have https://github.com/collectiveidea/delayed_job in you gem file
8
+
7
9
  Add this line to your application's Gemfile:
8
10
 
9
11
  gem 'progress_job'
@@ -12,13 +14,34 @@ And then execute:
12
14
 
13
15
  $ bundle
14
16
 
15
- Or install it yourself as:
17
+ Run generator (run delayed job generators first!)
16
18
 
17
- $ gem install progress_job
19
+ $ rake progress_job:install
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ Create a new class that extends ProgressJob::Base
24
+
25
+ class NewJob < ProgressJob::Base
26
+
27
+ def perform
28
+ 10.times do |i|
29
+ sleep(1.seconds)
30
+ update_progress(step: 10)
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ Inside perform method you can use 'update_progress(step)' method to update the job progress.
37
+
38
+ To create a new job use Delayed job enqueue method, and pass the progress_max value
39
+
40
+ job = Delayed::Job.enqueue NewJob.new(100)
41
+
42
+ There is also a controller which returns the delayed job with calculated percentage
43
+
44
+ GET 'progress-jobs/:job_id/'
22
45
 
23
46
  ## Contributing
24
47
 
@@ -1,13 +1,10 @@
1
1
  module ProgressJob
2
2
  class ProgressController < ActionController::Base
3
3
 
4
- respond_to :json
5
-
6
- def progress
7
- @current_job = Delayed::Job.find(params[:job_id])
8
- percentage = current_job.current_progress / current_job.max_progress.to_f * 100
9
- @current_job[:percentage] = percentage
10
- render json: @current_job
4
+ def show
5
+ @delayed_job = Delayed::Job.find(params[:job_id])
6
+ percentage = !@delayed_job.progress_max.zero? ? @delayed_job.progress_current / @delayed_job.progress_max.to_f * 100 : 0
7
+ render json: @delayed_job.attributes.merge!(percentage: percentage).to_json
11
8
  end
12
9
 
13
10
  end
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
- get 'progress-job/progress' => 'progress_job/progress#progress'
2
+ get 'progress-job/:job_id' => 'progress_job/progress#show'
3
3
  end
@@ -2,8 +2,8 @@ class AddProgressToDelayedJobs < ActiveRecord::Migration
2
2
  def change
3
3
  change_table :delayed_jobs do |t|
4
4
  t.string :progress_stage, required: true
5
- t.string :progress_current, required: true, default: 0
6
- t.string :progress_max, required: true, default: 0
5
+ t.integer :progress_current, required: true, default: 0
6
+ t.integer :progress_max, required: true, default: 0
7
7
  end
8
8
 
9
9
  end
@@ -1,17 +1,17 @@
1
1
  module ProgressJob
2
2
  class Base
3
- def initialize(max_progress)
4
- @max_progress = max_progress
3
+ def initialize(progress_max)
4
+ @progress_max = progress_max
5
5
  super()
6
6
  end
7
7
 
8
8
  def before(job)
9
9
  @job = job
10
- @job.update_column(:max_progress, @max_progress)
10
+ @job.update_column(:progress_max, @progress_max)
11
11
  end
12
12
 
13
13
  def update_progress(step: 1)
14
- @job.update_column(:current_progress, @job.current_progress + step)
14
+ @job.update_column(:progress_current, @job.progress_current + step)
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module ProgressJob
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progress_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stjepan Hadjic