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

reset job failed flag #3

Merged
merged 5 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Reset the `job.opts[:failed]` flag after a failed job [@arlantir]
- Restoring tests [@arlantir]

### Changed

- Refactoring tests [@arlantir]

## 0.2.0 (2022-10-19)

### Added
Expand All @@ -27,3 +36,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

[@skryukov]: https://github.com/skryukov
[@bibendi]: https://github.com/bibendi
[@arlantir]: https://github.com/arlantir
2 changes: 2 additions & 0 deletions lib/yabeda/schked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def self.job_name(job)
labels = {success: !job.opts[:failed], name: job_name(job)}
Yabeda.schked.job_execution_runtime.measure(labels, job.last_work_time.round(3))
Yabeda.schked.jobs_executed_total.increment(labels)
ensure
job.opts[:failed] = false
end

::Schked.config.register_callback(:on_error) do |job|
Expand Down
6 changes: 3 additions & 3 deletions spec/support/schedule.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

at "2020-01-01 00:00:00", as: "SuccessfulJob", blocking: true do
cron "*/30 * * * *", as: "SuccessfulJob", blocking: true do
:ok
end

at "2020-01-01 00:00:00", as: "FailedJob", blocking: true do
cron "*/30 * * * *", as: "FailedJob", blocking: true do
raise StandardError, "Boom!"
end

at "2020-01-01 00:00:00", tag: "without_name", blocking: true do
cron "*/30 * * * *", tag: "without_name", blocking: true do
:ok
end
38 changes: 30 additions & 8 deletions spec/yabeda/schked_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,40 @@
let(:worker) { Schked.worker.tap(&:pause) }
let(:job) { worker.job(job_name) }

before do
Yabeda.schked.jobs_executed_total.values.clear
Yabeda.schked.job_execution_runtime.values.clear
end

context "when job is successful" do
let(:job_name) { "SuccessfulJob" }

it "measures called job" do
Yabeda.schked.jobs_executed_total.values.clear
Yabeda.schked.job_execution_runtime.values.clear
job.trigger_off_schedule

expect(Yabeda.schked.jobs_executed_total.values).to include(
{name: job_name, success: true} => 1
)
expect(Yabeda.schked.job_execution_runtime.values).to include(
{name: job_name, success: true} => kind_of(Numeric)
)
end
end

context "when job fails on first call but succeeds on second" do
let(:job_name) { "SuccessfulJob" }

it "measures the job with failure and success" do
job.opts[:failed] = true

job.trigger_off_schedule

expect(Yabeda.schked.jobs_executed_total.values).to include(
{name: job_name, success: false} => 1
)
expect(Yabeda.schked.job_execution_runtime.values).to include(
{name: job_name, success: false} => kind_of(Numeric)
)

job.trigger_off_schedule

Expand All @@ -31,9 +59,6 @@
let(:job_name) { "FailedJob" }

it "measures called job" do
Yabeda.schked.jobs_executed_total.values.clear
Yabeda.schked.job_execution_runtime.values.clear

job.trigger_off_schedule

expect(Yabeda.schked.jobs_executed_total.values).to include(
Expand All @@ -49,9 +74,6 @@
let(:job_name) { nil }

it "measures called job" do
Yabeda.schked.jobs_executed_total.values.clear
Yabeda.schked.job_execution_runtime.values.clear

expect { job.trigger_off_schedule }.to output(
/Warning: No name specified for the job/
).to_stderr
Expand Down