dj_progress_job 0.1.0
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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +174 -0
- data/Rakefile +1 -0
- data/app/controllers/dj_progress_job/progress_controller.rb +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/routes.rb +3 -0
- data/dj_progress_job.gemspec +24 -0
- data/lib/dj_progress_bar.rb +5 -0
- data/lib/dj_progress_job.rb +3 -0
- data/lib/dj_progress_job/base.rb +34 -0
- data/lib/dj_progress_job/engine.rb +3 -0
- data/lib/dj_progress_job/version.rb +3 -0
- data/lib/generators/dj_progress_job/USAGE +9 -0
- data/lib/generators/dj_progress_job/install_generator.rb +20 -0
- data/lib/generators/dj_progress_job/templates/migration.rb +10 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 069b1d899806fd431596f3db8fe30b70ba605d68
|
4
|
+
data.tar.gz: b2ac6fb875d58c6e173179184db52834d9976aff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f8aa14dfad472a6f2497521988ea10e67ab8352185ebb48c9f004f57fffb03c137a43140fa2d89cb857fbb57cf77811b4c076f82e855f97c592771d401b5fae
|
7
|
+
data.tar.gz: 556f320a83acfdd5f28004f2f2d5b4257ec8e5b1d29b138bc696958f6980a073764c0316e61eeafd62199f043d1ff7bb02f9d6b48f3c263482cf78c30d942c02
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Stjepan Hadjic
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
# ProgressJob
|
2
|
+
|
3
|
+
This gem add a couple of colums to delayed job table, and gives u a basic class for working with progress
|
4
|
+
|
5
|
+
|
6
|
+
## Requirements
|
7
|
+
|
8
|
+
Ruby 2.0.0 (as the methods are using keyword arguments.)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
You need to have https://github.com/collectiveidea/delayed_job in you gem file
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'dj_progress_job'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Run generator (run delayed job generators first!)
|
23
|
+
|
24
|
+
$ rails generate dj_progress_job:install
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Create a new class that extends ProgressJob::Base
|
29
|
+
|
30
|
+
class NewJob < DjProgressJob::Base
|
31
|
+
|
32
|
+
def perform
|
33
|
+
# some actions
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
Inside perform method you can use:
|
39
|
+
|
40
|
+
update_progress(step: 10) # default step is 1
|
41
|
+
update_stage('name of stage')
|
42
|
+
update_stage_progress('name of stage', step: 11)
|
43
|
+
update_progress_max(progress_max)
|
44
|
+
|
45
|
+
methods to update the job progress.
|
46
|
+
|
47
|
+
|
48
|
+
To create a new job use Delayed job enqueue method, and pass the progress_max value
|
49
|
+
|
50
|
+
job = Delayed::Job.enqueue NewJob.new(progress_max: 100) # default progress_max is 100
|
51
|
+
|
52
|
+
There is also a controller which returns the delayed job with calculated percentage
|
53
|
+
|
54
|
+
GET 'dj_progress-jobs/:job_id/'
|
55
|
+
|
56
|
+
|
57
|
+
### Progress job class
|
58
|
+
|
59
|
+
``` ruby
|
60
|
+
class NewJob < DjProgressJob::Base
|
61
|
+
|
62
|
+
def perform
|
63
|
+
handler = Handler.new
|
64
|
+
|
65
|
+
update_stage('Handling ports')
|
66
|
+
handler.handle_ports
|
67
|
+
|
68
|
+
update_stage_progress('Handling cruise', step: 10)
|
69
|
+
handler.handle_cruise
|
70
|
+
|
71
|
+
update_stage_progress('Handling days', step: 10)
|
72
|
+
handler.handle_days
|
73
|
+
|
74
|
+
update_stage_progress('Handling pick up times', step: 10)
|
75
|
+
handler.handle_pick_up_times
|
76
|
+
|
77
|
+
update_stage_progress('Handling users', step: 10)
|
78
|
+
handler.handle_users
|
79
|
+
|
80
|
+
update_stage_progress('Handling item categories', step: 10)
|
81
|
+
handler.handle_item_categories
|
82
|
+
|
83
|
+
update_stage_progress('Handling items', step: 10)
|
84
|
+
handler.handle_items
|
85
|
+
handler.handle_other_items
|
86
|
+
|
87
|
+
update_stage_progress('Handling event types', step: 10)
|
88
|
+
handler.handle_event_types
|
89
|
+
|
90
|
+
update_stage_progress('Handling events', step: 10)
|
91
|
+
handler.handle_events
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
### HAML
|
98
|
+
|
99
|
+
``` ruby
|
100
|
+
= simple_form_for :import, url: [:import], remote: true do |f|
|
101
|
+
.row
|
102
|
+
.col-xs-10
|
103
|
+
= f.input :file, as: :file
|
104
|
+
.col-xs-2
|
105
|
+
= f.button :submit, "Import", class: "btn btn-success"
|
106
|
+
|
107
|
+
%br
|
108
|
+
.well{style: "display:none"}
|
109
|
+
.row
|
110
|
+
.col-xs-12
|
111
|
+
.progress-status.text-primary
|
112
|
+
.row
|
113
|
+
.col-xs-12
|
114
|
+
.progress.progress-striped.active
|
115
|
+
.progress-bar
|
116
|
+
.text-primary
|
117
|
+
0%
|
118
|
+
```
|
119
|
+
|
120
|
+
### Ajax usage
|
121
|
+
|
122
|
+
Example of ajax call (this is a .html.haml remote: true response):
|
123
|
+
|
124
|
+
``` javascript
|
125
|
+
var interval;
|
126
|
+
$('.hermes-import .well').show();
|
127
|
+
interval = setInterval(function(){
|
128
|
+
$.ajax({
|
129
|
+
url: '/progress-job/' + #{@job.id},
|
130
|
+
success: function(job){
|
131
|
+
var stage, progress;
|
132
|
+
|
133
|
+
// If there are errors
|
134
|
+
if (job.last_error != null) {
|
135
|
+
$('.progress-status').addClass('text-danger').text(job.progress_stage);
|
136
|
+
$('.progress-bar').addClass('progress-bar-danger');
|
137
|
+
$('.progress').removeClass('active');
|
138
|
+
clearInterval(interval);
|
139
|
+
}
|
140
|
+
|
141
|
+
// Upload stage
|
142
|
+
if (job.progress_stage != null){
|
143
|
+
stage = job.progress_stage;
|
144
|
+
progress = job.progress_current / job.progress_max * 100;
|
145
|
+
} else {
|
146
|
+
progress = 0;
|
147
|
+
stage = 'Uploading file';
|
148
|
+
}
|
149
|
+
|
150
|
+
// In job stage
|
151
|
+
if (progress !== 0){
|
152
|
+
$('.progress-bar').css('width', progress + '%').text(progress + '%');
|
153
|
+
}
|
154
|
+
|
155
|
+
$('.progress-status').text(stage);
|
156
|
+
},
|
157
|
+
error: function(){
|
158
|
+
// Job is no loger in database which means it finished successfuly
|
159
|
+
$('.progress').removeClass('active');
|
160
|
+
$('.progress-bar').css('width', '100%').text('100%');
|
161
|
+
$('.progress-status').text('Successfully imported!');
|
162
|
+
clearInterval(interval);
|
163
|
+
}
|
164
|
+
})
|
165
|
+
},100);
|
166
|
+
```
|
167
|
+
|
168
|
+
## Contributing
|
169
|
+
|
170
|
+
1. Fork it ( http://github.com/<my-github-username>/progress_job/fork )
|
171
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
172
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
173
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
174
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module DjProgressJob
|
2
|
+
class ProgressController < ActionController::Base
|
3
|
+
|
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
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dj_progress_job"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dj_progress_job/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dj_progress_job"
|
8
|
+
spec.version = DjProgressJob::VERSION
|
9
|
+
spec.authors = ["vk"]
|
10
|
+
spec.email = ["gvenki911@gmail.com"]
|
11
|
+
spec.summary = %q{Delayed jobs with progress.}
|
12
|
+
spec.description = %q{Add progress feature to delayed jobs}
|
13
|
+
spec.homepage = "https://github.com/venki911/dj_progress_job.git"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency 'delayed_job'
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module DjProgressJob
|
2
|
+
class Base
|
3
|
+
def initialize(progress_max = 100)
|
4
|
+
@progress_max = progress_max
|
5
|
+
end
|
6
|
+
|
7
|
+
def before(job)
|
8
|
+
@job = job
|
9
|
+
job.update_column(:progress_max, @progress_max)
|
10
|
+
job.update_column(:progress_current, 0)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update_progress(step = 1)
|
14
|
+
@job.update_column(:progress_current, @job.progress_current + step)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_stage(stage)
|
18
|
+
@job.update_column(:progress_stage, stage)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_stage_progress(stage, step = 1)
|
22
|
+
update_stage(stage)
|
23
|
+
update_progress(step = step)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_progress_max(progress_max)
|
27
|
+
@job.update_column(:progress_max, progress_max)
|
28
|
+
end
|
29
|
+
|
30
|
+
def error(job, exception)
|
31
|
+
job.update_column(:progress_stage, exception.message)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Description:
|
2
|
+
Generates migration for acts_as_simple_translatable.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate acts_as_simple_translatable en category name description
|
6
|
+
|
7
|
+
This will create a migration to translate the name and description fields in the categories table.
|
8
|
+
It will insert the existing category and description values in the record_translations table using the 'en' (English) locale.
|
9
|
+
Note: You cannot roll back this migration.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module DjProgressJob
|
4
|
+
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def install
|
12
|
+
migration_template "migration.rb", "db/migrate/add_progress_to_delayed_jobs.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.next_migration_number(path)
|
16
|
+
@migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class AddProgressToDelayedJobs < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
change_table :delayed_jobs do |t|
|
4
|
+
t.string :progress_stage, required: true
|
5
|
+
t.integer :progress_current, required: true, default: 0
|
6
|
+
t.integer :progress_max, required: true, default: 0
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dj_progress_job
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- vk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: delayed_job
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Add progress feature to delayed jobs
|
56
|
+
email:
|
57
|
+
- gvenki911@gmail.com
|
58
|
+
executables:
|
59
|
+
- console
|
60
|
+
- setup
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- app/controllers/dj_progress_job/progress_controller.rb
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- config/routes.rb
|
72
|
+
- dj_progress_job.gemspec
|
73
|
+
- lib/dj_progress_bar.rb
|
74
|
+
- lib/dj_progress_job.rb
|
75
|
+
- lib/dj_progress_job/base.rb
|
76
|
+
- lib/dj_progress_job/engine.rb
|
77
|
+
- lib/dj_progress_job/version.rb
|
78
|
+
- lib/generators/dj_progress_job/USAGE
|
79
|
+
- lib/generators/dj_progress_job/install_generator.rb
|
80
|
+
- lib/generators/dj_progress_job/templates/migration.rb
|
81
|
+
homepage: https://github.com/venki911/dj_progress_job.git
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Delayed jobs with progress.
|
105
|
+
test_files: []
|