Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
courier
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张宇
courier
Commits
f917b408
Commit
f917b408
authored
Feb 11, 2020
by
张宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[M]HuanXinClient singleton
parent
1b1f4ca5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
0 deletions
+12
-0
client.py
hx/client.py
+12
-0
No files found.
hx/client.py
View file @
f917b408
# -*- coding: utf-8 -*-
import
json
from
typing
import
Optional
from
threading
import
Lock
from
django.conf
import
settings
import
requests
...
...
@@ -39,6 +40,9 @@ def handle_huanxin_response_error(response: requests.models.Response, client=Non
return
result
_instance
=
None
_lock
=
Lock
()
class
HuanXinClient
(
object
):
BASE_URL
=
getattr
(
settings
,
'HX_BASE_URL'
,
None
)
ORG_NAME
=
getattr
(
settings
,
'HX_ORG_NAME'
,
None
)
...
...
@@ -54,6 +58,14 @@ class HuanXinClient(object):
'huanxin config error'
self
.
session
=
requests
.
Session
()
@staticmethod
def
__new__
(
cls
,
*
args
,
**
kwargs
):
global
_lock
,
_instance
_lock
.
acquire
()
_instance
=
_instance
or
super
(
HuanXinClient
,
cls
)
.
__new__
(
cls
)
_lock
.
release
()
return
_instance
def
_get_auth_token
(
self
):
GET_TOKEN_URL
=
'{base_url}/{org_name}/{app_name}/token'
.
format
(
base_url
=
self
.
BASE_URL
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment