Coder Social home page Coder Social logo

Comments (9)

pjcalvo avatar pjcalvo commented on August 24, 2024 1

I will make it so it returns a true in case of success.. @obriat

from locust-influxdb-listener.

obriat avatar obriat commented on August 24, 2024 1

I think I find the right process by using the ping method and catching its exception:

            influxDBSettings = InfluxDBSettings(
                influx_host='influx_host',
                influx_port='8086',
                user='admin',
                pwd='pass',
                database='locustidb'
            )

            for i in range(1, 6):
                try:
                    # start listener with the given configuration
                    influx = InfluxDBListener(env=environment, influxDbSettings=influxDBSettings)
                    influx.influxdb_client.ping()
                except:
                   # InfluxDBListener does not throw exception but  influx.influxdb_client.ping() do.
                    wait = i * i
                    print("Try nĀ°" + str(i) + ": Could not connect to influxdb, wait for " + str(
                        wait) + " seconds and try again.")
                    time.sleep(wait)  # sleep the script for x seconds and....#

                else:
                    print("Influx (version: " + influx.influxdb_client.ping() + ") is available")
                    break  # ...break out of the loop#
            else:
                print("Influx is not available!")

from locust-influxdb-listener.

pjcalvo avatar pjcalvo commented on August 24, 2024

I will take a look.

from locust-influxdb-listener.

pjcalvo avatar pjcalvo commented on August 24, 2024

@obriat I just uploaded a fix. switched to .error instead of .exception to hide the extra information. https://pypi.org/project/locust-influxdb-listener/0.0.5/

from locust-influxdb-listener.

obriat avatar obriat commented on August 24, 2024

It didn't fix my issue, I'm a python newbie so maybe my approach is not the right one
I want to wait for influxdb to be ready and just log it if it can't be reach but without stopping my locsut test.

@events.init.add_listener
def locust_init(environment, **kwargs):
...
      influxDBSettings = InfluxDBSettings(
            influx_host=influx_host,
            influx_port='8086',
            user='****',
            pwd='****',
            database='locustidb'
        )
       # try 5 times for a total of 55s
        for i in range(5):
            try:
               InfluxDBListener(env=environment, influxDbSettings=influxDBSettings)
            except:
                wait = i * i 
                log("Try " + i + ": Could not connect to influxdb, wait for" + wait + " seconds and try again.")
                time.sleep(wait) 
                continue 
            else:
                log("Influxdb is available")
                break
        else:
            log("Influxdb is not available")

from locust-influxdb-listener.

pjcalvo avatar pjcalvo commented on August 24, 2024

@obriat The exception is currently handled by the listener. So you don't have to catch it in your end here.

Make you you update to version 0.0.5, which has the fix for the extra log information....

from locust-influxdb-listener.

obriat avatar obriat commented on August 24, 2024

You're right, my package wasn't up to date.
I also see my other mistake, I took the logger.exception for a real exception.
So do you know how I can determine if InfluxDBListener is connected ? The object doesn't seem to return any data or state, it just logs the error.

from locust-influxdb-listener.

obriat avatar obriat commented on August 24, 2024

Here a suggestion: #12.

It turns out that __init__ should not return anything, so I used a state parameter.

from locust-influxdb-listener.

pjcalvo avatar pjcalvo commented on August 24, 2024

Perfect.

from locust-influxdb-listener.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.