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

Start Auction by sending to Auctioneer #116

Merged
merged 32 commits into from
Jan 5, 2024
Merged

Conversation

bd-viget
Copy link
Contributor

@bd-viget bd-viget commented Dec 21, 2023

Summary

This PR is super exciting! It uses the Auction Start Cron action to signal to Auctioneer (our Node.js server) that an Auction is starting. We are pulling Auctions that start 1 minute from the current day/time.

Changes to Ticket

There are a few changes that go against the requirements in the ticket, mostly outlined in this Issue.

  • The Endpoint URL(s) (and/or Request method) will change (POST /auction/{guid}/start)
  • The Payload will be different based on the endpoint, and will be limited to only the required information, based on the type of request.

Environment Variables

I have gone ahead and update the WP VIP Development Environment variable for GOODBIDS_AUCTIONEER_URL_DEVELOP. That command is:
vip @goodbids.develop config envvar set GOODBIDS_AUCTIONEER_URL_DEVELOP

Important: Updates to environment variables will not be available until the application’s next deploy.

Then follow the prompts. The value should be: https://goodbids-node-develop.go-vip.net.

We have 2 others we could set up (GOODBIDS_AUCTIONEER_URL_LOCAL and GOODBIDS_AUCTIONEER_URL_PRODUCTION), however, for the purpose of this PR, they have not been set up. And the "Develop" Environment variable has only been set up on the VIP Development Environment.

Issues

Testing Instructions-ish

Local Environment

Since we don't have access to the remote VIP Environment variables, we have to use a PHP file. Create a new file in client-mu-plugins called vip-env-vars.local.php. The contents should be:

defined( 'VIP_ENV_VAR_GOODBIDS_AUCTIONEER_URL_LOCAL' ) || define( 'VIP_ENV_VAR_GOODBIDS_AUCTIONEER_URL_LOCAL', 'http://localhost:3000' );
defined( 'VIP_ENV_VAR_GOODBIDS_AUCTIONEER_URL_DEVELOP' ) || define( 'VIP_ENV_VAR_GOODBIDS_AUCTIONEER_URL_DEVELOP', 'https://goodbids-node-develop.go-vip.net' );
defined( 'VIP_ENV_VAR_GOODBIDS_AUCTIONEER_URL_PRODUCTION' ) || define( 'VIP_ENV_VAR_GOODBIDS_AUCTIONEER_URL_PRODUCTION', 'https://goodbids-node.go-vip.net' );

(although we're only currently using the 2nd one)

Local and Development Environments

  1. At this time, I don't think there's really anything visual that can be used to verify if this is working.
  2. I'd say just go through the Create a New Auction process
  3. Make sure you don't get any errors (watch error logs)
  4. I honestly don't think WP Cron is even running locally, so not even sure if there's anything else you could do there.
  5. For Develop, it might be good to wait until the auction starts, and verify the status is updated.

Dev Notes

I have a feeling a good bit of this code will change once we start adding more endpoints, seeing code duplication, and adding more logging. I'm definitely open to suggestions on other approaches. @joshuapease and I discussed using Named Arguments to define the Request Objects, but didn't add it this round.

@bd-viget bd-viget requested a review from joshuapease December 21, 2023 21:58
@clatwell
Copy link
Contributor

This PR IS super exciting!!! 🎉 🎉 🎉

Super cool that you and @nick-telsan worked through revisions to the endpoints together today. Go team!

Comment on lines 25 to 27
'local' => 'GOODBIDS_AUCTIONEER_URL_LOCAL',
'develop' => 'GOODBIDS_AUCTIONEER_URL_DEVELOP',
'production' => 'GOODBIDS_AUCTIONEER_URL_PRODUCTION',
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it also work to have a single env var GOODBIDS_AUCTIONEER_URL and just have the value be different across each environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, the environments relate to the Auctioneer specifically, and The Auctioneer Environment does not have to match the GoodBids Site Environment. The idea is if I'm on Develop (or local) and I want to primarily use the Production Auctioneer, however, there's a new feature on the develop Auctioneer URL that hasn't been tested yet, I can easily switch to that environment without updating the ENV vars. It's super easy to do locally, but on Develop or Production, you have to re-deploy if you update environment variables. So did this just to make things consistent across all environments.

Comment on lines +139 to +146
// TODO: Refactor using individual Response classes.
$payload = [
'id' => $guid,
'startTime' => goodbids()->auctions->get_start_date_time( $auction_id, 'c' ),
'endTime' => goodbids()->auctions->get_end_date_time( $auction_id, 'c' ),
'currentBid' => floatval( $bid_product?->get_price( 'edit' ) ),
'requestTime' => current_datetime()->format( 'c' ),
];
Copy link
Contributor

@joshuapease joshuapease Dec 21, 2023

Choose a reason for hiding this comment

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

I think this works great.

In this case, the two biggest benefit of classes & named arguments are:

  1. automated refactors. But... if you're only building up this payload in one spot... you don't really benefit much from it.
  2. Type hints / warnings. Not sure if that's super valuable here either.

Might as well not add complexity until you need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those were my thoughts as well. I don't know if we'll ever be building these payloads differently, so we can cross that bridge if/when we get there.

Copy link
Contributor

@nathan-schmidt-viget nathan-schmidt-viget left a comment

Choose a reason for hiding this comment

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

Looks awesome!

@bd-viget bd-viget merged commit 259cece into main Jan 5, 2024
1 check passed
@bd-viget bd-viget deleted the bd/82-auction-start-part-2 branch January 5, 2024 05:51
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.

4 participants