Class: ArchiveStorage::ScheduleConfig
- Inherits:
-
Object
- Object
- ArchiveStorage::ScheduleConfig
- Defined in:
- lib/archive_storage/schedule_config.rb
Instance Attribute Summary collapse
-
#cron ⇒ Object
readonly
Returns the value of attribute cron.
-
#migration_rate ⇒ Object
readonly
Returns the value of attribute migration_rate.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#mounted_as ⇒ Object
readonly
Returns the value of attribute mounted_as.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#uploaders ⇒ Object
readonly
Returns the value of attribute uploaders.
Instance Method Summary collapse
- #entry_name ⇒ Object
- #good_job_entry ⇒ Object
-
#initialize(name, cron:, model: nil, mounted_as: nil, uploaders: [], migration_rate: nil) ⇒ ScheduleConfig
constructor
A new instance of ScheduleConfig.
- #job_arguments ⇒ Object
- #sidekiq_cron_entry ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(name, cron:, model: nil, mounted_as: nil, uploaders: [], migration_rate: nil) ⇒ ScheduleConfig
Returns a new instance of ScheduleConfig.
10 11 12 13 14 15 16 17 |
# File 'lib/archive_storage/schedule_config.rb', line 10 def initialize(name, cron:, model: nil, mounted_as: nil, uploaders: [], migration_rate: nil) @name = name.to_sym @cron = cron @model = model @mounted_as = mounted_as&.to_sym @uploaders = uploaders.flatten.compact.map(&:to_s) @migration_rate = MigrationRate.new(migration_rate) if migration_rate end |
Instance Attribute Details
#cron ⇒ Object (readonly)
Returns the value of attribute cron.
8 9 10 |
# File 'lib/archive_storage/schedule_config.rb', line 8 def cron @cron end |
#migration_rate ⇒ Object (readonly)
Returns the value of attribute migration_rate.
8 9 10 |
# File 'lib/archive_storage/schedule_config.rb', line 8 def migration_rate @migration_rate end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/archive_storage/schedule_config.rb', line 8 def model @model end |
#mounted_as ⇒ Object (readonly)
Returns the value of attribute mounted_as.
8 9 10 |
# File 'lib/archive_storage/schedule_config.rb', line 8 def mounted_as @mounted_as end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/archive_storage/schedule_config.rb', line 8 def name @name end |
#uploaders ⇒ Object (readonly)
Returns the value of attribute uploaders.
8 9 10 |
# File 'lib/archive_storage/schedule_config.rb', line 8 def uploaders @uploaders end |
Instance Method Details
#entry_name ⇒ Object
19 20 21 |
# File 'lib/archive_storage/schedule_config.rb', line 19 def entry_name name end |
#good_job_entry ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/archive_storage/schedule_config.rb', line 43 def good_job_entry validate! { cron: cron, class: "ArchiveStorage::Jobs::QueueJob", set: { queue: ArchiveStorage.configuration.schedule_queue }, args: [job_arguments] } end |
#job_arguments ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/archive_storage/schedule_config.rb', line 23 def job_arguments {}.tap do |args| if mount_schedule? args[:model] = model_name args[:mounted_as] = mounted_as.to_s else args[:uploaders] = uploaders end args[:migration_rate] = migration_rate.max_files_per_run if migration_rate end end |
#sidekiq_cron_entry ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/archive_storage/schedule_config.rb', line 54 def sidekiq_cron_entry validate! { "cron" => cron, "class" => "ArchiveStorage::Jobs::SidekiqQueueWorker", "queue" => ArchiveStorage.configuration.schedule_queue.to_s, "args" => [stringify_keys(job_arguments)] } end |
#validate! ⇒ Object
36 37 38 39 40 41 |
# File 'lib/archive_storage/schedule_config.rb', line 36 def validate! raise ConfigurationError, "archive_storage schedule #{name.inspect} requires cron" if cron.nil? || cron == "" return if mount_schedule? || uploaders.any? raise ConfigurationError, "archive_storage schedule #{name.inspect} requires model/mounted_as or uploader" end |