Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
facebook
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
mautrix
facebook
Commits
8a58e655
Commit
8a58e655
authored
4 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Add option for periodic reconnects
parent
54fa5c95
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mautrix_facebook/__main__.py
+54
-2
54 additions, 2 deletions
mautrix_facebook/__main__.py
mautrix_facebook/config.py
+2
-1
2 additions, 1 deletion
mautrix_facebook/config.py
mautrix_facebook/example-config.yaml
+4
-1
4 additions, 1 deletion
mautrix_facebook/example-config.yaml
with
60 additions
and
4 deletions
mautrix_facebook/__main__.py
+
54
−
2
View file @
8a58e655
# mautrix-facebook - A Matrix-Facebook Messenger puppeting bridge
# Copyright (C) 20
19
Tulir Asokan
# Copyright (C) 20
20
Tulir Asokan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
...
...
@@ -13,7 +13,8 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from
itertools
import
chain
import
asyncio
import
logging
from
mautrix.bridge
import
Bridge
...
...
@@ -45,6 +46,8 @@ class MessengerBridge(Bridge):
config
:
Config
public_website
:
PublicBridgeWebsite
periodic_reconnect_task
:
asyncio
.
Task
def
prepare_bridge
(
self
)
->
None
:
init_db
(
self
.
db
)
context
=
Context
(
az
=
self
.
az
,
config
=
self
.
config
,
loop
=
self
.
loop
,
bridge
=
self
)
...
...
@@ -59,6 +62,7 @@ class MessengerBridge(Bridge):
self
.
az
.
app
.
add_subapp
(
self
.
config
[
"
appservice.public.prefix
"
],
self
.
public_website
.
app
)
def
prepare_shutdown
(
self
)
->
None
:
self
.
periodic_reconnect_task
.
cancel
()
self
.
log
.
debug
(
"
Stopping puppet syncers
"
)
for
puppet
in
Puppet
.
by_custom_mxid
.
values
():
puppet
.
stop
()
...
...
@@ -67,5 +71,53 @@ class MessengerBridge(Bridge):
user
.
stop_listening
()
user
.
save
()
async
def
start
(
self
)
->
None
:
await
super
().
start
()
self
.
periodic_reconnect_task
=
self
.
loop
.
create_task
(
self
.
_try_periodic_reconnect_loop
())
async
def
_try_periodic_reconnect_loop
(
self
)
->
None
:
try
:
await
self
.
_periodic_reconnect_loop
()
except
Exception
:
self
.
log
.
exception
(
"
Fatal error in periodic reconnect loop
"
)
async
def
_periodic_reconnect_loop
(
self
)
->
None
:
log
=
logging
.
getLogger
(
"
mau.periodic_reconnect
"
)
interval
=
self
.
config
[
"
bridge.periodic_reconnect_interval
"
]
if
interval
<=
0
:
log
.
debug
(
"
Periodic reconnection is not enabled
"
)
return
mode
=
self
.
config
[
"
bridge.periodic_reconnect_mode
"
].
lower
()
if
mode
!=
"
refresh
"
and
mode
!=
"
reconnect
"
:
log
.
error
(
"
Invalid periodic reconnect mode
'
%s
'"
,
mode
)
return
elif
interval
<
600
:
log
.
warning
(
"
Periodic reconnect interval is quite low (%d)
"
,
interval
)
log
.
debug
(
"
Starting periodic reconnect loop
"
)
while
True
:
try
:
await
asyncio
.
sleep
(
interval
)
except
asyncio
.
CancelledError
:
log
.
debug
(
"
Periodic reconnect loop stopped
"
)
return
log
.
info
(
"
Executing periodic reconnections
"
)
for
user
in
User
.
by_fbid
.
values
():
if
not
user
.
is_connected
:
log
.
debug
(
"
Not reconnecting %s: not connected
"
,
user
.
mxid
)
continue
log
.
debug
(
"
Executing periodic reconnect for %s
"
,
user
.
mxid
)
try
:
if
mode
==
"
refresh
"
:
await
user
.
refresh
()
elif
mode
==
"
reconnect
"
:
user
.
listener
.
disconnect
()
await
user
.
listen_task
user
.
listen_task
=
user
.
loop
.
create_task
(
user
.
try_listen
())
except
asyncio
.
CancelledError
:
log
.
debug
(
"
Periodic reconnect loop stopped
"
)
return
except
Exception
:
log
.
exception
(
"
Error while reconnecting
"
,
user
.
mxid
)
MessengerBridge
().
run
()
This diff is collapsed.
Click to expand it.
mautrix_facebook/config.py
+
2
−
1
View file @
8a58e655
...
...
@@ -64,7 +64,8 @@ class Config(BaseBridgeConfig):
copy
(
"
bridge.backfill.invite_own_puppet
"
)
copy
(
"
bridge.backfill.initial_limit
"
)
copy
(
"
bridge.backfill.missed_limit
"
)
copy
(
"
bridge.auto_reconnect_interval
"
)
copy
(
"
bridge.periodic_reconnect_interval
"
)
copy
(
"
bridge.periodic_reconnect_mode
"
)
copy
(
"
bridge.resync_max_disconnected_time
"
)
copy_dict
(
"
bridge.permissions
"
)
...
...
This diff is collapsed.
Click to expand it.
mautrix_facebook/example-config.yaml
+
4
−
1
View file @
8a58e655
...
...
@@ -138,7 +138,10 @@ bridge:
missed_limit
:
1000
# Interval in seconds in which to automatically reconnect all users.
# This can be used to automatically mitigate the bug where Facebook stops sending messages.
auto_reconnect_interval
:
-1
# Set to -1 to disable periodic reconnections entirely.
periodic_reconnect_interval
:
-1
# What to do in periodic reconnects. Either "refresh" or "reconnect"
periodic_reconnect_mode
:
refresh
# The number of seconds that a disconnection can last without triggering an automatic re-sync
# and missed message backfilling when reconnecting.
# Set to 0 to always re-sync, or -1 to never re-sync automatically.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment