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

6336 Make central record processor generic #6337

Merged
merged 6 commits into from
Feb 3, 2025

Conversation

andreievg
Copy link
Collaborator

@andreievg andreievg commented Jan 29, 2025

Fixes #6336

πŸ‘©πŸ»β€πŸ’» What does this PR do?

Allow for central record processor to be generic.
Expand central record processor trait to have extra methods:
change_log_table_names
changelogs_filter
cursor_type
should_run

Processor trigger accepts type of central record processor

Relocated processor files to be more structured (now that there is central processor, it lives in parent dir and has contact form as child)

πŸ’Œ Any notes for the reviewer?

πŸ§ͺ Testing

  • Contact form emails still work

@andreievg andreievg changed the title Make central record processor generic 6336 Make central record processor generic Jan 29, 2025
let changelog_repo = ChangelogRepository::new(&ctx.connection);
let cursor_controller = CursorController::new(KeyType::ContactFormProcessorCursor);

let cursor_controller = CursorController::new(processor.cursor_type());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

processor now defines cursor_type and changelog_filter

@@ -29,14 +30,14 @@ const CHANNEL_BUFFER_SIZE: usize = 30;
pub struct ProcessorsTrigger {
requisition_transfer: Sender<()>,
invoice_transfer: Sender<()>,
contact_form_to_email: Sender<()>,
central_record: Sender<CentralRecordProcessorType>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When triggered we specify which central record type should be processed

@@ -27,21 +26,39 @@ pub(crate) enum ProcessCentralRecordsError {

const CHANGELOG_BATCH_SIZE: u32 = 20;

#[derive(Clone)]
pub enum CentralRecordProcessorType {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Type is used because processor will be triggered in generic way, and need to specify which records to process

@github-actions github-actions bot added enhancement New feature or request Team Ruru πŸ¦‰ Roxy, Ferg, Noel feature: plugin labels Jan 29, 2025
@andreievg andreievg added Team Ruru πŸ¦‰ Roxy, Ferg, Noel and removed enhancement New feature or request Team Ruru πŸ¦‰ Roxy, Ferg, Noel labels Jan 29, 2025
@lache-melvin lache-melvin self-assigned this Jan 29, 2025
@lache-melvin lache-melvin added this to the v2.6.0 milestone Jan 29, 2025
/// Extra check to see if processor should trigger, like if it's central for contact form email
fn should_run(&self) -> bool {
true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's the central server processor, shouldn't it always only run on central server?

impl CentralRecordProcessorType {
pub(super) fn get_processor(&self) -> Box<dyn CentralServerProcessor> {
match self {
CentralRecordProcessorType::ContactFormEmail => Box::new(QueueContactEmailProcessor),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep the capability to have multiple processors for the same record type, like we have for invoices?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel like the transfer processors are a bit different, because:

They prepare data in a particular shape before processors run (maybe can be done with some generic, but a bit complex for now ?)

I think we can use the cursor increase function of this generic processors also for transfers, you are right ! I'll have a little go at this now, won't spend too long on it though

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we can use the cursor increase function of this generic processors also for transfers, you are right ! I'll have a little go at this now, won't spend too long on it though

Actually I am getting a bit worried with 'order of operation', so will keep existing transfer logic as is for now

Copy link
Contributor

@lache-melvin lache-melvin left a comment

Choose a reason for hiding this comment

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

Thanks for this Andrei, knew this needed a little cleaning up 😁

This feels now like it's just a Processor - we could consolidate the requisition and invoice processors into this one (with should_run always true) - or it should actually just be central only?

@andreievg
Copy link
Collaborator Author

andreievg commented Jan 30, 2025

@lache-melvin thanks for your review, here is the change for the renaming: c666f7d (sorry now git is confused, and can't seem to recognise that file was moved and changed, in overall diff, but that diff looks ok)

I think we can use this 'Processor' in requisition and invoice transfers, but thought to not change too much and was worried a little bit about ordering. The try_process_record can implement getting the required records from the changelog and then running a bunch of specific processors, this can potentially be made generic but I think it would be a big hard with generic types, like

 // fn try_process_record(
fn prepare_record_for processing(&self) -> T // Get all the pre requisite records ready to pass to ProcessRecordFucntion
fn get_process_record_functions(&sefl) ->Vec<Box<dyn ProcessRecordFunction<T>>>> { 
// ...
// The above should work but when it comes to Box Processor, need to actually specify "T" (so stuck on that)

Copy link
Contributor

@lache-melvin lache-melvin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for changes πŸ™

impl ProcessorType {
pub(super) fn get_processor(&self) -> Box<dyn Processor> {
match self {
ProcessorType::ContactFormEmail => Box::new(QueueContactEmailProcessor),
Copy link
Contributor

Choose a reason for hiding this comment

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

Only thought is whether this should support a vec of processors, like we have for invoices etc... there might end up being multiple things we want to process with the contact form? But guess we can add that when we get there 😁

@andreievg andreievg merged commit 3ab36c4 into develop Feb 3, 2025
2 checks passed
@andreievg andreievg deleted the 6336-Central-record-processor-to-be-generic branch February 3, 2025 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor central processor to allow new processors to be added
2 participants