carrierwave_backgrounder 0.4.3 → 1.0.0.beta

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +4 -4
  4. data/CHANGELOG.md +14 -0
  5. data/Gemfile +1 -1
  6. data/README.md +59 -67
  7. data/carrierwave_backgrounder.gemspec +7 -2
  8. data/lib/backgrounder/orm/activemodel.rb +7 -7
  9. data/lib/backgrounder/orm/base.rb +18 -12
  10. data/lib/backgrounder/support/backends.rb +1 -45
  11. data/lib/backgrounder/version.rb +1 -1
  12. data/lib/backgrounder/workers/active_job/process_asset.rb +14 -0
  13. data/lib/backgrounder/workers/active_job/store_asset.rb +14 -0
  14. data/lib/backgrounder/workers/process_asset_mixin.rb +16 -7
  15. data/lib/backgrounder/workers/store_asset_mixin.rb +14 -19
  16. data/lib/carrierwave_backgrounder.rb +11 -10
  17. data/lib/generators/carrierwave_backgrounder/install_generator.rb +1 -1
  18. data/lib/generators/carrierwave_backgrounder/templates/config/initializers/carrierwave_backgrounder.rb +1 -7
  19. data/spec/backgrounder/orm/activemodel_spec.rb +2 -5
  20. data/spec/backgrounder/support/backends_spec.rb +0 -159
  21. data/spec/backgrounder/workers/process_asset_spec.rb +8 -6
  22. data/spec/backgrounder/workers/store_asset_spec.rb +20 -99
  23. data/spec/integrations/process_in_background_multi_upload_spec.rb +81 -0
  24. data/spec/integrations/process_in_background_spec.rb +75 -0
  25. data/spec/integrations/store_in_background_multi_upload_spec.rb +87 -0
  26. data/spec/integrations/store_in_background_spec.rb +86 -0
  27. data/spec/rails_helper.rb +27 -0
  28. data/spec/spec_helper.rb +2 -0
  29. data/spec/support/dummy_app/Gemfile +49 -0
  30. data/spec/support/dummy_app/README.md +24 -0
  31. data/spec/support/dummy_app/Rakefile +6 -0
  32. data/spec/support/dummy_app/app/controllers/application_controller.rb +2 -0
  33. data/spec/support/dummy_app/app/controllers/concerns/.keep +0 -0
  34. data/spec/support/dummy_app/app/jobs/application_job.rb +7 -0
  35. data/spec/support/dummy_app/app/models/admin.rb +10 -0
  36. data/spec/support/dummy_app/app/models/application_record.rb +3 -0
  37. data/spec/support/dummy_app/app/models/concerns/.keep +0 -0
  38. data/spec/support/dummy_app/app/models/user.rb +10 -0
  39. data/spec/support/dummy_app/app/uploaders/avatar_uploader.rb +67 -0
  40. data/spec/support/dummy_app/bin/bundle +114 -0
  41. data/spec/support/dummy_app/bin/rails +4 -0
  42. data/spec/support/dummy_app/bin/rake +4 -0
  43. data/spec/support/dummy_app/bin/setup +33 -0
  44. data/spec/support/dummy_app/config/application.rb +39 -0
  45. data/spec/support/dummy_app/config/boot.rb +3 -0
  46. data/spec/support/dummy_app/config/database.yml +25 -0
  47. data/spec/support/dummy_app/config/environment.rb +8 -0
  48. data/spec/support/dummy_app/config/environments/development.rb +65 -0
  49. data/spec/support/dummy_app/config/environments/production.rb +86 -0
  50. data/spec/support/dummy_app/config/environments/test.rb +61 -0
  51. data/spec/support/dummy_app/config/initializers/carrierwave_backgrounder.rb +4 -0
  52. data/spec/support/dummy_app/config/initializers/cors.rb +16 -0
  53. data/spec/support/dummy_app/config/initializers/filter_parameter_logging.rb +8 -0
  54. data/spec/support/dummy_app/config/initializers/inflections.rb +16 -0
  55. data/spec/support/dummy_app/config/locales/en.yml +33 -0
  56. data/spec/support/dummy_app/config/routes.rb +6 -0
  57. data/spec/support/dummy_app/config/storage.yml +34 -0
  58. data/spec/support/dummy_app/config.ru +6 -0
  59. data/spec/support/dummy_app/db/migrate/20230804214459_create_users.rb +9 -0
  60. data/spec/support/dummy_app/db/migrate/20230807165013_add_avatar_tmp_column_to_user.rb +5 -0
  61. data/spec/support/dummy_app/db/migrate/20230808233036_add_avatar_processing_flag_to_users.rb +5 -0
  62. data/spec/support/dummy_app/db/migrate/20230809215320_create_admins.rb +10 -0
  63. data/spec/support/dummy_app/db/migrate/20230810182011_add_images_to_users.rb +7 -0
  64. data/spec/support/dummy_app/db/migrate/20230811155811_add_images_to_admins.rb +6 -0
  65. data/spec/support/dummy_app/db/schema.rb +34 -0
  66. data/spec/support/dummy_app/db/seeds.rb +7 -0
  67. data/spec/support/dummy_app/lib/tasks/.keep +0 -0
  68. data/spec/support/dummy_app/log/.keep +0 -0
  69. data/spec/support/dummy_app/public/robots.txt +1 -0
  70. data/spec/support/dummy_app/storage/.keep +0 -0
  71. data/spec/support/dummy_app/tmp/.keep +0 -0
  72. data/spec/support/dummy_app/tmp/development_secret.txt +1 -0
  73. data/spec/support/dummy_app/tmp/images/.gitkeep +0 -0
  74. data/spec/support/dummy_app/tmp/pids/.keep +0 -0
  75. data/spec/support/dummy_app/tmp/storage/.keep +0 -0
  76. data/spec/support/dummy_app/vendor/.keep +0 -0
  77. data/spec/support/fixtures/images/test-1.jpg +0 -0
  78. data/spec/support/fixtures/images/test-2.jpg +0 -0
  79. data/spec/support/global_macros.rb +23 -0
  80. data/spec/support/mock_worker.rb +2 -0
  81. metadata +203 -15
  82. data/spec/support/backend_constants.rb +0 -58
