Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
slack-ruby-bot-server/lib/slack-ruby-bot-server/service.rb at master · dblock/slack-ruby-bot-server · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
dblock
slack-ruby-bot-server
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
slack-ruby-bot-server
/
lib
/
slack-ruby-bot-server
/
service.rb
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
154 lines (134 loc) · 3.62 KB
master
Breadcrumbs
slack-ruby-bot-server
/
lib
/
slack-ruby-bot-server
/
service.rb
Copy path
Top
File metadata and controls
Code
Blame
154 lines (134 loc) · 3.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
module
SlackRubyBotServer
class
Service
include
SlackRubyBotServer
::
Loggable
def
self
.
start!
Thread
.
new
do
Thread
.
current
.
abort_on_exception
=
true
instance
.
start_from_database!
end
end
def
self
.
instance
@instance
||=
SlackRubyBotServer
::
Config
.
service_class
.
new
end
def
initialize
@callbacks
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
[
]
}
@intervals
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
[
]
}
end
def
on
(
*
types
,
&
block
)
Array
(
types
)
.
each
do
|
type
|
@callbacks
[
type
.
to_s
]
<<
block
end
end
def
once_and_every
(
*
intervals
,
&
block
)
Array
(
intervals
)
.
each
do
|
interval
|
@intervals
[
_validate_interval
(
interval
)
]
<<
[
block
,
{
run_on_start
:
true
}
]
end
end
def
every
(
*
intervals
,
&
block
)
Array
(
intervals
)
.
each
do
|
interval
|
@intervals
[
_validate_interval
(
interval
)
]
<<
[
block
,
{
}
]
end
end
def
create!
(
team
,
options
=
{
}
)
run_callbacks
:creating
,
team
,
nil
,
options
start!
(
team
)
run_callbacks
:created
,
team
,
nil
,
options
end
def
start!
(
team
)
logger
.
info
"Starting team
#{
team
}
."
run_callbacks
:starting
,
team
run_callbacks
:started
,
team
rescue
StandardError
=>
e
run_callbacks
:error
,
team
,
e
logger
.
error
e
end
def
restart!
(
team
)
logger
.
info
"Restarting team
#{
team
}
."
run_callbacks
:restarting
,
team
run_callbacks
:restarted
,
team
rescue
StandardError
=>
e
run_callbacks
:error
,
team
,
e
logger
.
error
e
end
def
stop!
(
team
)
logger
.
info
"Stopping team
#{
team
}
."
run_callbacks
:stopping
,
team
run_callbacks
:stopped
,
team
rescue
StandardError
=>
e
run_callbacks
:error
,
team
,
e
logger
.
error
e
end
def
start_from_database!
Team
.
active
.
each
do
|
team
|
run_callbacks
:booting
,
team
start!
(
team
)
run_callbacks
:booted
,
team
end
start_intervals!
end
def
start_intervals!
(
&
_block
)
::
Async
::
Reactor
.
run
do
|
task
|
@intervals
.
each_pair
do
|
period
,
calls_with_options
|
calls_with_options
.
each
do
|
call_with_options
|
call
,
options
=
*
call_with_options
_every
period
,
options
do
call
.
call
end
end
end
yield
task
if
block_given?
end
end
def
deactivate!
(
team
)
run_callbacks
:deactivating
,
team
team
.
deactivate!
run_callbacks
:deactivated
,
team
rescue
StandardError
=>
e
run_callbacks
:error
,
team
,
e
logger
.
error
"
#{
team
.
name
}
:
#{
e
.
class
}
,
#{
e
.
message
}
, ignored."
end
def
self
.
reset!
@instance
=
nil
end
private
def
_validate_interval
(
interval
)
case
interval
when
:minute
interval
=
60
when
:hour
interval
=
60
*
60
when
:day
interval
=
60
*
60
*
24
end
raise
"Invalid interval
\"
#{
interval
}
\"
."
unless
interval
.
is_a?
(
Integer
)
&&
interval
>
0
interval
end
def
_every
(
tt
,
options
=
{
}
,
&
_block
)
::
Async
::
Reactor
.
run
do
|
task
|
loop
do
begin
if
options
[
:run_on_start
]
options
=
{
}
yield
end
task
.
sleep
tt
yield
rescue
StandardError
=>
e
logger
.
error
e
end
end
end
end
def
run_callbacks
(
type
,
team
=
nil
,
error
=
nil
,
options
=
{
}
)
callbacks
=
@callbacks
[
type
.
to_s
]
return
false
unless
callbacks
callbacks
.
each
do
|
c
|
c
.
call
team
,
error
,
options
end
true
rescue
StandardError
=>
e
logger
.
error
e
false
end
end
end
You can’t perform that action at this time.