Adds Service Desk custom email cleanup worker
What does this MR do and why?
This MR adds a cronjob worker ServiceDesk::CustomEmailCleanupWorker
that marks started and overdue verifications for Service Desk custom email addresses as failed.
Verification workflow: We send a verification email to the custom email which should get forwarded to the Service Desk email address of the project and we then ingest that email. This should usually take only a couple of minutes. If we didn't receive anything within the last 30 minutes, we need to end the verification process for that project, mark the verification as failed and send the verification result emails. This is what the worker will do.
The worker will run every two minutes.
Screenshots or screen recordings
Query
The DB index was added with Adds indexes on service_desk_custom_email_verif... (!128498 - merged)
Query
SELECT "service_desk_custom_email_verifications".*
FROM "service_desk_custom_email_verifications"
WHERE "service_desk_custom_email_verifications"."state" = 0 AND
(triggered_at <= '2023-08-04 13:21:28.666463')
Plan
Index Scan using i_custom_email_verifications_on_triggered_at_and_state_started on service_desk_custom_email_verifications (cost=0.12..3.14 rows=1 width=108)
Index Cond: (triggered_at <= '2023-08-04 13:21:28.666463+00'::timestamp with time zone)
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
-
Open the rails console and add records for a custom email address for a project that is overdue:
project = Project.find(7) current_user = User.first custom_email = 'support@example.com' setting = ServiceDeskSetting.find_or_create_by!(project_id: project.id) setting.update!(custom_email: custom_email) credential = ServiceDesk::CustomEmailCredential.create!( project_id: project.id, smtp_address: 'smtp.gmail.com', # we need a valid smtp address smtp_port: 587, smtp_username: custom_email, smtp_password: 'supersecret' ) verification = ServiceDesk::CustomEmailVerification.new( project_id: project.id ) verification.mark_as_started!(current_user) verification.update!(triggered_at: 31.minutes.ago) ServiceDesk::CustomEmailVerificationCleanupWorker.new.perform verification.reset
-
The verification print should say something like
state: "failed", error: "mail_not_received_within_timeframe",
-
You can also leave out the call of the worker and wait until the cronjob runs and then reset the verification object to see that it changed the state.
-
In letter opener (if you have no other email config) you should see a verification result email to
User.first
with the error.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.