Class: ArchiveStorage::ScheduleConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/archive_storage/schedule_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cronObject (readonly)

Returns the value of attribute cron.



8
9
10
# File 'lib/archive_storage/schedule_config.rb', line 8

def cron
  @cron
end

#migration_rateObject (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

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/archive_storage/schedule_config.rb', line 8

def model
  @model
end

#mounted_asObject (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

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/archive_storage/schedule_config.rb', line 8

def name
  @name
end

#uploadersObject (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_nameObject



19
20
21
# File 'lib/archive_storage/schedule_config.rb', line 19

def entry_name
  name
end

#good_job_entryObject



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_argumentsObject



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_entryObject



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

Raises:



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