dialog_ruby 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Dockerfile +13 -0
- data/{lib/storage/redis → _dev}/redisPubSub.rb +1 -1
- data/background/_init.rb +43 -0
- data/background/batch.rb +69 -0
- data/background/redis.rb +34 -0
- data/dialog_ruby.gemspec +6 -7
- data/exec/conf/redis_global.conf +4 -2
- data/exec/dialog.sh +28 -26
- data/exec/git_sync/dialog__sync.service +1 -1
- data/exec/prereq.sh +18 -1
- data/exec/systemd/dialog_background.service +29 -0
- data/exec/systemd/dialog_redis.service +1 -1
- data/exec/systemd/dialog_runMode@.service +16 -6
- data/exec/systemd/dialog_runner@.path +8 -0
- data/lib/{triggers/start → begin}/_main.rb +29 -21
- data/lib/begin/_pre_bot.rb +58 -0
- data/lib/begin/background.rb +24 -0
- data/lib/{triggers/start → begin}/bot.rb +27 -6
- data/lib/{triggers/start → begin}/tdlib.rb +12 -16
- data/lib/configuration.rb +39 -27
- data/lib/dialect/canvas/element/send/Inline_query_result.rb +2 -0
- data/lib/dialect/canvas/element/send/background.rb +28 -0
- data/lib/dialect/canvas/element/send/recognize.rb +3 -2
- data/lib/dialect/canvas/element/send/restrict.rb +0 -1
- data/lib/dialect/canvas/element/send/tdlib_chat.rb +1 -1
- data/lib/dialect/canvas/element/send/tdlib_message.rb +1 -1
- data/lib/dialect/codegen/codegen.rb +9 -9
- data/lib/dialect/codegen/erb/functional/2.2.1.Events2ModReceive.erb +27 -4
- data/lib/dialect/codegen/erb/functional/4.1.AppEvent2Elements.erb +7 -2
- data/lib/dialect/codegen/erb/functional/5.1.Element2ModElements.erb +1 -1
- data/lib/dialect/codegen/erb/functional/7.ElementChains.erb +7 -6
- data/lib/dialog_ruby.rb +5 -2
- data/lib/metamess/_run.rb +1 -0
- data/lib/metamess/content/content_o-contact_f.rb +41 -0
- data/lib/metamess/content/content_o.rb +7 -6
- data/lib/metamess/func.rb +0 -24
- data/lib/metamess/naming.rb +8 -5
- data/lib/metamess/service/service_o-inline_f.rb +4 -3
- data/lib/require.rb +21 -2
- data/lib/statistics/func.rb +72 -0
- data/lib/statistics/general.rb +44 -0
- data/lib/statistics/redisDump.rb +49 -0
- data/lib/storage/redis/cached/pullpush.rb +76 -0
- data/lib/storage/redis/cached/pushPreproc.rb +41 -0
- data/lib/storage/redis/func.rb +47 -0
- data/lib/storage/redis/stat/push.rb +33 -0
- data/lib/tdlib/auth.rb +8 -7
- data/lib/tdlib/init.rb +5 -5
- data/lib/telegram/botapi.rb +2 -1
- data/lib/telegram/wrappers.rb +1 -2
- data/lib/tooling/log.rb +0 -1
- data/lib/tooling/strings.rb +12 -0
- data/lib/triggers/_func.rb +39 -0
- data/lib/triggers/{_meta/full.rb → console_start.rb} +8 -5
- data/lib/triggers/deploy.rb +104 -0
- data/lib/triggers/false.rb +8 -6
- data/lib/triggers/init.rb +23 -10
- data/lib/triggers/systemd_start.rb +24 -0
- data/lib/version.rb +1 -1
- metadata +83 -41
- data/_dev/sidekiq.rb +0 -28
- data/exec/systemd/_fix/dialog_bot@.path +0 -6
- data/exec/systemd/_fix/dialog_bot_dev@.path +0 -6
- data/exec/systemd/_fix/dialog_bot_dev_pre@.service +0 -16
- data/lib/storage/redis/rediscached.rb +0 -97
- data/lib/triggers/deploy/deploy.rb +0 -78
- data/lib/triggers/start/_pre_bot.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edf13cf660e814e5a448bea845d6078bee8a9ea15c8b5e89b432f5f56b616f07
|
4
|
+
data.tar.gz: 27414e8dfb0d6eba3282a2f695b12643d8b107ee84d1138f4cdb798291133939
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 938c3e4a721e3b939bda7db593602462325773d2100270c4418d8162b353df88b7d1d63bfde4872fcd15a32fc5da33eed8a5148bd3fbd6efebd24646726cb4a3
|
7
|
+
data.tar.gz: 27aa3098126b9ec3046be95869992bedb04581ca2a915bf4cc8092894807fe843fdacbc3358a4ab0f52f8d679155e5109abc9c589702444b00a7b105a8f0ae85
|
data/Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
FROM opensuse:leap
|
2
|
+
LABEL maintainer="Eugene Istomin <e.istomin@innosense.org>"
|
3
|
+
|
4
|
+
RUN zypper ar -cf http://download.opensuse.org/repositories/openSUSE:/Leap:/15.0/standard standard::leap15.0
|
5
|
+
RUN zypper ar -cf http://download.opensuse.org/update/leap/15.0/oss update_oss::leap15.0
|
6
|
+
RUN zypper ar -cf http://download.opensuse.org/update/openSUSE-stable update_oss::stable
|
7
|
+
|
8
|
+
RUN zypper --gpg-auto-import-keys --non-interactive in --replacefiles -f ruby2.5-devel ruby2.5-rubygem-sqlite3
|
9
|
+
RUN gem specific_install -u -l https://gitlab.com/Innosense/MVP/dialog_ruby.git
|
10
|
+
|
11
|
+
ENTRYPOINT ["/bin/echo"]
|
12
|
+
CMD ["hi"]
|
13
|
+
|
@@ -33,7 +33,7 @@ module Dialog
|
|
33
33
|
def subGetUnsub(args,redisChannelPrefix,redisSubTimeout)
|
34
34
|
args[:x][:redis][:redisChannelpostfix].nil? ? args[:x][:redis][:redisChannelpostfix] = "" : true
|
35
35
|
redisChannel = "#{redisChannelPrefix}__#{args[:x][:redis][:subPostfix]}_#{args[:x][:redis][:redisChannelpostfix]}"
|
36
|
-
redis ||=
|
36
|
+
#redis ||= Redis.new
|
37
37
|
redis.subscribe_with_timeout(redisSubTimeout, redisChannel) do |on, subscriptions|
|
38
38
|
Dialog.logger.debug "Subscribed to #{redisChannel} (#{subscriptions} subscriptions)"
|
39
39
|
on.message do |channel, msg|
|
data/background/_init.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
######## ####### ######## ####### ######## ########
|
2
|
+
## / / / / License \ \ \ \
|
3
|
+
## Copyleft culture, Copyright (C) is prohibited here
|
4
|
+
## This work is licensed under a CC BY-SA 4.0
|
5
|
+
## Creative Commons Attribution-ShareAlike 4.0 License
|
6
|
+
## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
|
7
|
+
######## ####### ######## ####### ######## ########
|
8
|
+
## / / / / Code Climate \ \ \ \
|
9
|
+
## Language = ruby
|
10
|
+
## Indent = space; 2 chars;
|
11
|
+
######## ####### ######## ####### ######## ########
|
12
|
+
|
13
|
+
module Dialog
|
14
|
+
module Background
|
15
|
+
class << self
|
16
|
+
|
17
|
+
require 'active_support/time'
|
18
|
+
require 'drb'
|
19
|
+
require_relative './../lib/require.rb'
|
20
|
+
Dialog._require_min
|
21
|
+
Dialog._require_background
|
22
|
+
Dir.glob(File.join("#{File.dirname(__FILE__)}/../lib/**", "*.rb")).each{|f| require f}
|
23
|
+
|
24
|
+
Sidekiq.configure_server do |config|
|
25
|
+
config.redis = { path: Dialog.config.db.redis_url, db: Dialog.config.db.redisDBBackground }
|
26
|
+
config.average_scheduled_poll_interval = 5 ## DEV
|
27
|
+
end
|
28
|
+
|
29
|
+
Sidekiq.configure_client do |config|
|
30
|
+
config.redis = { path: Dialog.config.db.redis_url, db: Dialog.config.db.redisDBBackground }
|
31
|
+
end
|
32
|
+
|
33
|
+
## DEV
|
34
|
+
rs = Sidekiq::RetrySet.new
|
35
|
+
rs.size
|
36
|
+
rs.clear
|
37
|
+
##
|
38
|
+
|
39
|
+
Dir.glob(File.join("#{File.dirname(__FILE__)}/**", "*.rb")).each{|f| require f}
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/background/batch.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
######## ####### ######## ####### ######## ########
|
2
|
+
## / / / / License \ \ \ \
|
3
|
+
## Copyleft culture, Copyright (C) is prohibited here
|
4
|
+
## This work is licensed under a CC BY-SA 4.0
|
5
|
+
## Creative Commons Attribution-ShareAlike 4.0 License
|
6
|
+
## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
|
7
|
+
######## ####### ######## ####### ######## ########
|
8
|
+
## / / / / Code Climate \ \ \ \
|
9
|
+
## Language = ruby
|
10
|
+
## Indent = space; 2 chars;
|
11
|
+
######## ####### ######## ####### ######## ########
|
12
|
+
|
13
|
+
module Dialog
|
14
|
+
module Background
|
15
|
+
|
16
|
+
class BotApi
|
17
|
+
include Sidekiq::Worker
|
18
|
+
include Sidekiq::Status::Worker
|
19
|
+
sidekiq_options queue: 'default'
|
20
|
+
|
21
|
+
def perform(instance,args)
|
22
|
+
batch = Sidekiq::Batch.new
|
23
|
+
batch.on(:success, 'Dialog::Background::Callback#success')
|
24
|
+
batch.on(:complete,'Dialog::Background::Callback#complete')
|
25
|
+
|
26
|
+
batch.jobs do
|
27
|
+
BotApiSend.perform_in(5.seconds.from_now,instance,args.to_h)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
class Callback
|
35
|
+
include Sidekiq::Worker
|
36
|
+
include Sidekiq::Status::Worker
|
37
|
+
sidekiq_options queue: 'default'
|
38
|
+
|
39
|
+
def success(status, options)
|
40
|
+
puts "You called a callback 'success', status: #{status}, options: #{options}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def complete(status, options)
|
44
|
+
puts "You called a callback 'complete', status: #{status}, options: #{options}"
|
45
|
+
#if status.failures != 0
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
class BotApiSend
|
52
|
+
include Sidekiq::Worker
|
53
|
+
include Sidekiq::Status::Worker
|
54
|
+
sidekiq_options queue: 'default'
|
55
|
+
|
56
|
+
def perform(instance, mmsg)
|
57
|
+
bot = DRbObject.new_with_uri("drbunix:./_data/bot/#{instance}/drb.sock")
|
58
|
+
puts "instance: #{instance}, mmsg: #{mmsg}"
|
59
|
+
smsg = {}
|
60
|
+
pp bot.api.send(:getMe)
|
61
|
+
chatId = mmsg["fqndata"]["o"]["chat"]["id"]
|
62
|
+
pp bot.api.send(:sendMessage, {'chat_id' => chatId, 'text' => "This is the background proc, man: reply to you message from '#{DateTime.strptime(mmsg["fqndata"]["o"]["msg"]["date"].to_s, '%s')}'"})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
data/background/redis.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
######## ####### ######## ####### ######## ########
|
2
|
+
## / / / / License \ \ \ \
|
3
|
+
## Copyleft culture, Copyright (C) is prohibited here
|
4
|
+
## This work is licensed under a CC BY-SA 4.0
|
5
|
+
## Creative Commons Attribution-ShareAlike 4.0 License
|
6
|
+
## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
|
7
|
+
######## ####### ######## ####### ######## ########
|
8
|
+
## / / / / Code Climate \ \ \ \
|
9
|
+
## Language = ruby
|
10
|
+
## Indent = space; 2 chars;
|
11
|
+
######## ####### ######## ####### ######## ########
|
12
|
+
|
13
|
+
module Dialog
|
14
|
+
module Background
|
15
|
+
class << self
|
16
|
+
|
17
|
+
Sidekiq::Cron::Job.create(name: 'RedisDumper - every 1 min', cron: '*/1 * * * *', class: 'Dialog::Background::RedisDumper')
|
18
|
+
pp Sidekiq::Cron::Job.all
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class RedisDumper
|
23
|
+
include Sidekiq::Worker
|
24
|
+
include Sidekiq::Status::Worker
|
25
|
+
sidekiq_options queue: 'default'
|
26
|
+
|
27
|
+
def perform
|
28
|
+
puts Dialog::Statistics.redisDump2json
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/dialog_ruby.gemspec
CHANGED
@@ -20,21 +20,20 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
s.require_paths = ['lib'.freeze]
|
22
22
|
|
23
|
-
#Innosense
|
24
|
-
s.add_runtime_dependency 'dialect_lookup', '~> 0.0.4'
|
25
|
-
s.add_runtime_dependency 'dialog_bot_ruby', '~> 0.8.7'
|
26
|
-
|
27
|
-
|
28
23
|
#External
|
29
24
|
s.add_runtime_dependency 'tdlib-ruby', '~> 1.0'
|
25
|
+
s.add_runtime_dependency 'activesupport', '~> 5.2'
|
30
26
|
s.add_runtime_dependency 'i18n', '~> 1.1'
|
31
27
|
s.add_runtime_dependency 'redis', '~> 4.0'
|
32
|
-
s.add_runtime_dependency 'concurrent-ruby', '~> 1.0
|
28
|
+
s.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
33
29
|
s.add_runtime_dependency 'oj', '~> 3.6'
|
34
|
-
s.add_runtime_dependency 'sidekiq-cron', '~> 1.0'
|
35
30
|
s.add_runtime_dependency 'sidekiq', '~> 5.2'
|
31
|
+
s.add_runtime_dependency 'sidekiq-batch', '~> 0.1'
|
32
|
+
s.add_runtime_dependency 'sidekiq-status', '~> 1.1'
|
33
|
+
s.add_runtime_dependency 'sidekiq-cron', '~> 1.0'
|
36
34
|
s.add_runtime_dependency 'sidekiq-rate-limiter', '~> 0.1'
|
37
35
|
s.add_runtime_dependency 'dry-configurable', '~> 0.7'
|
36
|
+
s.add_runtime_dependency 'redis-dump', '~> 0.4'
|
38
37
|
|
39
38
|
end
|
40
39
|
|
data/exec/conf/redis_global.conf
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
daemonize no
|
2
|
-
port
|
2
|
+
port 4000
|
3
3
|
unixsocketperm 700
|
4
4
|
loglevel notice
|
5
5
|
syslog-enabled yes
|
6
6
|
syslog-facility local1
|
7
|
-
databases
|
7
|
+
databases 4
|
8
8
|
save 600 1
|
9
9
|
save 300 5
|
10
10
|
save 180 10
|
11
11
|
save 60 50
|
12
12
|
save 10 100
|
13
13
|
|
14
|
+
maxmemory-policy noeviction
|
15
|
+
|
14
16
|
stop-writes-on-bgsave-error yes
|
15
17
|
rdbcompression yes
|
16
18
|
rdbchecksum yes
|
data/exec/dialog.sh
CHANGED
@@ -15,38 +15,40 @@ set -e
|
|
15
15
|
## PRE - ENV ##
|
16
16
|
# . ./engine/exec.sh
|
17
17
|
|
18
|
-
if [[ -z $
|
19
|
-
DialogMsg="Please specify
|
20
|
-
echo $DialogMsg; select
|
18
|
+
if [[ -z $runInstance ]]; then
|
19
|
+
DialogMsg="Please specify instance"
|
20
|
+
echo $DialogMsg; select runInstance in `ls ./_env/*|grep -v tmpl|sed -e 's/.*.\///'`; do break ; done
|
21
|
+
runMode=`echo $runInstance|cut -d '.' -f 2`
|
22
|
+
runInstance=`echo $runInstance|cut -d '.' -f 1`
|
21
23
|
fi
|
22
24
|
|
23
|
-
if [[ -z $
|
24
|
-
DialogMsg="Please specify
|
25
|
-
echo $DialogMsg; select
|
25
|
+
if [[ -z $runScope ]]; then
|
26
|
+
DialogMsg="Please specify scope"
|
27
|
+
echo $DialogMsg; select runScope in init systemd_start console_start; do break ; done
|
28
|
+
showCommand=1
|
26
29
|
fi
|
27
30
|
|
28
|
-
case $
|
29
|
-
'
|
31
|
+
case $runScope in
|
32
|
+
'console_start')
|
33
|
+
runModes="bot tdlib check dialect"
|
30
34
|
;;
|
35
|
+
*)
|
36
|
+
runModes="bot tdlib bot_dev"
|
37
|
+
;;
|
38
|
+
esac
|
31
39
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
echo $DialogMsg; select runScope in init start stop; do break ; done
|
37
|
-
fi
|
38
|
-
|
39
|
-
if [[ -z $runMode ]]; then
|
40
|
-
DialogMsg="Please specify mode: "
|
41
|
-
echo $DialogMsg; select runMode in check bot dev dev_offline; do break ; done
|
42
|
-
fi
|
40
|
+
if [[ -z $runMode ]]; then
|
41
|
+
DialogMsg="Please specify mode: "
|
42
|
+
echo $DialogMsg; select runMode in $runModes; do break ; done
|
43
|
+
fi
|
43
44
|
|
44
|
-
|
45
|
+
if [[ $showCommand == 1 ]]; then
|
46
|
+
GREEN='\033[0;32m'
|
47
|
+
NC='\033[0m' # No Color
|
48
|
+
runCommand="runInstance=$runInstance runScope=$runScope runMode=$runMode"
|
49
|
+
echo -e "Start using:\n${GREEN}$runCommand bash ./dialog.sh ${NC}"
|
50
|
+
else
|
51
|
+
export $(grep -v '^#' ./_env/$runInstance.* | xargs)
|
45
52
|
ruby ./dialog.rb
|
53
|
+
fi
|
46
54
|
|
47
|
-
;;
|
48
|
-
|
49
|
-
*)
|
50
|
-
echo 'Wrong run method!'
|
51
|
-
;;
|
52
|
-
esac
|
data/exec/prereq.sh
CHANGED
@@ -1,2 +1,19 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
######## ####### ######## ####### ######## ########
|
3
|
+
## / / / / License \ \ \ \
|
4
|
+
## Copyleft culture, Copyright (C) is prohibited here
|
5
|
+
## This work is licensed under a CC BY-SA 4.0
|
6
|
+
## Creative Commons Attribution-ShareAlike 4.0 License
|
7
|
+
## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
|
8
|
+
######## ####### ######## ####### ######## ########
|
9
|
+
## / / / / Code Climate \ \ \ \
|
10
|
+
## Language = bash
|
11
|
+
## Indent = space; 2 chars;
|
12
|
+
######## ####### ######## ####### ######## ########
|
13
|
+
set -e
|
14
|
+
|
1
15
|
zypper ar -cf https://download.opensuse.org/repositories/devel:/languages:/ruby:/extensions/openSUSE_Leap_15.0/devel:languages:ruby:extensions.repo
|
2
|
-
zypper
|
16
|
+
zypper ar -cf https://download.opensuse.org/repositories/devel:/languages:/ruby/openSUSE_Leap_15.0/devel:languages:ruby.repo
|
17
|
+
zypper --gpg-auto-import-keys --non-interactive up
|
18
|
+
zypper --gpg-auto-import-keys --non-interactive in jemalloc tdlib redis
|
19
|
+
zypper --gpg-auto-import-keys --non-interactive in ruby2.5-devel ruby2.5-rubygem-sqlite3 ruby2.5-rubygem-oj ruby2.5-rubygem-yajl-ruby
|
@@ -0,0 +1,29 @@
|
|
1
|
+
[Unit]
|
2
|
+
Description= Dialog background runner
|
3
|
+
After=syslog.target network.target
|
4
|
+
|
5
|
+
[Service]
|
6
|
+
Type=simple
|
7
|
+
WorkingDirectory=<%=Dialog.config.path.dialog%>
|
8
|
+
|
9
|
+
Environment=runScope=_run
|
10
|
+
Environment=runMode=background
|
11
|
+
|
12
|
+
# Greatly reduce Ruby memory fragmentation and heap usage
|
13
|
+
# https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
|
14
|
+
Environment=MALLOC_ARENA_MAX=2
|
15
|
+
# Use jemalloc
|
16
|
+
# https://brandonhilkert.com/blog/reducing-sidekiq-memory-usage-with-jemalloc/
|
17
|
+
Environment=LD_PRELOAD=/usr/lib64/libjemalloc.so.2
|
18
|
+
|
19
|
+
ExecStart=/usr/bin/ruby ./dialog.rb
|
20
|
+
|
21
|
+
RestartSec=5
|
22
|
+
TimeoutStopSec=5
|
23
|
+
Restart=on-failure
|
24
|
+
StandardOutput=syslog
|
25
|
+
StandardError=syslog
|
26
|
+
SyslogIdentifier=dialog_background
|
27
|
+
|
28
|
+
[Install]
|
29
|
+
WantedBy=default.target
|
@@ -1,3 +1,5 @@
|
|
1
|
+
<% erb.has_key?(:env) ? env = erb[:env] : env = erb[:mode]
|
2
|
+
%>
|
1
3
|
[Unit]
|
2
4
|
Description= Dialog (Telegram Bot abstraction layer) - instance %i
|
3
5
|
After=syslog.target network.target
|
@@ -5,22 +7,30 @@ After=syslog.target network.target
|
|
5
7
|
[Service]
|
6
8
|
Type=simple
|
7
9
|
WorkingDirectory=<%=Dialog.config.path.dialog%>
|
8
|
-
EnvironmentFile=<%=Dialog.config.path.dialog%>/_env/%i
|
9
|
-
Environment=runScope=
|
10
|
-
Environment=runMode=<%=mode%>
|
11
|
-
Environment=
|
10
|
+
EnvironmentFile=<%=Dialog.config.path.dialog%>/_env/%i.<%= env %>
|
11
|
+
Environment=runScope=_run
|
12
|
+
Environment=runMode=<%=erb[:mode]%>
|
13
|
+
Environment=runInstance=%i
|
12
14
|
|
13
15
|
# Greatly reduce Ruby memory fragmentation and heap usage
|
14
16
|
# https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
|
15
17
|
Environment=MALLOC_ARENA_MAX=2
|
18
|
+
# Use jemalloc
|
19
|
+
# https://brandonhilkert.com/blog/reducing-sidekiq-memory-usage-with-jemalloc/
|
20
|
+
Environment=LD_PRELOAD=/usr/lib64/libjemalloc.so.2
|
16
21
|
|
22
|
+
<% if erb.has_key?(:systemdChain)%>
|
23
|
+
ExecStartPre=/usr/bin/ruby ./dialog.rb
|
24
|
+
ExecStart=/usr/bin/systemctl --user restart <%=erb[:systemdChain]%>@%i
|
25
|
+
<% else %>
|
17
26
|
ExecStart=/usr/bin/ruby ./dialog.rb
|
27
|
+
<% end %>
|
18
28
|
RestartSec=5
|
19
29
|
TimeoutStopSec=5
|
20
30
|
Restart=on-failure
|
21
31
|
StandardOutput=syslog
|
22
32
|
StandardError=syslog
|
23
|
-
SyslogIdentifier=dialog_<%=mode%>_%i
|
33
|
+
SyslogIdentifier=dialog_<%=erb[:mode]%>_%i
|
24
34
|
|
25
35
|
[Install]
|
26
|
-
WantedBy=
|
36
|
+
WantedBy=default.target
|
@@ -13,9 +13,11 @@
|
|
13
13
|
module Dialog
|
14
14
|
class << self
|
15
15
|
|
16
|
-
def
|
16
|
+
def _run(mode=false)
|
17
17
|
args = {}
|
18
|
-
|
18
|
+
mode == false ? mode = Dialog.config.run.mode : true
|
19
|
+
Dialog.logger.debug "Using mode '#{mode}'"
|
20
|
+
case mode
|
19
21
|
when 'check'
|
20
22
|
_require
|
21
23
|
jsonDriven(args, :check)
|
@@ -23,31 +25,27 @@ module Dialog
|
|
23
25
|
_require
|
24
26
|
jsonDriven(args, :prod)
|
25
27
|
bot(args)
|
26
|
-
when '
|
27
|
-
_require
|
28
|
-
dialectDriven(args)
|
29
|
-
jsonDriven(args, :prod)
|
30
|
-
bot(args)
|
31
|
-
when 'dev_offline'
|
28
|
+
when 'dialect'
|
32
29
|
_require
|
33
30
|
dialectDriven(args)
|
34
31
|
jsonDriven(args, :check)
|
35
32
|
when 'tdlib'
|
36
33
|
start_tdlib(args)
|
34
|
+
when 'background'
|
35
|
+
start_background(args)
|
37
36
|
else
|
38
|
-
Dialog.logger.error "ERROR: no such mode - '#{
|
37
|
+
Dialog.logger.error "ERROR: no such mode - '#{mode}'"
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
|
-
|
43
41
|
|
44
42
|
def dialectDriven(args)
|
45
43
|
require 'dialect_lookup'
|
46
44
|
state = {
|
47
|
-
dialectFolder: Dialog.config.
|
45
|
+
dialectFolder: Dialog.config.naming.interface,
|
48
46
|
myAppName: Dialog.config.naming.app,
|
49
47
|
sqlite: Dialog.config.dialect.sqlite,
|
50
|
-
|
48
|
+
json: Dialog.config.dialect.json
|
51
49
|
}
|
52
50
|
::Dialect::Lookup.new.run(state)
|
53
51
|
# File.delete(Dialog.config.dialect.sqlite)
|
@@ -58,15 +56,25 @@ module Dialog
|
|
58
56
|
FileUtils.rm_rf(Dir.glob("#{Dialog.config.path.dialogRender}/code_#{type}/*.rb"))
|
59
57
|
args[:dialect] = {}
|
60
58
|
|
61
|
-
json =
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
59
|
+
json = Dialog.config.dialect.json
|
60
|
+
if File.file?(json)
|
61
|
+
jsonLoad = Oj.load(File.read(json), symbol_keys: true)
|
62
|
+
args[:dialect] = jsonLoad[:stages][Dialog.config.naming.interface.to_sym]
|
63
|
+
Dialog::Dialect.run(args, type)
|
64
|
+
|
65
|
+
args[:dialect] ={}
|
66
|
+
args[:tmp] = {}
|
67
|
+
Dir.glob(File.join("#{Dialog.config.path.dialogRender}/code_#{type}/**", "*.rb")).sort.each{|f| require f}
|
68
|
+
Dialog.logger.info "Rendered bot code is ok"
|
69
|
+
else
|
70
|
+
Dialog.logger.info "No JSON to render, trying to export"
|
71
|
+
begin
|
72
|
+
trigger_start('dialect')
|
73
|
+
rescue
|
74
|
+
Dialog.logger.error "Seems like no Dialect DB, exiting! Please upload valid JSON or use a valid Dialect DB"
|
75
|
+
exit(false)
|
76
|
+
end
|
77
|
+
end
|
70
78
|
end
|
71
79
|
|
72
80
|
|