This repository was archived by the owner on Feb 20, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +40
-7
lines changed Expand file tree Collapse file tree 7 files changed +40
-7
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ docker/log
6
6
.viminfo
7
7
.bash_history
8
8
* .swp
9
+ .env
10
+ .idea
9
11
10
12
# Ruby / RMV
11
13
.ruby-version
Original file line number Diff line number Diff line change 9
9
#
10
10
# See https://docs.rubocop.org/rubocop/configuration
11
11
Layout/LineLength :
12
- Max : 100
12
+ Max : 120
13
13
Style/FrozenStringLiteralComment :
14
14
EnforcedStyle : always_true
15
15
Safe : true
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
1
3
class Api ::SourcesController < ApplicationController
2
4
before_action :set_source , only : %i[ show update destroy ]
3
5
4
6
# GET /sources
5
7
def index
8
+ # re-read config.yml sources
9
+ Source . new . refresh
10
+
6
11
@sources = Source . all . order ( id : :asc )
7
12
8
13
render json : @sources
Original file line number Diff line number Diff line change 7
7
8
8
class LoaderJob < ApplicationJob
9
9
queue_as :default
10
+ CONFIG_FILE = 'load_config/config.yaml'
10
11
11
12
TYPE = :load
12
13
@@ -26,7 +27,7 @@ def perform(args)
26
27
logger . info 'Loading data'
27
28
28
29
begin
29
- BatchImporter . new ( 'load_config/config.yaml' ) . import
30
+ BatchImporter . new ( CONFIG_FILE ) . import
30
31
job . complete!
31
32
puts "Loader job finished - #{ guid } "
32
33
rescue StandardError => e
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
1
3
class Source < ApplicationRecord
2
4
enum status : {
3
5
disabled : 0 ,
@@ -9,4 +11,23 @@ class Source < ApplicationRecord
9
11
def schedule_worker
10
12
RunnerJob . perform_later if scan_requested?
11
13
end
14
+
15
+ def refresh
16
+ # read config file, find or create a source for each source listed
17
+ config_sources = JSON . parse ( YAML . load_file ( LoaderJob ::CONFIG_FILE ) . to_json , object_class : OpenStruct )
18
+
19
+ return unless config_sources &.local_dirs &.length &.positive?
20
+
21
+ config_sources . local_dirs . each do |dir |
22
+ puts "Config file local dir source=#{ dir } "
23
+ source = Source . find_or_create_by ( name : dir )
24
+ source . active!
25
+ end
26
+
27
+ # loop through all existing sources, disable if not in config file
28
+ Source . all . each do |source |
29
+ puts "Config file system source=#{ source . name } status=#{ source . status } "
30
+ source . disabled! unless config_sources . local_dirs . include? ( source . name )
31
+ end
32
+ end
12
33
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
1
3
class User < ApplicationRecord
2
4
has_secure_password
3
5
rolify
@@ -72,22 +74,22 @@ def get_nav_paths
72
74
{
73
75
path : '/campaigns' ,
74
76
name : 'Campaigns' ,
75
- num : Campaign . all . count
77
+ num : Campaign . all . count . to_s
76
78
} ,
77
79
{
78
80
path : '/profiles' ,
79
81
name : 'Profiles' ,
80
- num : Profile . all . count
82
+ num : Profile . all . count . to_s
81
83
} ,
82
84
{
83
85
path : '/controls' ,
84
86
name : 'Controls' ,
85
- num : Control . all . count
87
+ num : Control . all . count . to_s
86
88
} ,
87
89
{
88
90
path : '/sources' ,
89
91
name : 'Sources' ,
90
- num : Source . all . count
92
+ num : Source . all . count . to_s
91
93
}
92
94
]
93
95
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
1
3
$:. unshift ( '/app/app/jobs/lib' )
2
4
require 'batch_importer'
3
5
require 'pry'
4
6
5
7
namespace :batch do
6
8
desc 'Loads All Data from Import'
7
9
task import : :environment do
8
- BatchImporter . new ( "load_config/config.yaml" ) . import
10
+ BatchImporter . new ( LoaderJob :: CONFIG_FILE ) . import
9
11
end
10
12
end
You can’t perform that action at this time.
0 commit comments