Skip to content

Commit

Permalink
Merge pull request #34 from ib31iat/master
Browse files Browse the repository at this point in the history
Fix Github Actions
  • Loading branch information
sudoremo authored Jul 8, 2024
2 parents 58ec866 + 9730ff5 commit 301d291
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: nick-fields/retry@v2
with:
timeout_seconds: 120
retry_on: error
retry_on: any
max_attempts: 3
command: bundle exec rake test TESTOPTS='--verbose'

Expand All @@ -54,4 +54,4 @@ jobs:
ruby-version: 2.5.1
bundler-cache: true
- name: Run rubocop
run: bundle exec rubocop
run: bundle exec rubocop
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Workhorse Changelog

## unreleased - 2024-07-08

* Change `retry-on` in actions to `any`: also retry when the action hits a timeout

* Comply with RuboCop

## 1.2.21 - 2024-07-02

* Add active record release to `create_table_jobs` migration
Expand Down
4 changes: 2 additions & 2 deletions lib/workhorse/performer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(db_job_id, worker)
end

def perform
begin
begin # rubocop:disable Style/RedundantBegin
fail 'Performer can only run once.' if @started
@started = true
perform!
Expand All @@ -21,7 +21,7 @@ def perform
private

def perform!
begin
begin # rubocop:disable Style/RedundantBegin
Thread.current[:workhorse_current_performer] = self

ActiveRecord::Base.connection_pool.with_connection do
Expand Down
22 changes: 11 additions & 11 deletions lib/workhorse/poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def clean_stuck_jobs!

# Get pids without active process
orphaned_pids = job_pids.select do |pid|
begin
begin # rubocop:disable Style/RedundantBegin
Process.getpgid(pid)
false
rescue Errno::ESRCH
Expand Down Expand Up @@ -141,7 +141,7 @@ def sleep
end

def with_global_lock(name: :workhorse, timeout: 2, &_block)
begin
begin # rubocop:disable Style/RedundantBegin
if @is_oracle
result = Workhorse::DbJob.connection.select_all(
"SELECT DBMS_LOCK.REQUEST(#{ORACLE_LOCK_HANDLE}, #{ORACLE_LOCK_MODE}, #{timeout}) FROM DUAL"
Expand Down Expand Up @@ -169,17 +169,17 @@ def with_global_lock(name: :workhorse, timeout: 2, &_block)
@max_global_lock_fails_reached = true

worker.log 'Could not obtain global lock, retrying with next poll. ' \
'This will be the last such message for this worker until ' \
'the issue is resolved.', :warn
'This will be the last such message for this worker until ' \
'the issue is resolved.', :warn

message = "Worker reached maximum number of consecutive times (#{Workhorse.max_global_lock_fails}) " \
"where the global lock could no be acquired within the specified timeout (#{timeout}). " \
'A worker that obtained this lock may have crashed without ending the database ' \
'connection properly. On MySQL, use "show processlist;" to see which connection(s) ' \
'is / are holding the lock for a long period of time and consider killing them using ' \
"MySQL's \"kill <Id>\" command. This message will be issued only once per worker " \
'and may only be re-triggered if the error happens again *after* the lock has ' \
'been solved in the meantime.'
"where the global lock could no be acquired within the specified timeout (#{timeout}). " \
'A worker that obtained this lock may have crashed without ending the database ' \
'connection properly. On MySQL, use "show processlist;" to see which connection(s) ' \
'is / are holding the lock for a long period of time and consider killing them using ' \
"MySQL's \"kill <Id>\" command. This message will be issued only once per worker " \
'and may only be re-triggered if the error happens again *after* the lock has ' \
'been solved in the meantime.'

worker.log message
exception = StandardError.new(message)
Expand Down
2 changes: 1 addition & 1 deletion lib/workhorse/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def post
active_threads.increment

@executor.post do
begin
begin # rubocop:disable Style/RedundantBegin
yield
ensure
active_threads.decrement
Expand Down
4 changes: 2 additions & 2 deletions lib/workhorse/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ def idle
end

def perform(db_job_id)
begin
begin # rubocop:disable Style/RedundantBegin
mutex.synchronize do
assert_state! :running
log "Posting job #{db_job_id} to thread pool"

@pool.post do
begin
begin # rubocop:disable Style/RedundantBegin
Workhorse::Performer.new(db_job_id, self).perform
rescue Exception => e
log %(#{e.message}\n#{e.backtrace.join("\n")}), :error
Expand Down

0 comments on commit 301d291

Please sign in to comment.