-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert remove-stale-job to TS (#23538)
* chore(ts): migrate remove-stale-jobs to typescript * test: update related test files * fix(type): fix some typecheck errors
- Loading branch information
1 parent
2c75a81
commit b35c398
Showing
7 changed files
with
55 additions
and
34 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
IGatsbyState, | ||
IRemoveStaleJobAction, | ||
IGatsbyJobV2, | ||
} from "../redux/types" | ||
|
||
import { isJobStale } from "../utils/jobs-manager" | ||
import { publicActions, internalActions } from "../redux/actions" | ||
|
||
export const removeStaleJobs = ( | ||
state: IGatsbyState | ||
): IRemoveStaleJobAction[] => { | ||
const actions: IRemoveStaleJobAction[] = [] | ||
|
||
// If any of our finished jobs are stale we remove them to keep our cache small | ||
state.jobsV2.complete.forEach( | ||
(job: IGatsbyJobV2, contentDigest: string): void => { | ||
if (isJobStale(job)) { | ||
actions.push(internalActions.removeStaleJob(contentDigest)) | ||
} | ||
} | ||
) | ||
|
||
// If any of our pending jobs do not have an existing inputPath or the inputPath changed | ||
// we remove it from the queue as they would fail anyway | ||
state.jobsV2.incomplete.forEach(({ job, plugin }: IGatsbyJobV2): void => { | ||
if (isJobStale(job)) { | ||
actions.push(internalActions.removeStaleJob(job.contentDigest)) | ||
} else { | ||
actions.push(publicActions.createJobV2(job, plugin)) | ||
} | ||
}) | ||
|
||
return actions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters