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.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +226 -2
  3. data/app_test/job_test.rb +1 -1
  4. data/app_test/run.rb +1 -1
  5. data/bin/workerholic +1 -1
  6. data/demo_app/.gitignore +19 -0
  7. data/demo_app/Gemfile +40 -0
  8. data/demo_app/README.md +24 -0
  9. data/demo_app/Rakefile +6 -0
  10. data/demo_app/app/assets/config/manifest.js +3 -0
  11. data/demo_app/app/assets/images/.keep +0 -0
  12. data/demo_app/app/assets/javascripts/application.js +14 -0
  13. data/demo_app/app/assets/javascripts/cable.js +13 -0
  14. data/demo_app/app/assets/javascripts/channels/.keep +0 -0
  15. data/demo_app/app/assets/stylesheets/application.css +15 -0
  16. data/demo_app/app/assets/stylesheets/main.scss +140 -0
  17. data/demo_app/app/channels/application_cable/channel.rb +4 -0
  18. data/demo_app/app/channels/application_cable/connection.rb +4 -0
  19. data/demo_app/app/controllers/application_controller.rb +3 -0
  20. data/demo_app/app/controllers/concerns/.keep +0 -0
  21. data/demo_app/app/controllers/jobs_controller.rb +38 -0
  22. data/demo_app/app/helpers/application_helper.rb +2 -0
  23. data/demo_app/app/jobs/application_job.rb +2 -0
  24. data/demo_app/app/jobs/cpu_bound_job.rb +14 -0
  25. data/demo_app/app/jobs/io_bound_job.rb +8 -0
  26. data/demo_app/app/jobs/non_blocking_job.rb +8 -0
  27. data/demo_app/app/mailers/application_mailer.rb +4 -0
  28. data/demo_app/app/models/application_record.rb +3 -0
  29. data/demo_app/app/models/concerns/.keep +0 -0
  30. data/demo_app/app/views/jobs/_actions_form.html.slim +15 -0
  31. data/demo_app/app/views/jobs/_footer.html.slim +5 -0
  32. data/demo_app/app/views/jobs/_header.html.slim +3 -0
  33. data/demo_app/app/views/jobs/index.html.slim +8 -0
  34. data/demo_app/app/views/layouts/application.html.slim +15 -0
  35. data/demo_app/app/views/layouts/mailer.html.erb +13 -0
  36. data/demo_app/app/views/layouts/mailer.text.erb +1 -0
  37. data/demo_app/bin/bundle +3 -0
  38. data/demo_app/bin/rails +9 -0
  39. data/demo_app/bin/rake +9 -0
  40. data/demo_app/bin/setup +38 -0
  41. data/demo_app/bin/spring +17 -0
  42. data/demo_app/bin/update +29 -0
  43. data/demo_app/bin/yarn +11 -0
  44. data/demo_app/config.ru +5 -0
  45. data/demo_app/config/application.rb +19 -0
  46. data/demo_app/config/boot.rb +3 -0
  47. data/demo_app/config/cable.yml +10 -0
  48. data/demo_app/config/database.yml +85 -0
  49. data/demo_app/config/environment.rb +5 -0
  50. data/demo_app/config/environments/development.rb +54 -0
  51. data/demo_app/config/environments/production.rb +91 -0
  52. data/demo_app/config/environments/test.rb +42 -0
  53. data/demo_app/config/initializers/application_controller_renderer.rb +6 -0
  54. data/demo_app/config/initializers/assets.rb +14 -0
  55. data/demo_app/config/initializers/backtrace_silencers.rb +7 -0
  56. data/demo_app/config/initializers/cookies_serializer.rb +5 -0
  57. data/demo_app/config/initializers/filter_parameter_logging.rb +4 -0
  58. data/demo_app/config/initializers/inflections.rb +16 -0
  59. data/demo_app/config/initializers/mime_types.rb +4 -0
  60. data/demo_app/config/initializers/wrap_parameters.rb +14 -0
  61. data/demo_app/config/locales/en.yml +33 -0
  62. data/demo_app/config/puma.rb +56 -0
  63. data/demo_app/config/routes.rb +6 -0
  64. data/demo_app/config/secrets.yml +32 -0
  65. data/demo_app/config/spring.rb +6 -0
  66. data/demo_app/db/schema.rb +18 -0
  67. data/demo_app/db/seeds.rb +7 -0
  68. data/demo_app/lib/assets/.keep +0 -0
  69. data/demo_app/lib/tasks/.keep +0 -0
  70. data/demo_app/log/.keep +0 -0
  71. data/demo_app/package.json +5 -0
  72. data/demo_app/public/404.html +67 -0
  73. data/demo_app/public/422.html +67 -0
  74. data/demo_app/public/500.html +66 -0
  75. data/demo_app/public/apple-touch-icon-precomposed.png +0 -0
  76. data/demo_app/public/apple-touch-icon.png +0 -0
  77. data/demo_app/public/favicon.ico +0 -0
  78. data/demo_app/public/robots.txt +1 -0
  79. data/demo_app/tmp/.keep +0 -0
  80. data/demo_app/vendor/.keep +0 -0
  81. data/lib/workerholic.rb +1 -1
  82. data/lib/workerholic/cli.rb +1 -1
  83. data/lib/workerholic/job_processor.rb +2 -2
  84. data/lib/workerholic/job_serializer.rb +9 -9
  85. data/lib/workerholic/queue.rb +1 -1
  86. data/lib/workerholic/version.rb +1 -1
  87. data/lib/workerholic/web/application.rb +1 -1
  88. data/logos.png +0 -0
  89. data/spec/job_serializer_spec.rb +15 -5
  90. data/spec/spec_helper.rb +1 -1
  91. data/spec/statistics_storage_spec.rb +0 -2
  92. metadata +78 -2
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
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
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,14 @@
1
+ class CpuBoundJob
2
+ include Workerholic::Job
3
+ job_options queue_name: 'cpu_bound'
4
+
5
+ def perform(arg)
6
+ a, b = 0, 1
7
+
8
+ while b < arg
9
+ a, b = b, a + b
10
+ end
11
+
12
+ puts b
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ class IoBoundJob
2
+ include Workerholic::Job
3
+ job_options queue_name: 'io_bound'
4
+
5
+ def perform
6
+ puts HTTP.get('https://jsonplaceholder.typicode.com/posts/1').parse
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class NonBlockingJob
2
+ include Workerholic::Job
3
+ job_options queue_name: 'non_blocking'
4
+
5
+ def perform(arg)
6
+ arg
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ 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,5 @@
1
+ div id='app-footer'
2
+ p
3
+ | Powered by
4
+ a< href='https://github.com/workerholic/workerholic'
5
+ | Workerholic
@@ -0,0 +1,3 @@
1
+ div id='app-header'
2
+ h1 Demo App
3
+
@@ -0,0 +1,8 @@
1
+ - if flash[:success] || flash[:error]
2
+ div.message
3
+ - if flash[:success]
4
+ p.success = flash[:success]
5
+ - else
6
+ p.error = flash[:error]
7
+
8
+ = render 'actions_form'
@@ -0,0 +1,15 @@
1
+ doctype html
2
+ html
3
+ head
4
+ title DemoApp
5
+ = csrf_meta_tags
6
+ = stylesheet_link_tag 'application'
7
+ = javascript_include_tag 'application'
8
+
9
+ body
10
+ header
11
+ = render 'header'
12
+ main
13
+ = yield
14
+ footer
15
+ = render 'footer'
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -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
@@ -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
+ require_relative '../config/boot'
8
+ require 'rake'
9
+ Rake.application.run
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -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,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: async
6
+
7
+ production:
8
+ adapter: redis
9
+ url: redis://localhost:6379/1
10
+ channel_prefix: demo_app_production
@@ -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'] %>