Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
rabotnik
rcom
Commits
26508019
Commit
26508019
authored
Apr 25, 2022
by
Felix Delattre
Browse files
Introduced delay argument
parent
e171529f
Pipeline
#41970
passed with stage
in 2 minutes and 59 seconds
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
rcom/arguments/building_id.py
View file @
26508019
...
...
@@ -16,9 +16,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
from
..argument_base
import
ArgumentBase
import
asyncio
import
logging
from
..argument_base
import
ArgumentBase
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -29,11 +31,12 @@ class ArgumentBuildingId(ArgumentBase):
self
.
payload_argument
=
"building_id"
self
.
help_text
=
"Single `building_id` as integer"
async
def
execute
(
self
,
message_bus
,
argument
,
value
):
async
def
execute
(
self
,
message_bus
,
argument
,
value
,
delay
):
logger
.
info
(
"Dispatching `%s` with `%s` on `%s`."
,
argument
,
value
,
self
.
rabotnik_message
)
if
delay
:
await
asyncio
.
sleep
(
delay
/
100
)
await
message_bus
.
send
(
message
=
self
.
rabotnik_message
,
payload
=
{
self
.
payload_argument
:
value
}
)
rcom/arguments/building_ids_file.py
View file @
26508019
...
...
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import
asyncio
import
logging
from
..argument_base
import
ArgumentBase
...
...
@@ -30,7 +31,7 @@ class ArgumentBuildingIdsFile(ArgumentBase):
self
.
payload_argument
=
"building_id"
self
.
help_text
=
"File with many `building_id` in every new line"
async
def
execute
(
self
,
message_bus
,
argument
,
filename
):
async
def
execute
(
self
,
message_bus
,
argument
,
filename
,
delay
):
with
open
(
filename
)
as
f
:
for
line
in
f
:
...
...
@@ -45,3 +46,5 @@ class ArgumentBuildingIdsFile(ArgumentBase):
await
message_bus
.
send
(
message
=
self
.
rabotnik_message
,
payload
=
{
self
.
payload_argument
:
value
}
)
if
delay
:
await
asyncio
.
sleep
(
delay
/
100
)
rcom/rcom.py
View file @
26508019
...
...
@@ -55,6 +55,11 @@ class RCOM:
async
def
execute
(
self
,
args
):
await
self
.
ensure_message_bus_connected
()
if
"delay"
in
args
:
delay
=
args
[
"delay"
]
else
:
delay
=
False
# Find the argument to be put on the message bus
for
key
,
value
in
args
.
items
():
if
value
is
not
None
and
key
in
self
.
arguments
.
arguments
:
...
...
@@ -62,7 +67,7 @@ class RCOM:
rabotnik_value
=
value
await
self
.
arguments
.
arguments
[
rabotnik_argument
].
execute
(
self
.
message_bus
,
rabotnik_argument
,
rabotnik_value
self
.
message_bus
,
rabotnik_argument
,
rabotnik_value
,
delay
)
async
def
ensure_message_bus_connected
(
self
):
...
...
@@ -111,6 +116,12 @@ def main(args: list = None, message_bus: MessageBus = None):
default
=
None
,
help
=
"Connection timeout (optional)"
,
)
group
.
add_argument
(
"--delay"
,
type
=
int
,
default
=
None
,
help
=
"Delay for setting items on the bus (optional)"
,
)
parser
.
add_argument
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
help
=
"verbose mode"
,
dest
=
"verbose"
)
...
...
Write
Preview
Supports
Markdown
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