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

fix: set maximum job timeout #244

Merged
merged 1 commit into from
Aug 26, 2024
Merged

fix: set maximum job timeout #244

merged 1 commit into from
Aug 26, 2024

Conversation

rafaelcr
Copy link
Collaborator

Sets and enforces a maximum execution time for individual jobs.
Fixes #243

Copy link

Vercel deployment URL: https://token-metadata-70g6r2zg8-hirosystems.vercel.app 🚀

@@ -43,8 +43,13 @@ export abstract class Job {
// what to do in each case. If we choose to retry, this queue entry will simply not be marked as
// `processed = true` so it can be picked up by the queue at a later time.
try {
await this.handler();
status = DbJobStatus.done;
const success = await resolveOrTimeout(this.handler(), ENV.JOB_QUEUE_TIMEOUT_MS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this times out and returns continues with success==false, what happens to the underlying promise? It doesn't look like there's termination code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part is supposed to be handled by the tookit here: https://github.com/hirosystems/api-toolkit/blob/develop/src/helpers/time.ts#L68
But let me know if you think I should add something extra like an abort controller, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the scenario that seems like it could cause issues:

async function someTask() {
  await sleep(10_000);
  console.log('something happens because task was still going');
}
const success = await resolveOrTimeout(someTask(), 100);
console.log(`Task done, success: ${success}`);

In something like the above, you'd hit the task done, then later on have a dangling side-effect triggered in the background

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 63.63636% with 4 lines in your changes missing coverage. Please review.

Files Patch % Lines
src/token-processor/queue/job/job.ts 55.55% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@rafaelcr rafaelcr merged commit 3444917 into beta Aug 26, 2024
8 of 9 checks passed
@rafaelcr rafaelcr deleted the fix/job-timeout branch August 26, 2024 15:55
blockstack-devops pushed a commit that referenced this pull request Aug 26, 2024
## [1.0.0-beta.5](v1.0.0-beta.4...v1.0.0-beta.5) (2024-08-26)

### Bug Fixes

* set maximum job timeout ([#244](#244)) ([3444917](3444917))
@blockstack-devops
Copy link

🎉 This PR is included in version 1.0.0-beta.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

blockstack-devops pushed a commit that referenced this pull request Aug 26, 2024
## [1.0.0](v0.7.0...v1.0.0) (2024-08-26)

### ⚠ BREAKING CHANGES

* use chainhook to listen for chain events instead of a direct stacks api connection (#200)

### Features

* convert data: image uris into image files and upload to cdn ([#245](#245)) ([903b0aa](903b0aa))

### Bug Fixes

* catch econnreset errors ([#247](#247)) ([51347d6](51347d6))
* set maximum job timeout ([#244](#244)) ([3444917](3444917))
* take only first page of gif images ([#241](#241)) ([334f8c5](334f8c5))
* use bignumber to handle FT supplies ([#239](#239)) ([053d622](053d622))
* use google cloud library for image uploads ([#238](#238)) ([c7f1b43](c7f1b43))
* use prometheus port configured in ENV ([c769d29](c769d29))

### Code Refactoring

* use chainhook to listen for chain events instead of a direct stacks api connection ([#200](#200)) ([2ddb2c7](2ddb2c7)), closes [#229](#229) [#232](#232) [#233](#233) [#234](#234) [#235](#235) [#236](#236)
@blockstack-devops
Copy link

🎉 This PR is included in version 1.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants