pg_cron 2.0.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.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +25 -0
  3. data/CHANGELOG.md +56 -0
  4. data/Gemfile +8 -0
  5. data/Gemfile.lock +121 -0
  6. data/LICENSE +21 -0
  7. data/README.md +54 -0
  8. data/Rakefile +16 -0
  9. data/bin/console +15 -0
  10. data/bin/increment-version +37 -0
  11. data/bin/release-gem +32 -0
  12. data/bin/setup +8 -0
  13. data/lib/generators/pg_cron/job/USAGE +19 -0
  14. data/lib/generators/pg_cron/job/job_generator.rb +116 -0
  15. data/lib/generators/pg_cron/job/templates/db/migrate/create_job.erb +5 -0
  16. data/lib/generators/pg_cron/job/templates/db/migrate/update_job.erb +5 -0
  17. data/lib/generators/pg_cron/migration_helper.rb +48 -0
  18. data/lib/generators/pg_cron/name_helper.rb +29 -0
  19. data/lib/generators/pg_cron/version_helper.rb +53 -0
  20. data/lib/pg_cron/adapters/postgres/connection.rb +26 -0
  21. data/lib/pg_cron/adapters/postgres/jobs.rb +48 -0
  22. data/lib/pg_cron/adapters/postgres/query_executor.rb +37 -0
  23. data/lib/pg_cron/adapters/postgres.rb +116 -0
  24. data/lib/pg_cron/command_recorder.rb +50 -0
  25. data/lib/pg_cron/configuration.rb +37 -0
  26. data/lib/pg_cron/definition.rb +74 -0
  27. data/lib/pg_cron/job.rb +68 -0
  28. data/lib/pg_cron/railtie.rb +22 -0
  29. data/lib/pg_cron/schema_dumper.rb +35 -0
  30. data/lib/pg_cron/statements.rb +126 -0
  31. data/lib/pg_cron/version.rb +5 -0
  32. data/lib/pg_cron/version.rb.erb +5 -0
  33. data/lib/pg_cron.rb +44 -0
  34. data/lib/tasks/pg_cron/down.rake +21 -0
  35. data/lib/tasks/pg_cron/schedule_all_jobs.rake +33 -0
  36. data/lib/tasks/pg_cron/schedule_job.rake +12 -0
  37. data/lib/tasks/pg_cron/unschedule_job.rake +12 -0
  38. data/lib/tasks/pg_cron/up.rake +25 -0
  39. data/lib/tasks/pg_cron/utils.rb +124 -0
  40. data/spec/dummy/.gitignore +71 -0
  41. data/spec/dummy/.ruby-version +1 -0
  42. data/spec/dummy/README.md +24 -0
  43. data/spec/dummy/Rakefile +6 -0
  44. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  45. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  46. data/spec/dummy/app/models/application_record.rb +3 -0
  47. data/spec/dummy/app/models/concerns/.keep +0 -0
  48. data/spec/dummy/bin/rails +4 -0
  49. data/spec/dummy/bin/rake +4 -0
  50. data/spec/dummy/bin/setup +33 -0
  51. data/spec/dummy/config/application.rb +40 -0
  52. data/spec/dummy/config/boot.rb +3 -0
  53. data/spec/dummy/config/credentials.yml.enc +1 -0
  54. data/spec/dummy/config/database.yml +86 -0
  55. data/spec/dummy/config/environment.rb +5 -0
  56. data/spec/dummy/config/environments/development.rb +58 -0
  57. data/spec/dummy/config/environments/production.rb +96 -0
  58. data/spec/dummy/config/environments/test.rb +49 -0
  59. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  60. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  61. data/spec/dummy/config/initializers/cors.rb +16 -0
  62. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  63. data/spec/dummy/config/initializers/inflections.rb +16 -0
  64. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  65. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/spec/dummy/config/locales/en.yml +33 -0
  67. data/spec/dummy/config/puma.rb +43 -0
  68. data/spec/dummy/config/routes.rb +3 -0
  69. data/spec/dummy/config.ru +6 -0
  70. data/spec/dummy/db/pg_cron_jobs/dummy_job.yml +3 -0
  71. data/spec/dummy/db/seeds.rb +7 -0
  72. data/spec/dummy/lib/tasks/.keep +0 -0
  73. data/spec/dummy/log/.keep +0 -0
  74. data/spec/dummy/public/robots.txt +1 -0
  75. data/spec/dummy/tmp/.keep +0 -0
  76. data/spec/dummy/vendor/.keep +0 -0
  77. data/spec/pg_cron/configuration_spec.rb +20 -0
  78. data/spec/pg_cron/fx_coexistence_spec.rb +53 -0
  79. data/spec/pg_cron/statements_spec.rb +9 -0
  80. data/spec/spec_helper.rb +6 -0
  81. metadata +245 -0