@@ -0,0 +1,86 @@
1
+ require "active_support/core_ext/integer/time"
2
+
3
+ Rails.application.configure do
4
+ # Settings specified here will take precedence over those in config/application.rb.
5
+
6
+ # Code is not reloaded between requests.
7
+ config.cache_classes = true
8
+
9
+ # Eager load code on boot. This eager loads most of Rails and
10
+ # your application in memory, allowing both threaded web servers
11
+ # and those relying on copy on write to perform better.
12
+ # Rake tasks automatically ignore this option for performance.
13
+ config.eager_load = true
14
+
15
+ # Full error reports are disabled and caching is turned on.
16
+ config.consider_all_requests_local = false
17
+
18
+ # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
19
+ # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
20
+ # config.require_master_key = true
21
+
22
+ # Disable serving static files from the `/public` folder by default since
23
+ # Apache or NGINX already handles this.
24
+ config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
25
+
26
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
27
+ # config.asset_host = "http://assets.example.com"
28
+
29
+ # Specifies the header that your server uses for sending files.
30
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
31
+ # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
32
+
33
+ # Store uploaded files on the local file system (see config/storage.yml for options).
34
+ # config.active_storage.service = :local
35
+
36
+ # Mount Action Cable outside main process or domain.
37
+ # config.action_cable.mount_path = nil
38
+ # config.action_cable.url = "wss://example.com/cable"
39
+ # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
40
+
41
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
42
+ # config.force_ssl = true
43
+
44
+ # Include generic and useful information about system operation, but avoid logging too much
45
+ # information to avoid inadvertent exposure of personally identifiable information (PII).
46
+ config.log_level = :info
47
+
48
+ # Prepend all log lines with the following tags.
49
+ config.log_tags = [ :request_id ]
50
+
51
+ # Use a different cache store in production.
52
+ # config.cache_store = :mem_cache_store
53
+
54
+ # Use a real queuing backend for Active Job (and separate queues per environment).
55
+ # config.active_job.queue_adapter = :resque
56
+ # config.active_job.queue_name_prefix = "dummy_app_production"
57
+
58
+ config.action_mailer.perform_caching = false
59
+
60
+ # Ignore bad email addresses and do not raise email delivery errors.
61
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
62
+ # config.action_mailer.raise_delivery_errors = false
63
+
64
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
65
+ # the I18n.default_locale when a translation cannot be found).
66
+ config.i18n.fallbacks = true
67
+
68
+ # Don't log any deprecations.
69
+ config.active_support.report_deprecations = false
70
+
71
+ # Use default logging formatter so that PID and timestamp are not suppressed.
72
+ config.log_formatter = ::Logger::Formatter.new
73
+
74
+ # Use a different logger for distributed setups.
75
+ # require "syslog/logger"
76
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
77
+
78
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
79
+ logger = ActiveSupport::Logger.new(STDOUT)
80
+ logger.formatter = config.log_formatter
81
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
82
+ end
83
+
84
+ # Do not dump schema after migrations.
85
+ config.active_record.dump_schema_after_migration = false
86
+ end
@@ -0,0 +1,61 @@
1
+ require "active_support/core_ext/integer/time"
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+
8
+ Rails.application.configure do
9
+ # Settings specified here will take precedence over those in config/application.rb.
10
+
11
+ # Turn false under Spring and add config.action_view.cache_template_loading = true.
12
+ config.cache_classes = true
13
+
14
+ # Eager loading loads your whole application. When running a single test locally,
15
+ # this probably isn't necessary. It's a good idea to do in a continuous integration
16
+ # system, or in some way before deploying your code.
17
+ config.eager_load = ENV["CI"].present?
18
+
19
+ # Configure public file server for tests with Cache-Control for performance.
20
+ config.public_file_server.enabled = true
21
+ config.public_file_server.headers = {
22
+ "Cache-Control" => "public, max-age=#{1.hour.to_i}"
23
+ }
24
+
25
+ # Show full error reports and disable caching.
26
+ config.consider_all_requests_local = true
27
+ config.action_controller.perform_caching = false
28
+ config.cache_store = :null_store
29
+
30
+ # Raise exceptions instead of rendering exception templates.
31
+ config.action_dispatch.show_exceptions = false
32
+
33
+ # Disable request forgery protection in test environment.
34
+ config.action_controller.allow_forgery_protection = false
35
+
36
+ # Store uploaded files on the local file system in a temporary directory.
37
+ # config.active_storage.service = :test
38
+
39
+ # config.action_mailer.perform_caching = false
40
+
41
+ # Tell Action Mailer not to deliver emails to the real world.
42
+ # The :test delivery method accumulates sent emails in the
43
+ # ActionMailer::Base.deliveries array.
44
+ # config.action_mailer.delivery_method = :test
45
+ config.log_level = :info
46
+
47
+ # Print deprecation notices to the stderr.
48
+ config.active_support.deprecation = :stderr
49
+
50
+ # Raise exceptions for disallowed deprecations.
51
+ config.active_support.disallowed_deprecation = :raise
52
+
53
+ # Tell Active Support which deprecation messages to disallow.
54
+ config.active_support.disallowed_deprecation_warnings = []
55
+
56
+ # Raises error for missing translations.
57
+ # config.i18n.raise_on_missing_translations = true
58
+
59
+ # Annotate rendered view with file names.
60
+ # config.action_view.annotate_rendered_view_with_filenames = true
61
+ end
@@ -0,0 +1,4 @@
1
+ CarrierWave::Backgrounder.configure do |c|
2
+ # c.backend :active_job, queue: :carrierwave
3
+ c.backend :sidekiq, queue: :carrierwave
4
+ end
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Avoid CORS issues when API is called from the frontend app.
4
+ # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
5
+
6
+ # Read more: https://github.com/cyu/rack-cors
7
+
8
+ # Rails.application.config.middleware.insert_before 0, Rack::Cors do
9
+ # allow do
10
+ # origins "example.com"
11
+ #
12
+ # resource "*",
13
+ # headers: :any,
14
+ # methods: [:get, :post, :put, :patch, :delete, :options, :head]
15
+ # end
16
+ # end
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure parameters to be filtered from the log file. Use this to limit dissemination of
4
+ # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported
5
+ # notations and behaviors.
6
+ Rails.application.config.filter_parameters += [
7
+ :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
8
+ ]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, "\\1en"
8
+ # inflect.singular /^(ox)en/i, "\\1"
9
+ # inflect.irregular "person", "people"
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym "RESTful"
16
+ # end
@@ -0,0 +1,33 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t "hello"
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t("hello") %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # The following keys must be escaped otherwise they will not be retrieved by
20
+ # the default I18n backend:
21
+ #
22
+ # true, false, on, off, yes, no
23
+ #
24
+ # Instead, surround them with single quotes.
25
+ #
26
+ # en:
27
+ # "true": "foo"
28
+ #
29
+ # To learn more, please read the Rails Internationalization guide
30
+ # available at https://guides.rubyonrails.org/i18n.html.
31
+
32
+ en:
33
+ hello: "Hello world"
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
3
+
4
+ # Defines the root path route ("/")
5
+ # root "articles#index"
6
+ end
@@ -0,0 +1,34 @@
1
+ test:
2
+ service: Disk
3
+ root: <%= Rails.root.join("tmp/storage") %>
4
+
5
+ local:
6
+ service: Disk
7
+ root: <%= Rails.root.join("storage") %>
8
+
9
+ # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10
+ # amazon:
11
+ # service: S3
12
+ # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13
+ # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14
+ # region: us-east-1
15
+ # bucket: your_own_bucket-<%= Rails.env %>
16
+
17
+ # Remember not to checkin your GCS keyfile to a repository
18
+ # google:
19
+ # service: GCS
20
+ # project: your_project
21
+ # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22
+ # bucket: your_own_bucket-<%= Rails.env %>
23
+
24
+ # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25
+ # microsoft:
26
+ # service: AzureStorage
27
+ # storage_account_name: your_account_name
28
+ # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29
+ # container: your_container_name-<%= Rails.env %>
30
+
31
+ # mirror:
32
+ # service: Mirror
33
+ # primary: local
34
+ # mirrors: [ amazon, google, microsoft ]
@@ -0,0 +1,6 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative "config/environment"
4
+
5
+ run Rails.application
6
+ Rails.application.load_server
@@ -0,0 +1,9 @@
1
+ class CreateUsers < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :avatar
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class AddAvatarTmpColumnToUser < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :users, :avatar_tmp, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddAvatarProcessingFlagToUsers < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :users, :avatar_processing, :boolean, null: false, default: false
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class CreateAdmins < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :admins do |t|
4
+ t.string :avatar
5
+ t.boolean :avatar_processing, null: false, default: false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ class AddImagesToUsers < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :users, :images, :string
4
+ add_column :users, :images_tmp, :string
5
+ add_column :users, :images_processing, :boolean, null: false, default:false
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ class AddImagesToAdmins < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :admins, :images, :string
4
+ add_column :admins, :images_processing, :boolean, null: false, default: false
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema[7.0].define(version: 2023_08_11_155811) do
14
+ create_table "admins", force: :cascade do |t|
15
+ t.string "avatar"
16
+ t.boolean "avatar_processing", default: false, null: false
17
+ t.datetime "created_at", null: false
18
+ t.datetime "updated_at", null: false
19
+ t.string "images"
20
+ t.boolean "images_processing", default: false, null: false
21
+ end
22
+
23
+ create_table "users", force: :cascade do |t|
24
+ t.string "avatar"
25
+ t.datetime "created_at", null: false
26
+ t.datetime "updated_at", null: false
27
+ t.string "avatar_tmp"
28
+ t.boolean "avatar_processing", default: false, null: false
29
+ t.string "images"
30
+ t.string "images_tmp"
31
+ t.boolean "images_processing", default: false, null: false
32
+ end
33
+
34
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
7
+ # Character.create(name: "Luke", movie: movies.first)
File without changes
File without changes
@@ -0,0 +1 @@
1
+ # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
File without changes
File without changes
@@ -0,0 +1 @@
1
+ fd33bd1b056d5db3dc260f4afdc1f3763eecc9c80e4743f381c5d884f06cb6b916887b1bfdb318c6ac255c7ee18f8004a546525cf1ba26e0affc9f234bc950c3
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,23 @@
1
+ module GlobalMacros
2
+ def load_file(name)
3
+ File.open("#{image_fixture_path}/#{name}")
4
+ end
5
+
6
+ def load_files(*names)
7
+ names.map { |name| load_file(name) }
8
+ end
9
+
10
+ def image_fixture_path
11
+ 'spec/support/fixtures/images'
12
+ end
13
+
14
+ def file_count(path)
15
+ Dir.entries(path).reject { |f| f =~ /\.\.$|\.$|\.gitkeep/ }.size
16
+ end
17
+
18
+ def process_latest_sidekiq_job
19
+ job = Sidekiq::Queues["carrierwave"].pop
20
+ worker = job['class'].constantize.new(*job['args'])
21
+ worker.perform
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ require 'sidekiq'
2
+
1
3
  class MockWorker < Struct.new(:klass, :id, :column)
2
4
  def self.perform(*args)
3
5
  new(*args).perform