Skip to content

Conversation

@bakerkretzmar
Copy link
Contributor

@bakerkretzmar bakerkretzmar commented Jun 11, 2021

This PR adds support for syncing Forge workers 🤖

Pulling down workers from Forge

I added a new workers config key to store workers. The config:pull command can now retrieve a list of workers and store them in the config file under this key.

Values that are determined to be identical to the 'defaults' (see below) are not written to the config file, with two exceptions—the queue and connection variables are always written, even when they are the defaults (default and redis). This was just my opinion about what the bare minimum config values should be in order for the config file to make sense to look at, they aren't technically necessary and we could easily store more than that. Non-default values will always be written to the config file.

Example:

  workers:
    -
      queue: default
      connection: redis
      daemon: true
    -
      queue: emails
      connection: redis
      sleep: 30
      tries: 3

Pushing workers up to Forge

I added a new WorkerSync class that runs as part of the config:push command. It behaves similarly to the other sync classes, diffing the resources found locally and on Forge and then creating/deleting Forge resources as necessary.

Like the config:pull command, WorkerSync knows what the 'default' configuration values are for queue workers and will avoid creating/deleting workers with missing configuration values if those values are the defaults. For example, a locally configured worker with no timeout key will be considered identical to a worker found on Forge with a timeout value of 60, since 60 is the default. See below and the related testing PR (#21) for more details about how this works.

Like the other sync classes, WorkerSync won't actually delete Forge resources unless the --force flag is passed.

Defaults

To avoid storing lots of huge arrays of mostly-redundant properties, this PR also adds the concept of 'default' properties for Forge resources.

In this case I added a 'default worker' containing the default values for the worker configuration options available in the Forge UI. These defaults are not perfect—it doesn't appear to be possible to get or set the 'Maximum memory' and 'Directory' options through the Forge API at all, so I left these out, and the PHP version is returned in a format that isn't great for storing in the Yaml config file. Additionally, some of the UI and API defaults are different—leaving the timeout blank, for example, will default to 60 seconds in the Forge UI but 0 (no timeout) using the API. I tried to choose behaviour that would be intuitive and as similar to the Forge UI as possible.

My other goal with this class is to prevent having to repeat these default values in multiple places. Including the code in my related testing PR, these values are needed in 4 or 5 places, so I wanted to keep them in one place so they don't drift and become inconsistent.

@bakerkretzmar bakerkretzmar mentioned this pull request Jun 11, 2021
@mpociot mpociot merged commit b425f47 into beyondcode:master Jun 14, 2021
@bakerkretzmar bakerkretzmar deleted the add-workers branch June 14, 2021 13:20
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