Class: EtnaApp::Magma::Models::LoadFromRedcap

Inherits:
Etna::Command show all
Includes:
StrongConfirmation, WithEtnaClients, WithLogger
Defined in:
lib/commands.rb

Instance Attribute Summary

Attributes inherited from Etna::Command

#parent

Instance Method Summary collapse

Methods included from StrongConfirmation

#confirm

Methods included from WithLogger

#logger

Methods included from WithEtnaClients

#environment, #exit, exit, #janus_client, #magma_client, #metis_client, #polyphemus_client, #token

Methods inherited from Etna::Command

#completions, #fill_in_missing_params, #find_command, #initialize, parent_scope, #setup

Methods included from Etna::CommandOrExecutor

#command_name, #completions_for, #desc, #flag_argspec, #flag_as_parameter, included, #parse_flags, #program_name, #usage

Constructor Details

This class inherits a constructor from Etna::Command

Instance Method Details

#clean_sne_message(chunk) ⇒ Object



575
576
577
578
579
580
581
582
583
# File 'lib/commands.rb', line 575

def clean_sne_message(chunk)
  chunk.split("\n").reject do |c|
    c.start_with?("retry:") || c.start_with?("event:")
  end.map do |c|
    c.gsub("data:", "").strip
  end.reject do |c|
    c.empty?
  end
end

#execute(project_name, redcap_tokens, models: "all", mode: nil, commit: false) ⇒ Object



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/commands.rb', line 557

def execute(project_name, redcap_tokens, models: "all", mode: nil, commit: false)
  raise "Must provide at least one REDCap token (comma-separated)." unless redcap_tokens.split(',').length > 0

  puts "NOTE: This is a **preview** of what the data loading will look like. Use the --commit flag to load records into Magma." unless commit

  polyphemus_client.job(Etna::Clients::Polyphemus::RedcapJobRequest.new(
    model_names: "all" == models ? "all" : models.split(','),
    mode: mode,
    redcap_tokens: redcap_tokens.split(','),
    project_name: project_name,
    commit: commit
  )) do |response|
    response.read_body do |chunk|
      puts clean_sne_message(chunk)
    end
  end
end