[REFACTOR] Refactor Scheduler following Clean Architecture#988
[REFACTOR] Refactor Scheduler following Clean Architecture#988adrianq merged 13 commits intodevelopmentfrom
Conversation
|
Task linked: CU-8698310pt Refactor Scheduler |
…cRuleJobConfigD2Repository
9sneha-n
left a comment
There was a problem hiding this comment.
@anagperal Awesome first PR for refactor.
Some comments below, we will probably need architect's opinion for some of them, then we can make it a standard and use it in all the next refactor PRs.
| @@ -0,0 +1,27 @@ | |||
| import { Instance } from "../../domain/instance/entities/Instance"; | |||
There was a problem hiding this comment.
Shall we add a decorator for all refactored files? So that we can keep track of all the files that are pending refactor?
There was a problem hiding this comment.
I have added comments on the refactored files and TODOs commenting on what they need to be fully refactored. Also in PR I have added some common reactoring tasks
| export class SyncRuleJobConfigD2ApiRepository implements SyncRuleJobConfigRepository { | ||
| private dataStoreClient: StorageDataStoreClient; | ||
|
|
||
| constructor(private instance: Instance) { |
There was a problem hiding this comment.
currently in our projects, we are pass private api: D2Api to all repo constructors and then get the dataStoreClient from it. I am not sure why that is used instead of instance. We can check with Arnau and if that is recommended, shall we start using that pattern in all refactored repos?
There was a problem hiding this comment.
Code comment and task added for future implementation
| public schedulerRepository(instance: Instance) { | ||
| const config = this.configRepository(instance); | ||
| return this.get<SchedulerRepositoryConstructor>(Repositories.SchedulerRepository, [config]); | ||
| public schedulerExecutionInfoRepository(instance: Instance) { |
There was a problem hiding this comment.
do we need to use this concept of repository-factory? I dont see it in our standard apps. We can create a separate PR to handle these "common" refactors, just making a note here for us.
There was a problem hiding this comment.
Code comment and task added for future implementation
| import { Instance } from "../../instance/entities/Instance"; | ||
| import { SchedulerExecutionInfo } from "../entities/SchedulerExecutionInfo"; | ||
|
|
||
| export interface SchedulerExecutionInfoRepositoryConstructor { |
There was a problem hiding this comment.
Again this comment in for separate PR for "common" refactor - should we used this concept of Constructor ?
There was a problem hiding this comment.
Code comment and task added for future implementation
| export class GetLastSchedulerExecutionInfoUseCase implements UseCase { | ||
| constructor(private repositoryFactory: RepositoryFactory, private localInstance: Instance) {} | ||
|
|
||
| public execute(): Promise<SchedulerExecutionInfo> { |
There was a problem hiding this comment.
can we use Future instead of Promise? If its too big a change, we can add a note for future refactor and take care of it in separate PR
There was a problem hiding this comment.
I have added new Future entity and changed from Promise to Future
| import { FileRulesDefaultRepository } from "../data/rules/FileRulesDefaultRepository"; | ||
| import { RulesD2ApiRepository } from "../data/rules/RulesD2ApiRepository"; | ||
| import { SchedulerD2ApiRepository } from "../data/scheduler/SchedulerD2ApiRepository"; | ||
| import { SchedulerExecutionInfoD2ApiRepository } from "../data/scheduler/SchedulerExecutionInfoD2ApiRepository"; |
There was a problem hiding this comment.
common refactor note - We need to move to current way of implementing Composition root
There was a problem hiding this comment.
Code comment and task added for future implementation
src/scheduler/SchedulerPresenter.ts
Outdated
| import { SchedulerExecutionInfo } from "../domain/scheduler/entities/SchedulerExecutionInfo"; | ||
| import { Logger } from "./entities/Logger"; | ||
|
|
||
| export class SchedulerPresenter { |
There was a problem hiding this comment.
is SchedulerPresenter name too generic? Should we rename to something like SchedulerCLI or something similar?
src/scheduler/SchedulerPresenter.ts
Outdated
|
|
||
| // Format date to keep timezone offset | ||
| const nextDate = moment(job.nextExecution.toISOString()).toISOString(true); | ||
| this.options.logger.info("scheduler", `Scheduling new sync rule ${name} (${id}) at ${nextDate}`); |
There was a problem hiding this comment.
if we deconstruct options in the beginning one time, code would be more readable without all the 'this.options.' no?
| @@ -0,0 +1,6 @@ | |||
| export type ScheduledJob = { | |||
There was a problem hiding this comment.
Should these entities be moved to domain layer?
| @@ -0,0 +1,7 @@ | |||
| import { ScheduledJob } from "./ScheduledJob"; | |||
|
|
|||
| export interface SchedulerContract { | |||
There was a problem hiding this comment.
i have note seen interfaces with functions used in this way in our standard apps. Shall we check if this type of usage is recommended or needs to be changed?
There was a problem hiding this comment.
I would change this together with @xurxodev PR comments because I think this is more related with the architecture
Thanks for all the comments @9sneha-n ! I have added comments in code and in the PR for common refactor tasks that we need to do in the future, also I have added them in the whiteboard of MD Sync (CC @adrianq). |
xurxodev
left a comment
There was a problem hiding this comment.
thanks @anagperal
I leave things to change that we have seen in the live review:
- SyncRuleJobConfigD2ApiRepository and the use case that invoke it doesn't make sense. Better to use ListRulesUseCase passing required filter to avoid duplicate logic to retrive
- Move contracts used by SchedulerCli from domain to near of schedulerCli. This contracts are only used by SchedulerCli and it's contracts of presentation.
- Maybe make sense in the scheduler use cases pass directly the required repository because here the instance is not dynamic
- For tests better to use ts-mockito to create test doubles as we saw in the coding dojo
…rom list rules usecase. Improve tests and enabled filter name
Thanks @xurxodev!! All done except the part about changing the tests to use ts-mockito as you are adding it to another PR. I have noted this task for the future: Improve and refactor Scheduler tests using ts-mockito and adding integration tests to also add some integration testing to test syncs between two instances using the scheduler |
📌 References
📝 New refactor tasks
📝 Implementation
📹 Screenshots/Screen capture
🔥 Is there anything the reviewer should know to test it?
yarn start-scheduler -c config.json📑 Others
Any change in the GUI library? If so, what branch/PR?
Any change in the D2 Api? If so, what branch/PR?