workerholic 0.0.21 → 0.0.22
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 +226 -2
- data/app_test/job_test.rb +1 -1
- data/app_test/run.rb +1 -1
- data/bin/workerholic +1 -1
- data/demo_app/.gitignore +19 -0
- data/demo_app/Gemfile +40 -0
- data/demo_app/README.md +24 -0
- data/demo_app/Rakefile +6 -0
- data/demo_app/app/assets/config/manifest.js +3 -0
- data/demo_app/app/assets/images/.keep +0 -0
- data/demo_app/app/assets/javascripts/application.js +14 -0
- data/demo_app/app/assets/javascripts/cable.js +13 -0
- data/demo_app/app/assets/javascripts/channels/.keep +0 -0
- data/demo_app/app/assets/stylesheets/application.css +15 -0
- data/demo_app/app/assets/stylesheets/main.scss +140 -0
- data/demo_app/app/channels/application_cable/channel.rb +4 -0
- data/demo_app/app/channels/application_cable/connection.rb +4 -0
- data/demo_app/app/controllers/application_controller.rb +3 -0
- data/demo_app/app/controllers/concerns/.keep +0 -0
- data/demo_app/app/controllers/jobs_controller.rb +38 -0
- data/demo_app/app/helpers/application_helper.rb +2 -0
- data/demo_app/app/jobs/application_job.rb +2 -0
- data/demo_app/app/jobs/cpu_bound_job.rb +14 -0
- data/demo_app/app/jobs/io_bound_job.rb +8 -0
- data/demo_app/app/jobs/non_blocking_job.rb +8 -0
- data/demo_app/app/mailers/application_mailer.rb +4 -0
- data/demo_app/app/models/application_record.rb +3 -0
- data/demo_app/app/models/concerns/.keep +0 -0
- data/demo_app/app/views/jobs/_actions_form.html.slim +15 -0
- data/demo_app/app/views/jobs/_footer.html.slim +5 -0
- data/demo_app/app/views/jobs/_header.html.slim +3 -0
- data/demo_app/app/views/jobs/index.html.slim +8 -0
- data/demo_app/app/views/layouts/application.html.slim +15 -0
- data/demo_app/app/views/layouts/mailer.html.erb +13 -0
- data/demo_app/app/views/layouts/mailer.text.erb +1 -0
- data/demo_app/bin/bundle +3 -0
- data/demo_app/bin/rails +9 -0
- data/demo_app/bin/rake +9 -0
- data/demo_app/bin/setup +38 -0
- data/demo_app/bin/spring +17 -0
- data/demo_app/bin/update +29 -0
- data/demo_app/bin/yarn +11 -0
- data/demo_app/config.ru +5 -0
- data/demo_app/config/application.rb +19 -0
- data/demo_app/config/boot.rb +3 -0
- data/demo_app/config/cable.yml +10 -0
- data/demo_app/config/database.yml +85 -0
- data/demo_app/config/environment.rb +5 -0
- data/demo_app/config/environments/development.rb +54 -0
- data/demo_app/config/environments/production.rb +91 -0
- data/demo_app/config/environments/test.rb +42 -0
- data/demo_app/config/initializers/application_controller_renderer.rb +6 -0
- data/demo_app/config/initializers/assets.rb +14 -0
- data/demo_app/config/initializers/backtrace_silencers.rb +7 -0
- data/demo_app/config/initializers/cookies_serializer.rb +5 -0
- data/demo_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/demo_app/config/initializers/inflections.rb +16 -0
- data/demo_app/config/initializers/mime_types.rb +4 -0
- data/demo_app/config/initializers/wrap_parameters.rb +14 -0
- data/demo_app/config/locales/en.yml +33 -0
- data/demo_app/config/puma.rb +56 -0
- data/demo_app/config/routes.rb +6 -0
- data/demo_app/config/secrets.yml +32 -0
- data/demo_app/config/spring.rb +6 -0
- data/demo_app/db/schema.rb +18 -0
- data/demo_app/db/seeds.rb +7 -0
- data/demo_app/lib/assets/.keep +0 -0
- data/demo_app/lib/tasks/.keep +0 -0
- data/demo_app/log/.keep +0 -0
- data/demo_app/package.json +5 -0
- data/demo_app/public/404.html +67 -0
- data/demo_app/public/422.html +67 -0
- data/demo_app/public/500.html +66 -0
- data/demo_app/public/apple-touch-icon-precomposed.png +0 -0
- data/demo_app/public/apple-touch-icon.png +0 -0
- data/demo_app/public/favicon.ico +0 -0
- data/demo_app/public/robots.txt +1 -0
- data/demo_app/tmp/.keep +0 -0
- data/demo_app/vendor/.keep +0 -0
- data/lib/workerholic.rb +1 -1
- data/lib/workerholic/cli.rb +1 -1
- data/lib/workerholic/job_processor.rb +2 -2
- data/lib/workerholic/job_serializer.rb +9 -9
- data/lib/workerholic/queue.rb +1 -1
- data/lib/workerholic/version.rb +1 -1
- data/lib/workerholic/web/application.rb +1 -1
- data/logos.png +0 -0
- data/spec/job_serializer_spec.rb +15 -5
- data/spec/spec_helper.rb +1 -1
- data/spec/statistics_storage_spec.rb +0 -2
- metadata +78 -2
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class JobsController < ApplicationController
|
2
|
+
def create
|
3
|
+
if parse_jobs.all?(&:zero?)
|
4
|
+
flash[:error] = 'Please add at least 1 job.'
|
5
|
+
redirect_to root_path and return
|
6
|
+
end
|
7
|
+
|
8
|
+
non_blocking, cpu, io = parse_jobs
|
9
|
+
|
10
|
+
non_blocking.times do |n|
|
11
|
+
NonBlockingJob.new.perform_async(n)
|
12
|
+
end
|
13
|
+
|
14
|
+
cpu.times do
|
15
|
+
CpuBoundJob.new.perform_async(1000)
|
16
|
+
end
|
17
|
+
|
18
|
+
io.times do |n|
|
19
|
+
IoBoundJob.new.perform_async
|
20
|
+
end
|
21
|
+
|
22
|
+
counter = parse_jobs.reduce(:+)
|
23
|
+
|
24
|
+
flash[:success] = "Successfully added #{counter} jobs."
|
25
|
+
redirect_to root_path
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def job_params
|
31
|
+
params.require(:jobs).permit(:non_blocking, :cpu_bound, :io_bound)
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_jobs
|
35
|
+
jobs = params[:jobs]
|
36
|
+
[jobs[:non_blocking].to_i, jobs[:cpu_bound].to_i, jobs[:io_bound].to_i]
|
37
|
+
end
|
38
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
= form_tag('/add', method: 'post', class: 'work-form') do
|
2
|
+
fieldset.jobs-params
|
3
|
+
= label_tag 'jobs[non_blocking', 'Non-blocking jobs:'
|
4
|
+
= number_field_tag 'jobs[non_blocking', nil, in: 1..10_000, step: 1
|
5
|
+
br
|
6
|
+
= label_tag 'jobs[cpu_bound]', 'CPU-bound jobs:'
|
7
|
+
= number_field_tag 'jobs[cpu_bound]', nil, in: 1..10_000, step: 1
|
8
|
+
br
|
9
|
+
= label_tag 'jobs[io_bound]', 'IO-bound jobs:'
|
10
|
+
= number_field_tag 'jobs[io_bound]', nil, in: 1..100, step: 1
|
11
|
+
br
|
12
|
+
|
13
|
+
fieldset.actions
|
14
|
+
= submit_tag 'Add jobs'
|
15
|
+
= button_tag 'Reset', type: :reset
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
data/demo_app/bin/bundle
ADDED
data/demo_app/bin/rails
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
begin
|
3
|
+
load File.expand_path('../spring', __FILE__)
|
4
|
+
rescue LoadError => e
|
5
|
+
raise unless e.message.include?('spring')
|
6
|
+
end
|
7
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
8
|
+
require_relative '../config/boot'
|
9
|
+
require 'rails/commands'
|
data/demo_app/bin/rake
ADDED
data/demo_app/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a starting point to setup your application.
|
15
|
+
# Add necessary setup steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
# Install JavaScript dependencies if using Yarn
|
22
|
+
# system('bin/yarn')
|
23
|
+
|
24
|
+
|
25
|
+
# puts "\n== Copying sample files =="
|
26
|
+
# unless File.exist?('config/database.yml')
|
27
|
+
# cp 'config/database.yml.sample', 'config/database.yml'
|
28
|
+
# end
|
29
|
+
|
30
|
+
puts "\n== Preparing database =="
|
31
|
+
system! 'bin/rails db:setup'
|
32
|
+
|
33
|
+
puts "\n== Removing old logs and tempfiles =="
|
34
|
+
system! 'bin/rails log:clear tmp:clear'
|
35
|
+
|
36
|
+
puts "\n== Restarting application server =="
|
37
|
+
system! 'bin/rails restart'
|
38
|
+
end
|
data/demo_app/bin/spring
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This file loads spring without using Bundler, in order to be fast.
|
4
|
+
# It gets overwritten when you run the `spring binstub` command.
|
5
|
+
|
6
|
+
unless defined?(Spring)
|
7
|
+
require 'rubygems'
|
8
|
+
require 'bundler'
|
9
|
+
|
10
|
+
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
|
11
|
+
spring = lockfile.specs.detect { |spec| spec.name == "spring" }
|
12
|
+
if spring
|
13
|
+
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
|
14
|
+
gem 'spring', spring.version
|
15
|
+
require 'spring/binstub'
|
16
|
+
end
|
17
|
+
end
|
data/demo_app/bin/update
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a way to update your development environment automatically.
|
15
|
+
# Add necessary update steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
puts "\n== Updating database =="
|
22
|
+
system! 'bin/rails db:migrate'
|
23
|
+
|
24
|
+
puts "\n== Removing old logs and tempfiles =="
|
25
|
+
system! 'bin/rails log:clear tmp:clear'
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system! 'bin/rails restart'
|
29
|
+
end
|
data/demo_app/bin/yarn
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
VENDOR_PATH = File.expand_path('..', __dir__)
|
3
|
+
Dir.chdir(VENDOR_PATH) do
|
4
|
+
begin
|
5
|
+
exec "yarnpkg #{ARGV.join(" ")}"
|
6
|
+
rescue Errno::ENOENT
|
7
|
+
$stderr.puts "Yarn executable was not detected in the system."
|
8
|
+
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
end
|
data/demo_app/config.ru
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'boot'
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(*Rails.groups)
|
8
|
+
|
9
|
+
module DemoApp
|
10
|
+
class Application < Rails::Application
|
11
|
+
# Initialize configuration defaults for originally generated Rails version.
|
12
|
+
config.load_defaults 5.1
|
13
|
+
|
14
|
+
# Settings in config/environments/* take precedence over those specified here.
|
15
|
+
# Application configuration should go into files in config/initializers
|
16
|
+
# -- all .rb files in that directory are automatically loaded.
|
17
|
+
config.active_job.queue_adapter = :workerholic
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# PostgreSQL. Versions 9.1 and up are supported.
|
2
|
+
#
|
3
|
+
# Install the pg driver:
|
4
|
+
# gem install pg
|
5
|
+
# On OS X with Homebrew:
|
6
|
+
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
|
7
|
+
# On OS X with MacPorts:
|
8
|
+
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
|
9
|
+
# On Windows:
|
10
|
+
# gem install pg
|
11
|
+
# Choose the win32 build.
|
12
|
+
# Install PostgreSQL and put its /bin directory on your path.
|
13
|
+
#
|
14
|
+
# Configure Using Gemfile
|
15
|
+
# gem 'pg'
|
16
|
+
#
|
17
|
+
default: &default
|
18
|
+
adapter: postgresql
|
19
|
+
encoding: unicode
|
20
|
+
# For details on connection pooling, see Rails configuration guide
|
21
|
+
# http://guides.rubyonrails.org/configuring.html#database-pooling
|
22
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
23
|
+
|
24
|
+
development:
|
25
|
+
<<: *default
|
26
|
+
database: demo_app_development
|
27
|
+
|
28
|
+
# The specified database role being used to connect to postgres.
|
29
|
+
# To create additional roles in postgres see `$ createuser --help`.
|
30
|
+
# When left blank, postgres will use the default role. This is
|
31
|
+
# the same name as the operating system user that initialized the database.
|
32
|
+
#username: demo_app
|
33
|
+
|
34
|
+
# The password associated with the postgres role (username).
|
35
|
+
#password:
|
36
|
+
|
37
|
+
# Connect on a TCP socket. Omitted by default since the client uses a
|
38
|
+
# domain socket that doesn't need configuration. Windows does not have
|
39
|
+
# domain sockets, so uncomment these lines.
|
40
|
+
#host: localhost
|
41
|
+
|
42
|
+
# The TCP port the server listens on. Defaults to 5432.
|
43
|
+
# If your server runs on a different port number, change accordingly.
|
44
|
+
#port: 5432
|
45
|
+
|
46
|
+
# Schema search path. The server defaults to $user,public
|
47
|
+
#schema_search_path: myapp,sharedapp,public
|
48
|
+
|
49
|
+
# Minimum log levels, in increasing order:
|
50
|
+
# debug5, debug4, debug3, debug2, debug1,
|
51
|
+
# log, notice, warning, error, fatal, and panic
|
52
|
+
# Defaults to warning.
|
53
|
+
#min_messages: notice
|
54
|
+
|
55
|
+
# Warning: The database defined as "test" will be erased and
|
56
|
+
# re-generated from your development database when you run "rake".
|
57
|
+
# Do not set this db to the same as development or production.
|
58
|
+
test:
|
59
|
+
<<: *default
|
60
|
+
database: demo_app_test
|
61
|
+
|
62
|
+
# As with config/secrets.yml, you never want to store sensitive information,
|
63
|
+
# like your database password, in your source code. If your source code is
|
64
|
+
# ever seen by anyone, they now have access to your database.
|
65
|
+
#
|
66
|
+
# Instead, provide the password as a unix environment variable when you boot
|
67
|
+
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
|
68
|
+
# for a full rundown on how to provide these environment variables in a
|
69
|
+
# production deployment.
|
70
|
+
#
|
71
|
+
# On Heroku and other platform providers, you may have a full connection URL
|
72
|
+
# available as an environment variable. For example:
|
73
|
+
#
|
74
|
+
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
|
75
|
+
#
|
76
|
+
# You can use this database configuration with:
|
77
|
+
#
|
78
|
+
# production:
|
79
|
+
# url: <%= ENV['DATABASE_URL'] %>
|
80
|
+
#
|
81
|
+
production:
|
82
|
+
<<: *default
|
83
|
+
database: demo_app_production
|
84
|
+
username: demo_app
|
85
|
+
password: <%= ENV['DEMO_APP_DATABASE_PASSWORD'] %>
|