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

Add lifecycle hooks for Executor #7

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

kakubin
Copy link
Contributor

@kakubin kakubin commented Nov 18, 2024

Issue #, if available:

In order to use job-iteration and maintenance_tasks with aws-activejob-sqs, it should have the functionality for broadcasting terminal events.
these would be used for job-iteration to know when the worker is going to stop.

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.

these would be needed for job-iteration to know when the worker is going to stop.
@mullermp
Copy link
Contributor

Thanks for opening a pull request. On the surface, this makes sense. I looked around in the source code for job-iteration. I'm wondering, could you show me specifically where lifecycle hooks are necessary? It seems that they only require jobs to have the enumerable interfaces. My other question is - does an sqs adapter need to be added to their gem?

As far as testing goes, does it make sense to have a test dependency on job-iteration and write a higher level test using it? Otherwise it's not entirely clear why we have lifecycle hooks. Perhaps also adding an entry to the readme about how to stop (and resume?) jobs.

@kakubin
Copy link
Contributor Author

kakubin commented Nov 19, 2024

In job-iteration, JobIteration::Iteration#job_should_exit?(which module will be included to ApplicationJob) is called for each iteration of a job to check whether the processing could continue.

The interruption adapter referenced there needs to reflect the state of the worker, and an adapter is required for each job's backend implementation.

does an sqs adapter need to be added to their gem?

Partially yes.
Below is the specific code I have in mind:

module JobIteration
  module InterruptionAdapters
    module SqsAdapter
      class << self
        attr_accessor :stopping

        def call
          stopping
        end
      end

      Aws::ActiveJob::SQS.on_worker_stop do
        SqsAdapter.stopping = true
      end
    end

    register(:sqs, SqsAdapter)
  end
end

It seems that aws-activejob-sqs does not have an interface to reference the worker's state from the outside, so I wanted to add a hook for this purpose. I wasn't sure whether to include this adapter here or have it added to their gem, so I decided to limit the change to adding the hook for now.
As for preparing tests for job-iteration, it depends on where the adapter exists.

Copy link
Contributor

@alextwoods alextwoods 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 adding these - I agree adding the stop life cycle hook makes sense for this. I have a slight preference for the adapters living in their gems instead of in here, but either way, we should be able to merge this change

@kakubin
Copy link
Contributor Author

kakubin commented Nov 26, 2024

@mullermp
I will ask them after merged.
Please tell me if there's anything I can do now.

@alextwoods alextwoods merged commit 14d5ffa into aws:main Dec 2, 2024
15 checks passed
@kakubin kakubin deleted the add_lifecycle_hooks_for_stop branch December 3, 2024 22:59
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.

3 participants