Sha256: bd8d7b3beebbce5e70df2f174c58e6121978a2d3bc0dbed4f456d61afec94ceb

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

namespace :consyncful do
  task update: [:environment] do
    Consyncful::Sync.latest.run
  end

  task refresh: [:environment] do
    Consyncful::Sync.fresh.run
  end

  task :sync, [:seconds] => %i[environment update_model_names] do |_task, args|
    Signal.trap('TERM') do
      puts Rainbow("Graceful shutdown PID=#{Process.pid}").red
      exit 0
    end

    seconds = args[:seconds].to_i
    seconds = 15 if seconds.zero?
    loop do
      Consyncful::Sync.latest.run
      sleep(seconds)
    end
  end

  task update_model_names: [:environment] do
    if Rails.autoloaders.zeitwerk_enabled?
      Zeitwerk::Loader.eager_load_all
    else
      Rails.application.eager_load!
    end

    puts Rainbow('Updating model names:').blue

    Consyncful::Base.model_map.each do |contentful_name, constant|
      puts Rainbow("#{contentful_name}: #{constant}").yellow
      Consyncful::Base.where(contentful_type: contentful_name).update_all(_type: constant.to_s)
    end

    Consyncful::Base.where(:contentful_type.nin => Consyncful::Base.model_map.keys).update_all(_type: 'Consyncful::Base')
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
consyncful-1.0.1 lib/consyncful/tasks/consyncful.rake
consyncful-1.0.0 lib/consyncful/tasks/consyncful.rake
consyncful-0.9.0 lib/consyncful/tasks/consyncful.rake
consyncful-0.8.0 lib/consyncful/tasks/consyncful.rake
consyncful-0.7.3 lib/consyncful/tasks/consyncful.rake
consyncful-0.7.2 lib/consyncful/tasks/consyncful.rake