Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalClient
Commits
2cb4b749
Commit
2cb4b749
authored
Nov 15, 2018
by
Lukas Burgey
Browse files
Rework the debug print outs
parent
5562cd0e
Changes
3
Hide whitespace changes
Inline
Side-by-side
consumer.go
View file @
2cb4b749
package
main
import
(
"bytes"
"encoding/json"
"fmt"
"log"
...
...
@@ -104,7 +105,7 @@ func (c *consumer) connect() (deliveries <-chan amqp.Delivery, err error) {
// all the bindings from our queue to the topic exchange
for
_
,
exchange
:=
range
c
.
exchanges
{
if
*
b
roker
Debugging
{
if
*
b
ackend
Debugging
{
log
.
Printf
(
"[Conn] Binding to exchange %s with routing keys %v"
,
exchange
.
name
,
exchange
.
bindingKeys
)
}
for
_
,
bindingKey
:=
range
exchange
.
bindingKeys
{
...
...
@@ -191,6 +192,15 @@ func (c *consumer) startConsuming() (err error) {
func
(
c
*
config
)
consume
(
deliveries
<-
chan
amqp
.
Delivery
)
{
for
d
:=
range
deliveries
{
if
*
backendDebugging
{
indented
:=
new
(
bytes
.
Buffer
)
if
err
:=
json
.
Indent
(
indented
,
d
.
Body
,
" "
,
" "
);
err
!=
nil
{
log
.
Printf
(
"Received via AMQP (unable to indent: %v):
\n
%s"
,
err
,
d
.
Body
)
}
else
{
log
.
Printf
(
"Received via AMQP:
\n
%s"
,
indented
)
}
}
var
newTask
task
err
:=
json
.
Unmarshal
(
d
.
Body
,
&
newTask
)
...
...
main.go
View file @
2cb4b749
...
...
@@ -76,7 +76,6 @@ var (
configFile
=
app
.
Arg
(
"config"
,
"Config file to file to use."
)
.
Required
()
.
String
()
scriptDebugging
=
app
.
Flag
(
"debug-scripts"
,
"Display debugging info concerning executed scripts"
)
.
Bool
()
backendDebugging
=
app
.
Flag
(
"debug-backend"
,
"Display debugging info concerning the backend"
)
.
Bool
()
brokerDebugging
=
app
.
Flag
(
"debug-broker"
,
"Display debugging info concerning the message broker"
)
.
Bool
()
debugAll
=
app
.
Flag
(
"debug"
,
"Display all debugging info"
)
.
Bool
()
sequentialExecution
=
app
.
Flag
(
"seq"
,
"Execute tasks sequentially"
)
.
Bool
()
)
...
...
@@ -174,32 +173,19 @@ func getConfig(configFile string) (c config, err error) {
if
c
.
Password
==
""
{
log
.
Fatalf
(
"[Conf] No 'password' in config"
)
}
if
c
.
FetchIntervalString
==
""
{
c
.
FetchInterval
=
defaultFetchInterval
log
.
Printf
(
"[Conf] Using default fetch_interval of %v"
,
c
.
FetchInterval
)
}
else
{
c
.
FetchInterval
,
err
=
time
.
ParseDuration
(
c
.
FetchIntervalString
)
if
err
!=
nil
{
log
.
Printf
(
"[Conf] Error parsing fetch interval: %s"
,
err
)
err
=
nil
var
parseError
error
c
.
FetchInterval
,
parseError
=
time
.
ParseDuration
(
c
.
FetchIntervalString
)
if
parseError
!=
nil
{
log
.
Printf
(
"[Conf] Error parsing 'fetch_interval': %s"
,
parseError
)
c
.
FetchInterval
=
defaultFetchInterval
log
.
Printf
(
"[Conf] Using default fetch_interval of %v"
,
c
.
FetchInterval
)
}
log
.
Printf
(
"[Conf] Using default 'fetch_interval' of %v"
,
c
.
FetchInterval
)
}
if
c
.
ReconnectTimeoutString
==
""
{
c
.
ReconnectTimeout
=
defaultReconnectTimeout
log
.
Printf
(
"[Conf] Using default reconnect_timeout of %v"
,
c
.
ReconnectTimeout
)
}
else
{
c
.
ReconnectTimeout
,
err
=
time
.
ParseDuration
(
c
.
ReconnectTimeoutString
)
if
err
!=
nil
{
log
.
Printf
(
"[Conf] Error parsing reconnect timeout: %s"
,
err
)
err
=
nil
c
.
ReconnectTimeout
,
parseError
=
time
.
ParseDuration
(
c
.
ReconnectTimeoutString
)
if
parseError
!=
nil
{
log
.
Printf
(
"[Conf] Error parsing 'reconnect_timeout': %s"
,
parseError
)
c
.
ReconnectTimeout
=
defaultReconnectTimeout
log
.
Printf
(
"[Conf] Using default reconnect_timeout of %v"
,
c
.
ReconnectTimeout
)
}
log
.
Printf
(
"[Conf] Using default 'reconnect_timeout' of %v"
,
c
.
ReconnectTimeout
)
}
// fetch the remote configuration
...
...
@@ -236,14 +222,9 @@ func main() {
kingpin
.
MustParse
(
app
.
Parse
(
os
.
Args
[
1
:
]))
if
*
debugAll
{
*
brokerDebugging
=
true
*
scriptDebugging
=
true
*
backendDebugging
=
true
}
if
*
brokerDebugging
{
log
.
Printf
(
"[Debug] broker debugging enabled"
)
}
if
*
scriptDebugging
{
log
.
Printf
(
"[Debug] script debugging enabled"
)
}
...
...
task.go
View file @
2cb4b749
...
...
@@ -234,21 +234,25 @@ func (c *config) fetchTasks() (err error) {
var
newTasks
[]
task
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
var
indented
bytes
.
Buffer
json
.
Indent
(
&
indented
,
body
,
""
,
" "
)
log
.
Printf
(
"%s"
,
indented
.
Bytes
())
err
=
json
.
Unmarshal
(
body
,
&
newTasks
)
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"Error unmarshaling: %s
\n
%s"
,
err
,
body
)
return
}
log
.
Printf
(
"[Fetch] %d new tasks: %v"
,
len
(
newTasks
),
newTasks
)
if
*
backendDebugging
{
indented
:=
new
(
bytes
.
Buffer
)
if
err
:=
json
.
Indent
(
indented
,
body
,
""
,
" "
);
err
!=
nil
{
log
.
Printf
(
"Fetched via HTTP (unable to indent: %v):
\n
%s"
,
err
,
body
)
}
else
{
log
.
Printf
(
"Fetched via HTTP:
\n
%s"
,
indented
)
}
}
for
_
,
task
:=
range
newTasks
{
err
=
c
.
scheduleTask
(
task
)
if
err
!=
nil
{
log
.
Printf
(
"[
Fetch
] %v"
,
err
)
log
.
Printf
(
"[
scheduleTask
] %v"
,
err
)
// we execute all tasks even when one fails
err
=
nil
...
...
@@ -398,7 +402,7 @@ func (c *config) respondToTask(te taskReply) (err error) {
}
if
*
backendDebugging
{
log
.
Printf
(
"
Replying to the backend:
%s"
,
taskResponse
)
log
.
Printf
(
"
Task Response:
\n
%s"
,
taskResponse
)
}
url
:=
fmt
.
Sprintf
(
"https://%s/backend/clientapi/response"
,
c
.
Host
)
...
...
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