@@ -0,0 +1,86 @@
1
+ # PostgreSQL. Versions 9.3 and up are supported.
2
+ #
3
+ # Install the pg driver:
4
+ # gem install pg
5
+ # On macOS with Homebrew:
6
+ # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7
+ # On macOS 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
+ # https://guides.rubyonrails.org/configuring.html#database-pooling
22
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
23
+
24
+ development:
25
+ <<: *default
26
+ database: dummy_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 running Rails.
32
+ username: postgres
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: dummy_test
61
+
62
+ # As with config/credentials.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 or a full connection URL as an environment
67
+ # variable when you boot the app. For example:
68
+ #
69
+ # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
70
+ #
71
+ # If the connection URL is provided in the special DATABASE_URL environment
72
+ # variable, Rails will automatically merge its configuration values on top of
73
+ # the values provided in this file. Alternatively, you can specify a connection
74
+ # URL environment variable explicitly:
75
+ #
76
+ # production:
77
+ # url: <%= ENV['MY_APP_DATABASE_URL'] %>
78
+ #
79
+ # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
80
+ # for a full overview on how database connection configuration can be specified.
81
+ #
82
+ production:
83
+ <<: *default
84
+ database: dummy_production
85
+ username: dummy
86
+ password: <%= ENV['DUMMY_DATABASE_PASSWORD'] %>
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative "application"
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,58 @@
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
+ # In the development environment your application's code is reloaded any time
7
+ # it changes. This slows down response time but is perfect for development
8
+ # since you don't have to restart the web server when you make code changes.
9
+ config.cache_classes = false
10
+
11
+ # Do not eager load code on boot.
12
+ config.eager_load = false
13
+
14
+ # Show full error reports.
15
+ config.consider_all_requests_local = true
16
+
17
+ # Enable/disable caching. By default caching is disabled.
18
+ # Run rails dev:cache to toggle caching.
19
+ if Rails.root.join('tmp', 'caching-dev.txt').exist?
20
+ config.cache_store = :memory_store
21
+ config.public_file_server.headers = {
22
+ 'Cache-Control' => "public, max-age=#{2.days.to_i}"
23
+ }
24
+ else
25
+ config.action_controller.perform_caching = false
26
+
27
+ config.cache_store = :null_store
28
+ end
29
+
30
+ # Print deprecation notices to the Rails logger.
31
+ config.active_support.deprecation = :log
32
+
33
+ # Raise exceptions for disallowed deprecations.
34
+ config.active_support.disallowed_deprecation = :raise
35
+
36
+ # Tell Active Support which deprecation messages to disallow.
37
+ config.active_support.disallowed_deprecation_warnings = []
38
+
39
+ # Raise an error on page load if there are pending migrations.
40
+ config.active_record.migration_error = :page_load
41
+
42
+ # Highlight code that triggered database queries in logs.
43
+ config.active_record.verbose_query_logs = true
44
+
45
+
46
+ # Raises error for missing translations.
47
+ # config.i18n.raise_on_missing_translations = true
48
+
49
+ # Annotate rendered view with file names.
50
+ # config.action_view.annotate_rendered_view_with_filenames = true
51
+
52
+ # Use an evented file watcher to asynchronously detect changes in source code,
53
+ # routes, locales, etc. This feature depends on the listen gem.
54
+ # config.file_watcher = ActiveSupport::EventedFileUpdateChecker
55
+
56
+ # Uncomment if you wish to allow Action Cable access from any origin.
57
+ # config.action_cable.disable_request_forgery_protection = true
58
+ end
@@ -0,0 +1,96 @@
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
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
34
+ # config.force_ssl = true
35
+
36
+ # Include generic and useful information about system operation, but avoid logging too much
37
+ # information to avoid inadvertent exposure of personally identifiable information (PII).
38
+ config.log_level = :info
39
+
40
+ # Prepend all log lines with the following tags.
41
+ config.log_tags = [ :request_id ]
42
+
43
+ # Use a different cache store in production.
44
+ # config.cache_store = :mem_cache_store
45
+
46
+
47
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
48
+ # the I18n.default_locale when a translation cannot be found).
49
+ config.i18n.fallbacks = true
50
+
51
+ # Send deprecation notices to registered listeners.
52
+ config.active_support.deprecation = :notify
53
+
54
+ # Log disallowed deprecations.
55
+ config.active_support.disallowed_deprecation = :log
56
+
57
+ # Tell Active Support which deprecation messages to disallow.
58
+ config.active_support.disallowed_deprecation_warnings = []
59
+
60
+ # Use default logging formatter so that PID and timestamp are not suppressed.
61
+ config.log_formatter = ::Logger::Formatter.new
62
+
63
+ # Use a different logger for distributed setups.
64
+ # require "syslog/logger"
65
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
66
+
67
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
68
+ logger = ActiveSupport::Logger.new(STDOUT)
69
+ logger.formatter = config.log_formatter
70
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
71
+ end
72
+
73
+ # Do not dump schema after migrations.
74
+ config.active_record.dump_schema_after_migration = false
75
+
76
+ # Inserts middleware to perform automatic connection switching.
77
+ # The `database_selector` hash is used to pass options to the DatabaseSelector
78
+ # middleware. The `delay` is used to determine how long to wait after a write
79
+ # to send a subsequent read to the primary.
80
+ #
81
+ # The `database_resolver` class is used by the middleware to determine which
82
+ # database is appropriate to use based on the time delay.
83
+ #
84
+ # The `database_resolver_context` class is used by the middleware to set
85
+ # timestamps for the last write to the primary. The resolver uses the context
86
+ # class timestamps to determine how long to wait before reading from the
87
+ # replica.
88
+ #
89
+ # By default Rails will store a last write timestamp in the session. The
90
+ # DatabaseSelector middleware is designed as such you can define your own
91
+ # strategy for connection switching and pass that into the middleware through
92
+ # these configuration options.
93
+ # config.active_record.database_selector = { delay: 2.seconds }
94
+ # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
95
+ # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
96
+ end
@@ -0,0 +1,49 @@
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
+ config.cache_classes = true
12
+
13
+ # Do not eager load code on boot. This avoids loading your whole application
14
+ # just for the purpose of running a single test. If you are using a tool that
15
+ # preloads Rails for running tests, you may have to set it to true.
16
+ config.eager_load = false
17
+
18
+ # Configure public file server for tests with Cache-Control for performance.
19
+ config.public_file_server.enabled = true
20
+ config.public_file_server.headers = {
21
+ 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
22
+ }
23
+
24
+ # Show full error reports and disable caching.
25
+ config.consider_all_requests_local = true
26
+ config.action_controller.perform_caching = false
27
+ config.cache_store = :null_store
28
+
29
+ # Raise exceptions instead of rendering exception templates.
30
+ config.action_dispatch.show_exceptions = false
31
+
32
+ # Disable request forgery protection in test environment.
33
+ config.action_controller.allow_forgery_protection = false
34
+
35
+ # Print deprecation notices to the stderr.
36
+ config.active_support.deprecation = :stderr
37
+
38
+ # Raise exceptions for disallowed deprecations.
39
+ config.active_support.disallowed_deprecation = :raise
40
+
41
+ # Tell Active Support which deprecation messages to disallow.
42
+ config.active_support.disallowed_deprecation_warnings = []
43
+
44
+ # Raises error for missing translations.
45
+ # config.i18n.raise_on_missing_translations = true
46
+
47
+ # Annotate rendered view with file names.
48
+ # config.action_view.annotate_rendered_view_with_filenames = true
49
+ end
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # ActiveSupport::Reloader.to_prepare do
4
+ # ApplicationController.renderer.defaults.merge!(
5
+ # http_host: 'example.org',
6
+ # https: false
7
+ # )
8
+ # end
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code
7
+ # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'".
8
+ Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"]
@@ -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,6 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [
5
+ :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
6
+ ]
@@ -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,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # 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,43 @@
1
+ # Puma can serve each request in a thread from an internal thread pool.
2
+ # The `threads` method setting takes two numbers: a minimum and maximum.
3
+ # Any libraries that use thread pools should be configured to match
4
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
+ # and maximum; this matches the default thread size of Active Record.
6
+ #
7
+ max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8
+ min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9
+ threads min_threads_count, max_threads_count
10
+
11
+ # Specifies the `worker_timeout` threshold that Puma will use to wait before
12
+ # terminating a worker in development environments.
13
+ #
14
+ worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
15
+
16
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
17
+ #
18
+ port ENV.fetch("PORT") { 3000 }
19
+
20
+ # Specifies the `environment` that Puma will run in.
21
+ #
22
+ environment ENV.fetch("RAILS_ENV") { "development" }
23
+
24
+ # Specifies the `pidfile` that Puma will use.
25
+ pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
26
+
27
+ # Specifies the number of `workers` to boot in clustered mode.
28
+ # Workers are forked web server processes. If using threads and workers together
29
+ # the concurrency of the application would be max `threads` * `workers`.
30
+ # Workers do not work on JRuby or Windows (both of which do not support
31
+ # processes).
32
+ #
33
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
34
+
35
+ # Use the `preload_app!` method when specifying a `workers` number.
36
+ # This directive tells Puma to first boot the application and load code
37
+ # before forking the application. This takes advantage of Copy On Write
38
+ # process behavior so workers use less memory.
39
+ #
40
+ # preload_app!
41
+
42
+ # Allow puma to be restarted by `rails restart` command.
43
+ plugin :tmp_restart
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
3
+ end
@@ -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,3 @@
1
+ dummy_job:
2
+ cron: "* * * * *"
3
+ statement: "SELECT pg_sleep(1)"
@@ -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,20 @@
1
+ require "spec_helper"
2
+
3
+ module PgCron
4
+ RSpec.describe 'Configuration' do
5
+ it "must default using the ActiveRecord::Base.connection user" do
6
+ expect(PgCron.connection.execute("SELECT current_user").first["current_user"]).to eq(ActiveRecord::Base.connection_db_config.configuration_hash[:username])
7
+ end
8
+
9
+ it "must default connection to DEFAULT_PG_DATABASE_NAME database" do
10
+ expect(PgCron.connection.execute("SELECT current_database()").first["current_database"]).to eq(PgCron::Configuration::DEFAULT_PG_DATABASE_NAME)
11
+ end
12
+
13
+ it "must be possible to change database connection configuration" do
14
+ PgCron.configure do |config|
15
+ config.connection_config = ActiveRecord::Base.connection_db_config.configuration_hash.merge({ database: "dummy_development" })
16
+ end
17
+ expect(PgCron.connection.execute("SELECT current_database()").first["current_database"]).to eq("dummy_development")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The regression this gem shipped: PgCron::Statements and Fx::Statements are both
4
+ # included into ActiveRecord::ConnectionAdapters::AbstractAdapter, and every
5
+ # private helper here was lifted from F(x) under F(x)'s own name. We are included
6
+ # second, so ours won — and `resolve_sql_definition` takes one argument fewer
7
+ # than F(x)'s, which meant that merely loading this gem broke create_function,
8
+ # create_trigger and update_function in the HOST application:
9
+ #
10
+ # ArgumentError: wrong number of arguments (given 4, expected 3)
11
+ #
12
+ # The fix is that our private helpers are named `*_cron_*`. This is the test that
13
+ # says so, and it needs no database — the bug was in method lookup, not in SQL.
14
+ #
15
+ # Deliberately checks the whole intersection rather than that one method. The
16
+ # next helper copied across from F(x) is the next outage, and only a test of the
17
+ # INTERSECTION catches one that has not been written yet.
18
+ require "active_support/all"
19
+ require "pg_cron/statements"
20
+ require "fx/statements"
21
+
22
+ RSpec.describe "PgCron::Statements alongside Fx::Statements" do
23
+ # Both modules are mixed into one object, so any shared name is a collision —
24
+ # whichever include lands second silently replaces the other's method.
25
+ def shared_instance_methods(visibility)
26
+ ours = PgCron::Statements.send(:"#{visibility}_instance_methods", false)
27
+ theirs = Fx::Statements.send(:"#{visibility}_instance_methods", false)
28
+ ours & theirs
29
+ end
30
+
31
+ it "shares no public method name with F(x)" do
32
+ expect(shared_instance_methods(:public)).to be_empty
33
+ end
34
+
35
+ it "shares no private method name with F(x)" do
36
+ expect(shared_instance_methods(:private)).to be_empty
37
+ end
38
+
39
+ # The end the user actually feels: with both modules in, in the order the
40
+ # railties install them, F(x)'s statements still reach F(x)'s implementation.
41
+ it "leaves F(x)'s statements callable when included second" do
42
+ adapter = Class.new do
43
+ include Fx::Statements
44
+ include PgCron::Statements # second, as the railtie does it
45
+ end.new
46
+
47
+ # F(x)'s four-argument private helper, reached through F(x)'s own method
48
+ # lookup. Before the rename this raised ArgumentError here.
49
+ expect {
50
+ adapter.send(:resolve_sql_definition, "SELECT 1;\n", :whatever, 1, :function)
51
+ }.not_to raise_error
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ module PgCron
4
+ RSpec.describe 'Statements' do
5
+ it "must not fail if pg_cron extension is not enabled" do
6
+ expect { ActiveRecord::Base.connection.schedule_pg_cron_job("dummy_job") }.to_not raise_error
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../spec/dummy/config/environment.rb', __dir__)
4
+ ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '../../../spec/dummy'
5
+
6
+ require 'rspec/rails'