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 ID resolver for AWS lambda #10

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Add ID resolver for AWS lambda #10

wants to merge 11 commits into from

Conversation

inxilpro
Copy link
Contributor

Snowflakes/etc rely on unique datacenter and worker IDs to operate. Because AWS lambdas are different machines each time, it's impossible to assign each a unique worker/device ID.

This PR adds a new ID resolution mechanism that uses cache locks to acquire a unique ID when required, and then release that ID when the process is terminated. This means that you can effectively have 1024 processes generating unique snowflake IDs in parallel.

By default, Bits will use this mechanism if the AWS_LAMBDA_FUNCTION_NAME environmental variable is set.


public function __destruct()
{
$this->release();

Choose a reason for hiding this comment

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

Could we do an App::terminating callback in the constructor rather than a destruct?

Or we might end up releasing before verbs commits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the advantage of App::terminating over __destruct? I think destruct is a little more flexible, but I could be wrong…

Choose a reason for hiding this comment

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

If destruct happens after laravel tears down, could the cache be disconnected?

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.

2 participants