Skip to content

Conversation

@n1ru4l
Copy link
Contributor

@n1ru4l n1ru4l commented Dec 8, 2025

Background

If Redis dies we loose pending jobs

Description

  • Merges emails and webhook service + additional schema check purge service that was running in the server service into the workflow service powered by postgraphile worker
  • we now use the pg database as the job backend, which ensure we are not loosing any jobs :)
  • provides a simple interface so everyone can easily add new tasks and schedule them

Deployment Strategy

  • In order to not loose any existing tasks in the redis queue, we should deploy this service along-side the existing emails and webhooks service. Then once the redis emails and webhooks queue is drained, we can remove those services.
    Alternatively, we could also move tasks from bull to postgres, but this is additional work that can be avoided.

Checklist

  • Input validation
  • Output encoding
  • Authentication management
  • Session management
  • Access control
  • Cryptographic practices
  • Error handling and logging
  • Data protection
  • Communication security
  • System configuration
  • Database security
  • File management
  • Memory management
  • Testing

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @n1ru4l, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request establishes a new workflows service, designed to centralize and manage asynchronous background tasks within the application. By integrating graphile-worker, it provides a scalable and reliable mechanism for handling operations such as sending various email notifications (e.g., for user verification, organization invitations, password resets, and rate limit alerts) and performing critical database maintenance like purging expired schema checks. This service aims to improve application responsiveness and reliability by offloading these processes from the main application flow.

Highlights

  • New workflows service: A dedicated service has been introduced to manage background tasks and asynchronous operations.
  • Graphile-worker integration: The service utilizes graphile-worker for robust job queue management and task execution.
  • Comprehensive email system: A flexible email sending system with multiple providers (Postmark, SMTP, Sendmail, Mock) and MJML-based templating for various notifications has been implemented.
  • Structured task management: New utilities (defineTask, implementTask) provide a structured way to define and implement tasks with zod schema validation and integrated logging.
  • Environment configuration: A robust environment variable validation and configuration system using zod ensures proper setup for the new service.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
hive 8.13.0-alpha-20251209142608-77b31e031d4d60c2377067fe24bc2baa4488bf13 npm ↗︎ unpkg ↗︎

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

📚 Storybook Deployment

The latest changes are available as preview in: https://pr-7383.hive-storybook.pages.dev

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

💻 Website Preview

The latest changes are available as preview in: https://pr-7383.hive-landing-page.pages.dev

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new @hive/workflows package, which sets up a graphile-worker to handle background tasks. The implementation includes environment variable parsing, a task definition kit, and several task implementations for features like email notifications and data purging. The overall structure is sound, but I've identified a critical type error in the worker's context initialization, a deviation from the style guide regarding fetch usage, and a placeholder implementation that needs to be completed.

Comment on lines +74 to +88
const response = await fetch('https://api.postmarkapp.com/email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'X-Postmark-Server-Token': config.token,
},
body: JSON.stringify({
From: emailFrom,
To: email.to,
Subject: email.subject,
HtmlBody: email.body,
MessageStream: config.messageStream,
}),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The style guide discourages direct use of fetch because it lacks built-in retries. The postmark email provider uses fetch to send emails, which could lead to failed email deliveries on transient network issues. Please consider using a more robust HTTP client library that supports retries, like got which is used elsewhere in the repository, or implement a retry mechanism.

References
  1. Avoid using fetch or node-fetch directly, as it does not have built-in retries. (link)

@n1ru4l n1ru4l force-pushed the experiment-postgraphile-worker branch from b74e09e to 43524f0 Compare December 9, 2025 13:04
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

🐋 This PR was built and pushed to the following Docker images:

Targets: build

Platforms: linux/amd64

Image Tag: 77b31e031d4d60c2377067fe24bc2baa4488bf13

}),
}) as HivePubSub;

let dbPurgeTaskRunner: null | ReturnType<typeof createTaskRunner> = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now a cron in the workflow service

@n1ru4l n1ru4l changed the title Experiment postgraphile worker persistent job queue with postgraphile worker Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant