Skip to content

Commit d8fcee0

Browse files
authored
Merge pull request #39 from instana/delay-fsm
On boot, delay FSM start for process to initialize
2 parents 098ee57 + 8965819 commit d8fcee0

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

instana/agent.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ class Agent(object):
3535
host = a.AGENT_DEFAULT_HOST
3636
port = a.AGENT_DEFAULT_PORT
3737
fsm = None
38-
from_ = None
38+
from_ = From()
3939

4040
def __init__(self, sensor):
4141
log.debug("initializing agent")
4242

4343
self.sensor = sensor
4444
self.fsm = f.Fsm(self)
45-
self.reset()
4645

4746
def to_json(self, o):
4847
try:

instana/fsm.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import subprocess
2-
import os
31
import sys
2+
import os
43
import socket
4+
import subprocess
55
import threading as t
66
import fysom as f
77
from instana import log
@@ -41,7 +41,7 @@ def __init__(self, agent):
4141

4242
self.agent = agent
4343
self.fsm = f.Fysom({
44-
"initial": "lostandalone",
44+
"initial": {'state': "lostandalone", 'event': 'init', 'defer': True},
4545
"events": [
4646
("startup", "*", "lostandalone"),
4747
("lookup", "lostandalone", "found"),
@@ -52,10 +52,19 @@ def __init__(self, agent):
5252
"onannounce": self.announce_sensor,
5353
"onchangestate": self.printstatechange}})
5454

55+
timer = t.Timer(2, self.boot)
56+
timer.daemon = True
57+
timer.name = "Startup"
58+
timer.start()
59+
5560
def printstatechange(self, e):
5661
log.debug('========= (%i#%s) FSM event: %s, src: %s, dst: %s ==========' %
5762
(os.getpid(), t.current_thread().name, e.event, e.src, e.dst))
5863

64+
def boot(self):
65+
self.fsm.init()
66+
self.fsm.lookup()
67+
5968
def reset(self):
6069
self.fsm.lookup()
6170

@@ -110,6 +119,7 @@ def announce_sensor(self, e):
110119
log.debug("announcing sensor to the agent")
111120
s = None
112121
pid = os.getpid()
122+
cmdline = []
113123

114124
if os.path.isfile("/proc/self/cmdline"):
115125
with open("/proc/self/cmdline") as cmd:

0 commit comments

Comments
 (0)