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

Refactor Project Structure #11

Merged
merged 57 commits into from Oct 13, 2022
Merged

Refactor Project Structure #11

merged 57 commits into from Oct 13, 2022

Conversation

harveysanders
Copy link
Contributor

@harveysanders harveysanders commented Sep 30, 2022

Continuation of #10

  • Refactor project structure
  • Add CI/CD GitHub workflows
  • Remove internal email templates and use Mailgun's template API
  • Add tests for existing functionality

Project Structure

There is a signupService struct that has a list of tasks to run on a signup form event from the operationspark.org website.

A task is an interface with run and name methods.

type task interface {
	// Run takes a signup form struct and executes some action.
	// Ex.: Send an email, post a Slack message.
	run(signup Signup) error
	// Name Returns the name of the task.
	name() string
}

When someone signs up for an Info Session, the form is parsed, then passed to a series of tasks for processing.

// function.go

// Set up services/tasks to run when someone signs up for an Info Session.
mgSvc := NewMailgunService(mgDomain, mgAPIKey, "")
glSvc := NewGreenlightService(glWebhookURL)
slackSvc := NewSlackService(slackWebhookURL)

// These registration tasks include:
registrationService := newSignupService(
	// posting a WebHook to Greenlight,
	glSvc,
	// sending a "Welcome Email",
	mgSvc,
	// sending a Slack message to #signups channel,
	slackSvc,
	// TODO:
	// registering the user for the Zoom meeting,
	// sending an SMS confirmation message to the user.
)

server := newSignupServer(registrationService)
// Register executes a series of tasks in order. If one fails, the remaining tasks are cancelled.
func (sc *SignupService) register(su Signup) error {
	// TODO: Create specific errors for each handler
	// TODO: Use context.Context to cancel subsequent requests on any failures
	for _, task := range sc.tasks {
		err := task.run(su)
		if err != nil {
			return fmt.Errorf("task failed: %q: %v", task.name(), err)
		}
	}
	return nil
}

To register a new task, create a service struct and implement the task interface:

Example

package signup

type skywriteService struct {
}

func NewSkyWriteService() *skywriteService {
  return &skywriteService{}
}

func (d skywriteService) run(su Signup) error {
	return d.skyWrite(su.NameFirst)
}

func (d skywriteService) name() string {
	return "dominos service"
}

// SkyWrite sends a drone out to draw someones name in chemtrails.
func (d skywriteService) skyWrite(name string) error {
	// Do the thing
	return nil
}

Then pass the service to the registration service in function.go.

func NewServer() {
	// ...
  registrationService := newSignupService(
    // ... other tasks,
    // (Order matters!)
    NewSkyWriteService()
	)
  // ...
	server := newSignupServer(registrationService)
	return server
}

TODO

  • update QA token
  • update mailgun templates
  • handle "none of these fit my schedule" (gracefully)
  • Use context to cancel subsequent requests

@harveysanders
Copy link
Contributor Author

uber-go/atomic#120

@harveysanders harveysanders temporarily deployed to staging October 3, 2022 15:14 Inactive
@harveysanders harveysanders temporarily deployed to staging October 7, 2022 16:36 Inactive
@harveysanders harveysanders temporarily deployed to staging October 7, 2022 18:05 Inactive
@harveysanders harveysanders temporarily deployed to staging October 7, 2022 19:22 Inactive
@harveysanders harveysanders temporarily deployed to staging October 7, 2022 20:04 Inactive
@harveysanders harveysanders temporarily deployed to staging October 7, 2022 20:16 Inactive
@harveysanders harveysanders temporarily deployed to staging October 7, 2022 20:23 Inactive
@harveysanders harveysanders temporarily deployed to staging October 7, 2022 21:16 Inactive
@harveysanders harveysanders temporarily deployed to staging October 12, 2022 16:28 Inactive
@harveysanders harveysanders merged commit 0cd119d into main Oct 13, 2022
@harveysanders harveysanders deleted the staging branch October 13, 2022 14:33
@harveysanders harveysanders temporarily deployed to staging October 13, 2022 14:51 Inactive
@harveysanders harveysanders temporarily deployed to staging October 25, 2022 18:08 Inactive
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.

Update Signup process
3 participants