Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
workspaces
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ssa
workspaces
Commits
885441cd
Commit
885441cd
authored
4 years ago
by
Nathan Hertz
Browse files
Options
Downloads
Patches
Plain Diff
Added command-line arg support; started implementing send_event_data()
parent
59faedbf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/cli/utilities/wf_monitor/src/wf_monitor/monitor.py
+59
-2
59 additions, 2 deletions
apps/cli/utilities/wf_monitor/src/wf_monitor/monitor.py
with
59 additions
and
2 deletions
apps/cli/utilities/wf_monitor/src/wf_monitor/monitor.py
+
59
−
2
View file @
885441cd
...
...
@@ -4,6 +4,7 @@ import sys
import
time
import
signal
import
logging
import
argparse
import
subprocess
import
tracemalloc
from
typing
import
List
,
Union
,
Dict
...
...
@@ -11,8 +12,10 @@ from pathlib import Path
import
pika
import
pendulum
from
pycapo
import
CapoConfig
from
.wf_event
import
WorkflowEvent
,
EventType
from
._version
import
___version___
as
VERSION
WORKFLOW_STATUS_EXCH
:
str
=
'
workspaces.workflow-service.workflow-status
'
...
...
@@ -178,10 +181,64 @@ class WorkflowMonitor:
return
events
def
send_event_data
(
self
,
event_metadatum
:
str
):
def
send_event_data
(
self
,
connection
:
pika
.
BlockingConnection
,
event_metadatum
:
str
):
"""
Takes in a JSON-formatted string and sends it off to the workflow status exchange
:param event_metadatum: JSON string of event metadata
"""
# Send data to exchange
pass
\ No newline at end of file
channel
:
pika
.
channel
.
Channel
=
connection
.
channel
()
channel
.
exchange_declare
(
WORKFLOW_STATUS_EXCH
,
'
topic
'
,
durable
=
True
)
channel
.
basic_publish
(
exchange
=
WORKFLOW_STATUS_EXCH
,
# routing_key=?
)
_DESCRIPTION
=
'
Workspaces workflow monitor, version {}. Monitor execution of a workflow from
'
\
'
the command line.
'
def
make_arg_parser
()
->
argparse
.
ArgumentParser
:
"""
Initialize argument parser for command-line arguments
:return: Argument parser
"""
parser
:
argparse
.
ArgumentParser
=
argparse
.
ArgumentParser
(
description
=
_DESCRIPTION
.
format
(
VERSION
),
formatter_class
=
argparse
.
RawTextHelpFormatter
)
parser
.
add_argument
(
'
-P
'
,
'
--profile
'
,
action
=
'
store
'
,
required
=
True
,
help
=
'
profile name to use; e.g. test, production
'
)
parser
.
add_argument
(
'
log_path
'
,
action
=
'
store
'
,
required
=
True
,
help
=
'
path to the workflow
\'
s HTCondor log
'
)
return
parser
def
make_amqp_connection
(
profile
:
str
)
->
pika
.
BlockingConnection
:
"""
Initialize connection to AMQP server
:param profile: Capo profile to use
:return: Established connection
"""
capo_cfg
=
CapoConfig
(
profile
=
profile
)
hostname
:
str
=
capo_cfg
.
getstring
(
'
edu.nrao.archive.configuration.AmqpServer.hostname
'
)
username
:
str
=
capo_cfg
.
getstring
(
'
edu.nrao.archive.configuration.AmqpServer.username
'
)
password
:
str
=
capo_cfg
.
getstring
(
'
edu.nrao.archive.configuration.AmqpServer.password
'
)
return
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
hostname
,
credentials
=
pika
.
PlainCredentials
(
username
,
password
)
)
)
def
main
():
# Parse command-line args
args
:
argparse
.
Namespace
=
make_arg_parser
().
parse_args
()
connection
:
pika
.
BlockingConnection
=
make_amqp_connection
(
args
.
profile
)
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