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

[STU-74] Triggering an event after a successful refresh on queue jobs? #283

Closed
sunscreem opened this issue Nov 2, 2023 · 6 comments
Closed
Assignees
Labels
✨ enhancement linear Created by Linear-GitHub Sync

Comments

@sunscreem
Copy link
Contributor

sunscreem commented Nov 2, 2023

I'm wondering if anyone has worked out how to trigger an event when an update of the indexes has successfully completed.

The complication is I'm using supervisor to run my queue, so on my local testing this works great... But it doesn't seem to fire in production, I'm guessing because of how Craft runs queue jobs using supervisor?

 Event::on(
            Queue::class,
            Queue::EVENT_AFTER_EXEC_AND_RELEASE,
            function (ExecEvent $event) {
                if (get_class($event->job) === 'rias\scout\jobs\ImportIndex') {

                   Craft::info('testing');
                   
                }
            }
        );

Essentially what I'm trying to do is update a timestamp the last time a cron job to update my scout index is successfully completed.

STU-74

@janhenckens
Copy link
Member

@sunscreem Are you triggering a full import using the CLI command?
That uses a seperate job class so I could trigger a new "AFTER_INDEX_IMPORT" event there if that could help?

@janhenckens janhenckens self-assigned this Nov 8, 2023
@janhenckens janhenckens added ✨ enhancement linear Created by Linear-GitHub Sync labels Nov 8, 2023
@janhenckens janhenckens changed the title Triggering an event after a successful refresh on queue jobs? [STU-74] Triggering an event after a successful refresh on queue jobs? Nov 8, 2023
@sunscreem
Copy link
Contributor Author

Hey @janhenckens - coincidentally I managed to sort this just last night.

The issue was that supervisor needed restarted to pick up my changed code, only I hadn't notice it wasn't doing so in my deployments due to a permissions issue.

This is working a treat now. I use it alongside Oh Dear - Health Check to make sure my indexes are updating on a cron job overnight.

Although not needed, an event such as AFTER_INDEX_IMPORT would make it more specific to scout vs firing for every queue job?

@janhenckens
Copy link
Member

Good to hear you got it working!

Not having to check it for every queue job is probably a lot more efficient on your end, I'll put it on the list and let you know when it's available :)

@sunscreem
Copy link
Contributor Author

Awesome!

janhenckens added a commit that referenced this issue Nov 8, 2023
@janhenckens
Copy link
Member

Had to work on some other issues for the plugin so rolled this in already :) It's out in 3.3.1, you can find documentation here

@sunscreem
Copy link
Contributor Author

@janhenckens Works perfectly. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement linear Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

2 participants