Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Xbus emitter
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo modules
Xbus emitter
Commits
6c7a824b
Commit
6c7a824b
authored
10 years ago
by
Houzefa Abbasbhay
Browse files
Options
Downloads
Patches
Plain Diff
Function to send data to xbus
parent
5e93b291
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
model/xbus_emitter.py
+47
-0
47 additions, 0 deletions
model/xbus_emitter.py
with
47 additions
and
0 deletions
model/xbus_emitter.py
+
47
−
0
View file @
6c7a824b
import
logging
from
openerp
import
api
from
openerp
import
fields
from
openerp
import
models
...
...
@@ -1,6 +2,10 @@
from
openerp
import
api
from
openerp
import
fields
from
openerp
import
models
from
zmq_rpc
import
ZmqRpcClient
log
=
logging
.
getLogger
(
__name__
)
class
xbus_emitter
(
models
.
Model
):
...
...
@@ -45,3 +50,45 @@
@api.one
def
name_get
(
self
):
return
self
.
id
,
'
%s@%s
'
%
(
self
.
login
,
self
.
front_url
)
@api.one
def
send_items
(
self
,
event_type
,
items
):
"""
Send the data to Xbus, inside one event with the specified event
type.
:param event_type: Name of an Xbus event type.
:type event_type: String.
:type items: Iterable.
:return: The result of an
"
end_event
"
Xbus API call.
"""
# TODO Better handle failures (exceptions / timeouts).
log
.
debug
(
'
Establishing RPC connection...
'
)
conn
=
ZmqRpcClient
(
self
.
front_url
)
log
.
debug
(
'
RPC connection OK
'
)
token
=
conn
.
login
(
self
.
login
,
self
.
password
)
log
.
debug
(
'
Got connection token: %s
'
,
token
)
envelope_id
=
conn
.
start_envelope
(
token
)
log
.
debug
(
'
Envelope created: %s
'
,
envelope_id
)
event_id
=
conn
.
start_event
(
token
,
envelope_id
,
event_type
,
0
)
log
.
debug
(
'
Event created: %s
'
,
event_id
)
for
item
in
items
:
conn
.
send_item
(
token
,
envelope_id
,
event_id
,
item
)
log
.
debug
(
'
Data sent (event ID: %s)
'
,
event_id
)
ret
=
conn
.
end_event
(
token
,
envelope_id
,
event_id
)
log
.
debug
(
'
Event %s done: return value: %s
'
,
event_id
,
ret
)
conn
.
end_envelope
(
token
,
envelope_id
)
log
.
debug
(
'
Envelope %s closed
'
,
envelope_id
)
conn
.
logout
(
token
)
log
.
debug
(
'
Logged out; terminating
'
)
conn
.
close
()
log
.
debug
(
'
Done.
'
)
return
ret
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