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

Add timestamp support in send and send_batch #320

Merged
merged 17 commits into from
Oct 28, 2024
Merged

Conversation

Neptune650
Copy link
Contributor

@Neptune650 Neptune650 commented Oct 17, 2024

/claim #315
Closes #315

This pull request creates two functions - send_at and send_batch_at - which receive a timestamp and convert it to seconds from now.

This also documents both functions.

@Neptune650
Copy link
Contributor Author

@ChuckHend So is there anything else left to work on or can this be merged now?

@ChuckHend
Copy link
Member

ChuckHend commented Oct 18, 2024

@ChuckHend So is there anything else left to work on or can this be merged now?

Test cases would be great!

@Neptune650
Copy link
Contributor Author

Neptune650 commented Oct 18, 2024

@ChuckHend So is there anything else left to work on or can this be merged now?

Test cases would be great!

I figured it wouldn't be necessary since send with normal seconds delay isn't tested.

@ChuckHend
Copy link
Member

You are correct, we don't have a test to ensure that the delay feature continues to work as intended, but there are tests calling the function (in the future we should add tests to ensure delay continues to work as intended on send() too). Please add test cases for the new functions that are introduced in this PR.

@Neptune650
Copy link
Contributor Author

@ChuckHend I have added tests, tell me your thoughts.

Copy link
Collaborator

@v0idpwn v0idpwn left a comment

Choose a reason for hiding this comment

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

I think it would probably be a better API if instead send and send_batch were overloaded to support both a delay and a timestamp.

@Neptune650
Copy link
Contributor Author

Neptune650 commented Oct 18, 2024

I think it would probably be a better API if instead send and send_batch were overloaded to support both a delay and a timestamp.

@v0idpwn I've already talked with ChuckHend about this

And an issue remains and that is, which function to run when you only put 2 arguments

@v0idpwn
Copy link
Collaborator

v0idpwn commented Oct 18, 2024

Sorry, missed it because it was resolved :)

@tavallaie
Copy link
Contributor

if both variable are not none, you can simple raise an exception to user that those variable can not be use together.

@tavallaie
Copy link
Contributor

another question if user add delay can change it to vt or vise versa? what will happened? what we except?
what scenario use delay or vt or both?

@Neptune650
Copy link
Contributor Author

if both variable are not none, you can simple raise an exception to user that those variable can not be use together.

No, the issue is that Postgres will raise an exception if there are two overloading functions with the only difference being a default parameter.

@Neptune650
Copy link
Contributor Author

another question if user add delay can change it to vt or vise versa? what will happened? what we except? what scenario use delay or vt or both?

What do you mean?
The user can use delays and change it to vt yes, that's always been an option. The other way around can be done too with CURRENT_TIMESTAMP. It's up to the user to use timestamps or delays.

@Neptune650
Copy link
Contributor Author

Is there anything else I'm missing or is this PR done now?

@tavallaie
Copy link
Contributor

if both variable are not none, you can simple raise an exception to user that those variable can not be use together.

No, the issue is that Postgres will raise an exception if there are two overloading functions with the only difference being a default parameter.

Sorry, but I can't understand why we can't use delay as an option beside vt with default none or zero?

@Neptune650
Copy link
Contributor Author

if both variable are not none, you can simple raise an exception to user that those variable can not be use together.

No, the issue is that Postgres will raise an exception if there are two overloading functions with the only difference being a default parameter.

Sorry, but I can't understand why we can't use delay as an option beside vt with default none or zero?

Look, if we overload two functions like this

pgmq.send_batch( 
     queue_name text, 
     msgs jsonb[], 
     delay timestamp DEFAULT CURRENT_TIMESTAMP
 );

pgmq.send_batch( 
     queue_name text, 
     msgs jsonb[], 
     delay integer DEFAULT 0
 );

Postgres will raise an exception because it won't know which one to run if you just put the first two parameters.

@Neptune650
Copy link
Contributor Author

@ChuckHend Fixed tests, tell me if there's anything missing now.

@v0idpwn
Copy link
Collaborator

v0idpwn commented Oct 27, 2024

@ChuckHend @tavallaie not sure what should be done with the python client after these changes :)

@v0idpwn
Copy link
Collaborator

v0idpwn commented Oct 27, 2024

@Neptune650 I pushed the following changes:

  • Overload pgmq.send/pgmq.send_batch instead of adding new send_at and send_batch_at
  • Refactor to remove code duplication
  • Remove unnecessary timestamp -> duration -> timestamp conversion
  • Take timestamp with tz instead of timestamp without tz

I think the extension code is fine now. We just need to figure what to do in the python api.

@Neptune650
Copy link
Contributor Author

Neptune650 commented Oct 27, 2024

@Neptune650 I pushed the following changes:

  • Overload pgmq.send/pgmq.send_batch instead of adding new send_at and send_batch_at
  • Refactor to remove code duplication
  • Remove unnecessary timestamp -> duration -> timestamp conversion

I think the extension code is fine now. We just need to figure what to do in the python api.

@v0idpwn All sounds good to me, I was thinking we could leave the Python function names as is, while internally calling the overloaded pgmq.send

@tavallaie
Copy link
Contributor

@Neptune650 I pushed the following changes:

  • Overload pgmq.send/pgmq.send_batch instead of adding new send_at and send_batch_at
  • Refactor to remove code duplication
  • Remove unnecessary timestamp -> duration -> timestamp conversion
  • Take timestamp with tz instead of timestamp without tz

I think the extension code is fine now. We just need to figure out what to do in the python API.

I think we can add parameters of delay and ts with a default value of none; check if those, too are not none and use overloaded functions instead.

@Neptune650
Copy link
Contributor Author

@tavallaie I have pushed the changes you suggested, please tell me what you think

@tavallaie
Copy link
Contributor

@Neptune650 did you update unit tests too?

@Neptune650
Copy link
Contributor Author

@Neptune650 did you update unit tests too?

@tavallaie There's no need, they're working fine without changes.

@tavallaie
Copy link
Contributor

@Neptune650 did you update unit tests too?

@tavallaie There's no need, they're working fine without changes.

They are working because not supporting new scenarios like delay

For adding new scenarios we need new tests.

@ChuckHend
Copy link
Member

@Neptune650 , @tavallaie thoughts on moving the python changes to a new PR and focus on getting the SQL API changes approved? Also, while the python client changes are very helpful IMO they are out of scope to the bounty that @Neptune650 is working on.

@tavallaie
Copy link
Contributor

@Neptune650 , @tavallaie thoughts on moving the python changes to a new PR and focus on getting the SQL API changes approved? Also, while the python client changes are very helpful IMO they are out of scope to the bounty that @Neptune650 is working on.

Ok.

@Neptune650
Copy link
Contributor Author

@Neptune650 , @tavallaie thoughts on moving the python changes to a new PR and focus on getting the SQL API changes approved? Also, while the python client changes are very helpful IMO they are out of scope to the bounty that @Neptune650 is working on.

@ChuckHend Sounds good to me, I can create another PR for the Python changes (I'd appreciate if it was with a separate tip but I'll send it either way)

@v0idpwn
Copy link
Collaborator

v0idpwn commented Oct 28, 2024

@Neptune650 would you please revert the Python changes, then? Then I can merge.

@Neptune650
Copy link
Contributor Author

@v0idpwn I reverted the changes, please merge.

@tavallaie
Copy link
Contributor

@Neptune650 , @tavallaie thoughts on moving the python changes to a new PR and focus on getting the SQL API changes approved? Also, while the python client changes are very helpful IMO they are out of scope to the bounty that @Neptune650 is working on.

@ChuckHend Sounds good to me, I can create another PR for the Python changes (I'd appreciate if it was with a separate tip but I'll send it either way)

If you are busy, I can do that.

@Neptune650
Copy link
Contributor Author

@Neptune650 , @tavallaie thoughts on moving the python changes to a new PR and focus on getting the SQL API changes approved? Also, while the python client changes are very helpful IMO they are out of scope to the bounty that @Neptune650 is working on.

@ChuckHend Sounds good to me, I can create another PR for the Python changes (I'd appreciate if it was with a separate tip but I'll send it either way)

If you are busy, I can do that.

@tavallaie I've created a PR for it #333

Copy link
Member

@ChuckHend ChuckHend left a comment

Choose a reason for hiding this comment

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

Thank you @Neptune650

@Neptune650
Copy link
Contributor Author

Thank you @Neptune650

@ChuckHend No problem - please merge if ready.

@v0idpwn v0idpwn changed the title Create send_at and send_batch_at functions receiving a timestamp Add timestamp support in send and send_batch Oct 28, 2024
@v0idpwn v0idpwn merged commit d2a0021 into tembo-io:main Oct 28, 2024
15 of 19 checks passed
@Neptune650 Neptune650 deleted the send_at branch October 28, 2024 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: possible to have send() use a specific date time not a delay
4 participants