Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack addon, three different lead states #79

Merged
merged 8 commits into from
Jul 6, 2023
Merged

Conversation

gzukowski
Copy link
Contributor

No description provided.

self.api_url, headers=self.token_header, data=self.request_data
)
token = json.loads(response.text)["access_token"]
continue
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a asyncio.sleep(WAIT_TIME_ERROR) here - hold back on error (also define a constant near the top of the file).

buffer_users.append(result["email"])
if not has_more:
last_user = result["email"]
await asyncio.sleep(5)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await asyncio.sleep(5)
await asyncio.sleep(WAIT_TIME_ON_USER)

)
buffer_users.append(result["email"])
if not has_more:
last_user = result["email"]
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to keep the update time instead of email - users may change and we could just push the changed users as well, but email will do for now.

self.array = []

def append(self, value):
if len(self.array) == 5:
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! But

Suggested change
if len(self.array) == 5:
if len(self.array) == self.ARRAY_LENGTH:

Comment on lines 2 to 3
def __init__(self):
self.array = []
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self):
self.array = []
def __init__(self, length = 5):
self.array = []
self.ARRAY_LENGTH = length;

except Exception as error:
raise Exception(f"Config not loaded: {error}")
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return statement is not needed after raising an Exception here (same for chimp and Stripe). Its message "Config not loaded:" suggests that there was a problem with the config, but a different, unrelated exception might be raised by get_auth() method.

@S4adam
Copy link
Contributor

S4adam commented Jul 4, 2023

This line seems to be a leftover.

In Auth0, you check if an error occured with the string condition but a better way would be to check its status_code, like: if verified.status_code != 200: ..., and then parse it as json().

The get_auth() is async so I think these:

            verified = requests.get(self.verified_url, headers=headers).json()
            users = requests.get(self.users_url, headers=headers).json()

requests could be made asynchronously.

Instead of using prints, I think we should stick to the context.logger. Then you could specify log levels explicitly, so in except blocks you would use context.logger.error("..."), and for informational messages context.logger.info("...") etc.

Little inconsistency - in Auth0, asyncio.gather() is inside the try-except block, but in Stripe it is not.

And of course, as @MichalCz stated, constant variables should be introduced!:D

@gzukowski gzukowski requested review from S4adam and MichalCz July 5, 2023 09:37
Copy link
Contributor

@S4adam S4adam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing I could propose is not passing context, but rather logger because there is no other context usage in ChimpInsert other than for logging.
And what's up with tako? What is it for?

Also note that the:

verified =  await requests_async.get(self.verified_url, headers=headers)
users = await requests_async.get(self.users_url, headers=headers)

calls are not truly asynchronous (as in the meaning of the word), but at least they are on the event loop now so its all good👌

@gzukowski
Copy link
Contributor Author

@S4adam you were right ,"tako" is a debug leftover and I accidentally corrected it but in other file

@gzukowski gzukowski merged commit 63170fd into main Jul 6, 2023
2 checks passed
@gzukowski gzukowski deleted the feat/slack-addon branch July 6, 2023 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants