forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_version.rb
63 lines (42 loc) · 1.5 KB
/
app_version.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class AppVersion
=begin
get current app version
version = AppVersion.get
returns
'20150212131700:0' # 'version:if_browser_reload_is_required'
=end
def self.get
Setting.get('app_version')
end
MSG_APP_VERSION = 'app_version'.freeze
MSG_RESTART_MANUAL = 'restart_manual'.freeze
MSG_RESTART_AUTO = 'restart_auto'.freeze
MSG_CONFIG_CHANGED = 'config_changed'.freeze
=begin
set new app version and if browser reload is required
AppVersion.set(true) # true == reload is required / false == no reload is required
send also reload type to clients
AppVersion.set(true, AppVersion::MSG_APP_VERSION) # -> new app version
AppVersion.set(true, AppVersion::MSG_RESTART_MANUAL) # -> app needs restart
AppVersion.set(true, AppVersion::MSG_RESTART_AUTO) # -> app is restarting
AppVersion.set(true, AppVersion::MSG_CONFIG_CHANGED) # -> config has changed
=end
def self.set(reload_required = false, type = MSG_APP_VERSION)
return false if !Setting.exists?(name: 'app_version')
version = "#{Time.zone.now.strftime('%Y%m%d%H%M%S')}:#{reload_required}"
Setting.set('app_version', version)
# broadcast to clients
Sessions.broadcast(event_data(type), 'public')
Gql::Subscriptions::AppMaintenance.trigger({ type: type })
end
def self.event_data(type = 'app_version')
{
event: 'maintenance',
data: {
type: type,
app_version: get,
}
}
end
end