-
Notifications
You must be signed in to change notification settings - Fork 1
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
[TM-1531] add job connection #745
Open
egrojMonroy
wants to merge
25
commits into
staging
Choose a base branch
from
feat/TM-1531-add-job-connection
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
aa5b7e6
[TM-1531] add job service url and script
egrojMonroy 153050a
[TM-1531] apiSlice add job resource
egrojMonroy fa4d2c4
[TM-1531] updates for job service
egrojMonroy 9fbece2
[TM-1531] sort alphabetical
egrojMonroy 8303877
[TM-1531] add connection for list the delayed jobs
egrojMonroy 06783b3
[TM-1531] remove unnecesary code and consistency in selector and API …
egrojMonroy 4972958
[TM-1531] Merge branch 'staging' into feat/TM-1531-add-job-connection
egrojMonroy e8cef37
[TM-1531] add bulk update call on clear
egrojMonroy ded0b85
[TM-1531] add entityname and display data in notification
egrojMonroy c8d7c71
[TM-1531] use store and display only not acknowledged
egrojMonroy 07e2d56
[TM-1531] remove from apifetcher call and add continous call for dela…
egrojMonroy 9d45753
[TM-1531] Merge branch 'staging' into feat/TM-1531-add-job-service
egrojMonroy 05fdae6
[TM-1531] Merge branch 'feat/TM-1531-add-job-service' into feat/TM-15…
egrojMonroy 4637c98
[TM-1531] rollback apifetcher functionality
egrojMonroy e58c0a1
[TM-1531] adding message to notification
egrojMonroy 996d5a7
[TM-1531] display error messages in notifications
egrojMonroy b6e0102
[TM-1531] add error messages for failed jobs
egrojMonroy fc1a52a
[TM-1531] improve connection and remove awaits and asyncs
egrojMonroy 69d08d7
[TM-1531] changes and remove log
egrojMonroy d5ba353
[TM-1531] Merge branch 'release/utltimate-ulmus' into feat/TM-1531-ad…
egrojMonroy 042ecbc
[TM-1531] yarn generate:services
egrojMonroy 06a7958
[TM-1531] divide names loading for connections
egrojMonroy 6cad9a9
[TM-1531] running with build
egrojMonroy af9b8da
[TM-1531] only send not pending
egrojMonroy 1b73259
[TM-1531] fix loaded delayedjobs and filter
egrojMonroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { useEffect } from "react"; | ||
import { createSelector } from "reselect"; | ||
|
||
import { bulkUpdateJobs, listDelayedJobs } from "@/generated/v3/jobService/jobServiceComponents"; | ||
import { | ||
bulkUpdateJobsFetchFailed, | ||
bulkUpdateJobsIsFetching, | ||
listDelayedJobsFetchFailed | ||
} from "@/generated/v3/jobService/jobServicePredicates"; | ||
import { DelayedJobData, DelayedJobDto } from "@/generated/v3/jobService/jobServiceSchemas"; | ||
import { useConnection } from "@/hooks/useConnection"; | ||
import { ApiDataStore } from "@/store/apiSlice"; | ||
import { Connection } from "@/types/connection"; | ||
import { connectionLoader } from "@/utils/connectionShortcuts"; | ||
|
||
type DelayedJobsConnection = { | ||
delayedJobs?: DelayedJobDto[]; | ||
delayedJobsIsLoading: boolean; | ||
delayedJobsHasFailed: boolean; | ||
}; | ||
|
||
const delayedJobsSelector = (store: ApiDataStore) => | ||
Object.values(store.delayedJobs ?? {}).map(resource => resource.attributes); | ||
|
||
const delayedJobsLoadFailedSelector = (store: ApiDataStore) => listDelayedJobsFetchFailed(store) != null; | ||
|
||
const delayedJobsIsLoaded = ({ delayedJobs, delayedJobsHasFailed, delayedJobsIsLoading }: DelayedJobsConnection) => | ||
delayedJobs != null || delayedJobsHasFailed; | ||
|
||
const delayedJobsConnection: Connection<DelayedJobsConnection> = { | ||
load: connection => { | ||
if (!delayedJobsIsLoaded(connection)) { | ||
console.log("list call"); | ||
listDelayedJobs(); | ||
} | ||
}, | ||
isLoaded: delayedJobsIsLoaded, | ||
selector: createSelector( | ||
[delayedJobsSelector, delayedJobsLoadFailedSelector], | ||
(delayedJobs, delayedJobsHasFailed) => ({ | ||
delayedJobs, | ||
delayedJobsIsLoading: delayedJobs == null && !delayedJobsHasFailed, | ||
delayedJobsHasFailed | ||
}) | ||
) | ||
}; | ||
|
||
export const useDelayedJobs = () => { | ||
const connection = useConnection(delayedJobsConnection); | ||
|
||
useEffect(() => { | ||
const intervalId = setInterval(() => { | ||
console.log("This call"); | ||
listDelayedJobs(); | ||
}, 1500); | ||
|
||
return () => { | ||
clearInterval(intervalId); | ||
}; | ||
roguenet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, []); | ||
|
||
return connection; | ||
}; | ||
|
||
type BulkUpdateJobsConnection = { | ||
bulkUpdateJobsIsLoading: boolean; | ||
bulkUpdateJobsHasFailed: boolean; | ||
updatedJobsResponse?: DelayedJobDto[]; | ||
}; | ||
|
||
const bulkUpdateJobsSelector = (store: ApiDataStore) => ({ | ||
bulkUpdateJobsIsLoading: bulkUpdateJobsIsFetching(store), | ||
bulkUpdateJobsHasFailed: bulkUpdateJobsFetchFailed(store) != null, | ||
updatedJobsResponse: Object.values(store.delayedJobs ?? {}).map(resource => resource.attributes as DelayedJobDto) | ||
}); | ||
|
||
const bulkUpdateJobsIsLoaded = ({ bulkUpdateJobsIsLoading, bulkUpdateJobsHasFailed }: BulkUpdateJobsConnection) => | ||
!bulkUpdateJobsIsLoading && !bulkUpdateJobsHasFailed; | ||
|
||
const bulkUpdateJobsConnection: Connection<BulkUpdateJobsConnection, { jobs: DelayedJobData[] }> = { | ||
load: (connection, { jobs }) => { | ||
if (!bulkUpdateJobsIsLoaded(connection)) { | ||
bulkUpdateJobs({ body: { data: jobs } }); | ||
} | ||
}, | ||
isLoaded: bulkUpdateJobsIsLoaded, | ||
selector: createSelector( | ||
bulkUpdateJobsSelector, | ||
({ bulkUpdateJobsIsLoading, bulkUpdateJobsHasFailed, updatedJobsResponse }) => ({ | ||
bulkUpdateJobsIsLoading, | ||
bulkUpdateJobsHasFailed, | ||
updatedJobsResponse | ||
}) | ||
) | ||
}; | ||
roguenet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export const useBulkUpdateJobs = connectionLoader(bulkUpdateJobsConnection); | ||
|
||
// Function to trigger bulk update | ||
export const triggerBulkUpdate = (jobs: DelayedJobData[]) => bulkUpdateJobs({ body: { data: jobs } }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause this interval to keep refreshing the delayed jobs for as long as the surrounding component is mounted. Is that intentional? It seems like clearing the interval when all the delayed jobs have completed would be good to keep from continuing to hit the jobs endpoint. I'm OK with letting this live to prod if that's complicated to wire up; it's just not ideal and should be cleaned up in a future ticket.
Please either decide to implement an eventual stop like that in this PR, or see that a tech debt ticket is created to clean up in a future release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed, it is supposed to be attentive for any job created on any session.
Nonetheless I think it might not be good.
So for now the debt ticket will be needed, because we would have to think on the user cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the component using this hook expected to be mounted a lot of the time, or does the user have to go to a specific view for it? If this is up all the time, then I think we need to consider a better approach. If it's a view that's only mounted when the user is actively watching for something to finish, then I think this OK for now.