Skip to content

Commit 68004fc

Browse files
committed
feat: integrate Sidekiq for background job processing and update configurations
1 parent 22bea3c commit 68004fc

7 files changed

Lines changed: 98 additions & 37 deletions

File tree

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ gem 'rake'
1010
gem 'rexml' # Investigate why unicorn fails to start under ruby 3 without adding rexml gem to the Gemfile
1111
gem 'sinatra'
1212
gem 'rackup'
13+
gem 'sidekiq', '7.3.9'
1314

1415
github 'sinatra/sinatra' do
1516
gem 'sinatra-contrib'
@@ -54,7 +55,7 @@ gem 'pandoc-ruby'
5455
gem 'ncbo_annotator', git: 'https://github.com/agroportal/ncbo_annotator.git', branch: 'development'
5556
gem 'ncbo_cron', git: 'https://github.com/agroportal/ncbo_cron.git', branch: 'development'
5657
gem 'ncbo_ontology_recommender', git: 'https://github.com/agroportal/ncbo_ontology_recommender.git', branch: 'development'
57-
gem 'ontologies_linked_data', github: 'agroportal/ontologies_linked_data', branch: 'development'
58+
gem 'ontologies_linked_data', github: 'agroportal/ontologies_linked_data', branch: 'feat/sidekiq-integration'
5859
gem 'goo', github: 'agroportal/goo', branch: 'development'
5960
gem 'sparql-client', github: 'agroportal/sparql-client', branch: 'development'
6061

Gemfile.lock

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ GIT
2929

3030
GIT
3131
remote: https://github.com/agroportal/ncbo_cron.git
32-
revision: 2eb5cfd12e6e8fd9d3b0a6610d836a358cdfc409
32+
revision: 1447bf247caca0858cf4d454ec44fec6f3a44b55
3333
branch: development
3434
specs:
3535
ncbo_cron (0.0.1)
@@ -57,8 +57,8 @@ GIT
5757

5858
GIT
5959
remote: https://github.com/agroportal/ontologies_linked_data.git
60-
revision: e34ef6d84858c7235a6a28be77aca4a528e84b32
61-
branch: development
60+
revision: 3c3ff6749e7332521de5f9e43a22d1c47050d485
61+
branch: feat/sidekiq-integration
6262
specs:
6363
ontologies_linked_data (0.0.1)
6464
activesupport
@@ -128,7 +128,7 @@ GIT
128128
GEM
129129
remote: https://rubygems.org/
130130
specs:
131-
activesupport (7.2.3)
131+
activesupport (7.2.3.1)
132132
base64
133133
benchmark (>= 0.3)
134134
bigdecimal
@@ -137,7 +137,7 @@ GEM
137137
drb
138138
i18n (>= 1.6, < 2)
139139
logger (>= 1.4.2)
140-
minitest (>= 5.1)
140+
minitest (>= 5.1, < 6)
141141
securerandom (>= 0.3)
142142
tzinfo (~> 2.0, >= 2.0.5)
143143
addressable (2.8.9)
@@ -148,12 +148,12 @@ GEM
148148
ast (2.4.3)
149149
base64 (0.3.0)
150150
bcp47_spec (0.2.1)
151-
bcrypt (3.1.21)
151+
bcrypt (3.1.22)
152152
bcrypt_pbkdf (1.1.2)
153153
bcrypt_pbkdf (1.1.2-arm64-darwin)
154154
bcrypt_pbkdf (1.1.2-x86_64-darwin)
155155
benchmark (0.5.0)
156-
bigdecimal (4.0.1)
156+
bigdecimal (4.1.0)
157157
builder (3.3.0)
158158
capistrano (3.20.0)
159159
airbrussh (>= 1.0.0)
@@ -229,10 +229,12 @@ GEM
229229
google-cloud-env (2.3.1)
230230
base64 (~> 0.2)
231231
faraday (>= 1.0, < 3.a)
232-
google-cloud-errors (1.5.0)
232+
google-cloud-errors (1.6.0)
233233
google-logging-utils (0.2.0)
234234
google-protobuf (3.25.3)
235+
google-protobuf (3.25.3-aarch64-linux)
235236
google-protobuf (3.25.3-arm64-darwin)
237+
google-protobuf (3.25.3-x86-linux)
236238
google-protobuf (3.25.3-x86_64-darwin)
237239
google-protobuf (3.25.3-x86_64-linux)
238240
googleapis-common-protos (1.8.0)
@@ -252,9 +254,15 @@ GEM
252254
grpc (1.70.1)
253255
google-protobuf (>= 3.25, < 5.0)
254256
googleapis-common-protos-types (~> 1.0)
257+
grpc (1.70.1-aarch64-linux)
258+
google-protobuf (>= 3.25, < 5.0)
259+
googleapis-common-protos-types (~> 1.0)
255260
grpc (1.70.1-arm64-darwin)
256261
google-protobuf (>= 3.25, < 5.0)
257262
googleapis-common-protos-types (~> 1.0)
263+
grpc (1.70.1-x86-linux)
264+
google-protobuf (>= 3.25, < 5.0)
265+
googleapis-common-protos-types (~> 1.0)
258266
grpc (1.70.1-x86_64-darwin)
259267
google-protobuf (>= 3.25, < 5.0)
260268
googleapis-common-protos-types (~> 1.0)
@@ -272,7 +280,7 @@ GEM
272280
i18n (1.14.8)
273281
concurrent-ruby (~> 1.0)
274282
io-console (0.8.2)
275-
json (2.19.1)
283+
json (2.19.3)
276284
json-canonicalization (0.4.0)
277285
json-ld (3.2.5)
278286
htmlentities (~> 4.3)
@@ -300,13 +308,11 @@ GEM
300308
net-imap
301309
net-pop
302310
net-smtp
303-
mcp (0.8.0)
304-
json-schema (>= 4.1)
305311
method_source (1.1.0)
306312
mime-types (3.7.0)
307313
logger
308314
mime-types-data (~> 3.2025, >= 3.2025.0507)
309-
mime-types-data (3.2026.0303)
315+
mime-types-data (3.2026.0317)
310316
mini_mime (1.1.5)
311317
minitest (5.27.0)
312318
minitest-fail-fast (0.2.0)
@@ -344,7 +350,7 @@ GEM
344350
net-ssh (>= 5.0.0, < 8.0.0)
345351
net-smtp (0.5.1)
346352
net-protocol
347-
net-ssh (7.3.0)
353+
net-ssh (7.3.2)
348354
netrc (0.11.0)
349355
oj (3.16.16)
350356
bigdecimal (>= 3.0)
@@ -356,7 +362,7 @@ GEM
356362
pandoc-ruby (2.1.10)
357363
parallel (1.27.0)
358364
parseconfig (1.1.2)
359-
parser (3.3.10.2)
365+
parser (3.3.11.1)
360366
ast (~> 2.4.1)
361367
racc
362368
pony (1.13.1)
@@ -409,7 +415,7 @@ GEM
409415
rexml (~> 3.2)
410416
redis (5.4.1)
411417
redis-client (>= 0.22.0)
412-
redis-client (0.27.0)
418+
redis-client (0.28.0)
413419
connection_pool
414420
redis-rack-cache (2.2.1)
415421
rack-cache (>= 1.10, < 2)
@@ -435,19 +441,18 @@ GEM
435441
rsolr (2.6.0)
436442
builder (>= 2.1.2)
437443
faraday (>= 0.9, < 3, != 2.0.0)
438-
rubocop (1.85.1)
444+
rubocop (1.86.0)
439445
json (~> 2.3)
440446
language_server-protocol (~> 3.17.0.2)
441447
lint_roller (~> 1.1.0)
442-
mcp (~> 0.6)
443448
parallel (~> 1.10)
444449
parser (>= 3.3.0.2)
445450
rainbow (>= 2.2.2, < 4.0)
446451
regexp_parser (>= 2.9.3, < 3.0)
447452
rubocop-ast (>= 1.49.0, < 2.0)
448453
ruby-progressbar (~> 1.7)
449454
unicode-display_width (>= 2.4.0, < 4.0)
450-
rubocop-ast (1.49.0)
455+
rubocop-ast (1.49.1)
451456
parser (>= 3.3.7.2)
452457
prism (~> 1.7)
453458
ruby-progressbar (1.13.0)
@@ -460,6 +465,12 @@ GEM
460465
sentry-ruby (5.28.1)
461466
bigdecimal
462467
concurrent-ruby (~> 1.0, >= 1.0.2)
468+
sidekiq (7.3.9)
469+
base64
470+
connection_pool (>= 2.3.0)
471+
logger
472+
rack (>= 2.2.4)
473+
redis-client (>= 0.22.2)
463474
signet (0.21.0)
464475
addressable (~> 2.8)
465476
faraday (>= 0.17.5, < 3.a)
@@ -510,15 +521,17 @@ GEM
510521
uri (1.1.1)
511522
uuid (2.3.9)
512523
macaddr (~> 1.0)
513-
webmock (3.26.1)
524+
webmock (3.26.2)
514525
addressable (>= 2.8.0)
515526
crack (>= 0.3.2)
516527
hashdiff (>= 0.4.0, < 2.0.0)
517528
webrick (1.9.2)
518529

519530
PLATFORMS
531+
aarch64-linux
520532
arm64-darwin
521533
ruby
534+
x86-linux
522535
x86_64-darwin
523536
x86_64-linux
524537

@@ -575,6 +588,7 @@ DEPENDENCIES
575588
rubocop
576589
sentry-ruby (~> 5.24)
577590
shotgun!
591+
sidekiq (= 7.3.9)
578592
simplecov
579593
simplecov-cobertura
580594
sinatra
@@ -586,4 +600,4 @@ DEPENDENCIES
586600
webrick
587601

588602
BUNDLED WITH
589-
2.6.7
603+
2.6.9

app.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
require_relative 'lib/rack/slice_detection'
3030
require_relative 'lib/rack/request_lang'
3131

32+
# sidekiq requirements
33+
require 'sidekiq/web'
34+
require 'sidekiq'
35+
3236
# Logging setup
3337
require_relative 'config/logging'
3438

bin/ontoportal

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ build_docker_run_cmd() {
9696
local ncbo_path="$5"
9797

9898
local docker_run_cmd="docker compose --profile vo -p ontoportal_docker run --rm -it --name api-service"
99+
local sidekiq_run_cmd="docker compose --profile vo -p ontoportal_docker run --rm -d --name sidekiq-service"
99100
local bash_cmd=""
101+
local sidekiq_bash_cmd=""
100102

101103
# Conditionally add bind mounts only if the paths are not empty
102104
for path_var in "linked_data_path:ontologies_linked_data" "goo_path:goo" "sparql_client_path:sparql-client" "ncbo_path:ncbo_cron" ; do
@@ -107,15 +109,30 @@ build_docker_run_cmd() {
107109
echo "[+] Run: bundle config local.$value ${!path}"
108110
container_path="/srv/ontoportal/$value"
109111
docker_run_cmd+=" -v $host_path:$container_path"
112+
sidekiq_run_cmd+=" -v $host_path:$container_path"
110113
bash_cmd+="(git config --global --add safe.directory $container_path && bundle config local.$value $container_path) &&"
114+
sidekiq_bash_cmd+="(git config --global --add safe.directory $container_path && bundle config local.$value $container_path) &&"
111115
else
112116
bash_cmd+=" (bundle config unset local.$value) &&"
117+
sidekiq_bash_cmd+=" (bundle config unset local.$value) &&"
113118
fi
114119
done
115120

121+
# Build sidekiq command with same bundle setup
122+
local sidekiq_custom_command="bundle exec sidekiq -C /srv/ontoportal/ontologies_api/config/sidekiq.yml -r /srv/ontoportal/ontologies_api/app.rb --env=development"
123+
sidekiq_bash_cmd+=" (bundle check || bundle install || bundle update) && $sidekiq_custom_command"
124+
sidekiq_run_cmd+=" sidekiq bash -c \"$sidekiq_bash_cmd\""
125+
126+
# Start sidekiq detached first
127+
echo "[+] Starting Sidekiq in detached mode..."
128+
echo "[+] Run docker command $sidekiq_run_cmd"
129+
eval "$sidekiq_run_cmd"
130+
131+
# Build and run API command
116132
bash_cmd+=" (bundle check || bundle install || bundle update) && $custom_command"
117133
docker_run_cmd+=" --service-ports api bash -c \"$bash_cmd\""
118134

135+
echo "[+] Starting API server..."
119136
echo "[+] Run docker command $docker_run_cmd"
120137
eval "$docker_run_cmd"
121138
}

config.ru

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
require './app.rb'
22
run Sinatra::Application
3+
4+
map '/sidekiq' do
5+
run Sidekiq::Web
6+
end

config/sidekiq.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
:concurrency: 5
2+
3+
:queues:
4+
- default
5+
- mailers
6+
- critical
7+
8+
#:timeout: 25
9+
10+
:verbose: true
11+
12+
:logfile: ./log/sidekiq.log
13+
14+
:pidfile: ./tmp/pids/sidekiq.pid

docker-compose.yml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
x-app: &app
22
image: agroportal/ontologies_api:development
3-
environment: &env
3+
environment:
44
# default bundle config resolves to /usr/local/bundle/config inside of the container
55
# we are setting it to local app directory if we need to use 'bundle config local'
6-
BUNDLE_PATH: /srv/ontoportal/bundle
6+
7+
# BUNDLE_PATH: /srv/ontoportal/bundle
8+
&env
79
COVERAGE: 'true' # enable simplecov code coverage
810
REDIS_HOST: redis-ut
911
REDIS_PORT: 6379
@@ -27,13 +29,10 @@ x-app: &app
2729
tty: true
2830
command: /bin/bash
2931

30-
31-
3232
services:
3333
api:
3434
<<: *app
35-
env_file:
36-
.env
35+
env_file: .env
3736
environment:
3837
<<: *env
3938
BUNDLE_APP_CONFIG: /srv/ontoportal/ontologies_api/.bundle
@@ -53,15 +52,28 @@ services:
5352
- "9393:9393"
5453
volumes:
5554
# bundle volume for hosting gems installed by bundle; it speeds up gem install in local development
55+
- bundle:/srv/ontoportal/bundle
5656
- app_api:/srv/ontoportal/ontologies_api
5757
- repository:/srv/ontoportal/data/repository
58-
- bundle:/srv/ontoportal/bundle
58+
59+
sidekiq:
60+
<<: *app
61+
env_file: .env
62+
environment:
63+
<<: *env
64+
BUNDLE_APP_CONFIG: /srv/ontoportal/ontologies_api/.bundle
65+
66+
volumes:
67+
- app_api:/srv/ontoportal/ontologies_api
68+
- repository:/srv/ontoportal/data/repository
69+
depends_on:
70+
redis-ut:
71+
condition: service_healthy
5972

6073
ncbo_cron:
6174
<<: *app
6275
image: agroportal/ncbo_cron:development
63-
env_file:
64-
.env
76+
env_file: .env
6577
environment:
6678
<<: *env
6779
BUNDLE_APP_CONFIG: /srv/ontoportal/ncbo_cron/.bundle
@@ -84,7 +96,6 @@ services:
8496
virtuoso-ut:
8597
condition: service_started
8698

87-
8899
mgrep-ut:
89100
image: ontoportal/mgrep-ncbo:0.1
90101
ports:
@@ -141,11 +152,7 @@ services:
141152
- agdata:/agraph/data
142153
# - ./agraph/etc:/agraph/etc
143154
command: >
144-
bash -c "/agraph/bin/agraph-control --config /agraph/etc/agraph.cfg start
145-
; agtool repos create ontoportal_test --supersede
146-
; agtool users add anonymous
147-
; agtool users grant anonymous root:ontoportal_test:rw
148-
; tail -f /agraph/data/agraph.log"
155+
bash -c "/agraph/bin/agraph-control --config /agraph/etc/agraph.cfg start ; agtool repos create ontoportal_test --supersede ; agtool users add anonymous ; agtool users grant anonymous root:ontoportal_test:rw ; tail -f /agraph/data/agraph.log"
149156
# healthcheck:
150157
# test: ["CMD-SHELL", "curl -sf http://127.0.0.1:10035/repositories/ontoportal_test/status | grep -iqE '(^running|^lingering)' || exit 1"]
151158
# start_period: 10s
@@ -191,6 +198,7 @@ services:
191198
- gb
192199

193200
volumes:
201+
bundle:
194202
app_api:
195203
app_cron:
196204
agdata:
@@ -201,4 +209,3 @@ volumes:
201209
mgrep:
202210
logs:
203211
history:
204-
bundle:

0 commit comments

Comments
 (0)