Skip to content

Commit

Permalink
feat: complete the design of instance constroller
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Apr 28, 2022
1 parent 91e1c20 commit 3caa044
Show file tree
Hide file tree
Showing 20 changed files with 7,912 additions and 6 deletions.
7 changes: 7 additions & 0 deletions packages/instance-controller/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# node_modules
.env
ecosystem.config.js
# dist
data
src
tests
12 changes: 12 additions & 0 deletions packages/instance-controller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
dist

upload
data/*
tmp

.env
.env.local

ecosystem.config.js
.DS_Store
11 changes: 11 additions & 0 deletions packages/instance-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:16-alpine


EXPOSE 9000
WORKDIR /app
ENV LOG_LEVEL=debug
COPY . /app
# RUN npm i
# RUN npm run build
USER node
CMD [ "npm", "run", "start" ]
70 changes: 70 additions & 0 deletions packages/instance-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@


# laf service controller


### Application instance status
```ts
export enum ApplicationInstanceStatus {
CREATED = 'created',
PREPARED_START = 'prepared_start',
STARTING = 'starting',
RUNNING = 'running',
PREPARED_STOP = 'prepared_stop',
STOPPING = 'stopping',
STOPPED = 'stopped',
PREPARED_RESTART = 'prepared_restart',
RESTARTING = 'restarting'
}

```

### instance status machine

`created`: nop

`prepared_start`:
-> loop apps in `prepared_start`
-> start app instance for each
-> update app status to `starting`

`starting`:
-> loop apps in `starting`
-> get instance status for each app
-> update running app status to `running`

`running`: nop

`prepared_stop`:
-> loop apps in `prepared_stop`
-> stop app instance for each
-> update app status to `stopping`

`stopping`:
-> loop apps in `stopping`
-> get instance status for each app
-> update stopped app status to `stopped`

`stopped`: nop

`prepared_restart`:
-> loop apps in `prepared_restart`
-> stop app instance for each
-> update app status to `restarting`

`restarting`:
-> loop apps in `restarting`
-> get instance status for each app
-> start stopped app & update app status to `starting`


### scheduler logic design

- set a timer to execute schedular loop
- call each handlers in loop:
- `prepared_start` handler
- `starting` handler
- `prepared_stop` handler
- `stopping` handler
- `prepared_restart` handler
- `restarting` handler
Loading

0 comments on commit 3caa044

Please sign in to comment.