Skip to content

Commit

Permalink
fix(single_job): fix multiple minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Oct 13, 2023
1 parent b26eeb1 commit 98ca91a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,18 @@
"config": {
"type": "PLUGINS:dm-core-plugins/job/JobConfig",
"jobTargetAddress": {
"type": "PLUGINS:dm-core-plugins/job/JobTargetAddress",
"jobAddress": ".job",
"jobAddressScope": "local"
"type": "PLUGINS:dm-core-plugins/job/TargetAddress",
"targetAddress": ".job",
"addressScope": "local"
},
"label": "signal job",
"runner": {
"type": "dmss://DemoDataSource/apps/MySignalApp/models/SignalGeneratorJob"
},
"outputTarget": ".signal",
"jobInput": {
"type": "PLUGINS:dm-core-plugins/job/JobInput",
"_type": "dmss://system/SIMOS/Reference",
"referenceType": "link",
"jobInputAddress": ".study.cases[0]",
"jobInputAddressScope": "local"
"type": "PLUGINS:dm-core-plugins/job/TargetAddress",
"targetAddress": "."
}
}
},
Expand Down
21 changes: 11 additions & 10 deletions example/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
MONGO_INITDB_ROOT_PASSWORD: xd7wCEhEx4kszsecYFfC
SECRET_KEY: sg9aeUM5i1JO4gNN8fQadokJa3_gXQMLBjSGGYcfscs= # Don't reuse this in production...
DATA_SOURCE_FILES: '{ "name": "system", "repositories": { "db": { "type": "mongo-db", "host": "db", "port": 27017, "username": "root", "password": "xd7wCEhEx4kszsecYFfC", "tls": false, "database": "DMSS-core", "collection": "DMSS-core" } }}'
RESET_DATA_SOURCE: off
# volumes:
# - ../../data-modelling-storage-service/src:/code/src
ports:
Expand Down Expand Up @@ -55,16 +56,16 @@ services:
ports:
- '5001:5000'

# db-ui:
# image: mongo-express:1.0.0-alpha
# restart: unless-stopped
# ports:
# - "8082:8081"
# environment:
# ME_CONFIG_MONGODB_SERVER: db
# ME_CONFIG_MONGODB_ADMINUSERNAME: maf
# ME_CONFIG_MONGODB_ADMINPASSWORD: maf
# ME_CONFIG_MONGODB_ENABLE_ADMIN: "true"
# db-ui:
# image: mongo-express:1.0.0-alpha
# restart: unless-stopped
# ports:
# - "8082:8081"
# environment:
# ME_CONFIG_MONGODB_SERVER: db
# ME_CONFIG_MONGODB_ADMINUSERNAME: root
# ME_CONFIG_MONGODB_ADMINPASSWORD: xd7wCEhEx4kszsecYFfC
# ME_CONFIG_MONGODB_ENABLE_ADMIN: "true"

job-store:
image: redis:6.2.5-alpine
Expand Down
7 changes: 4 additions & 3 deletions packages/dm-core-plugins/blueprints/job/JobConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
{
"name": "outputTarget",
"type": "CORE:BlueprintAttribute",
"attributeType": "string"
"attributeType": "string",
"optional": true
},
{
"name": "label",
Expand All @@ -26,12 +27,12 @@
{
"name": "jobTargetAddress",
"type": "CORE:BlueprintAttribute",
"attributeType": "PLUGINS:dm-core-plugins/job/JobTargetAddress"
"attributeType": "PLUGINS:dm-core-plugins/job/TargetAddress"
},
{
"name": "jobInput",
"type": "CORE:BlueprintAttribute",
"attributeType": "PLUGINS:dm-core-plugins/job/JobInput"
"attributeType": "PLUGINS:dm-core-plugins/job/TargetAddress"
}
]
}
34 changes: 0 additions & 34 deletions packages/dm-core-plugins/blueprints/job/JobInput.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "JobTargetAddress",
"name": "TargetAddress",
"type": "CORE:Blueprint",
"description": "",
"attributes": [
Expand All @@ -9,12 +9,14 @@
"attributeType": "string"
},
{
"name": "jobAddressScope",
"name": "addressScope",
"type": "CORE:BlueprintAttribute",
"attributeType": "string"
"attributeType": "string",
"optional": true,
"default": "local"
},
{
"name": "jobAddress",
"name": "targetAddress",
"type": "CORE:BlueprintAttribute",
"attributeType": "string"
}
Expand Down
67 changes: 30 additions & 37 deletions packages/dm-core-plugins/src/job/JobPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
GetJobResultResponse,
IUIPlugin,
JobStatus,
splitAddress,
TJob,
TJobHandler,
useDMSS,
useJob,
} from '@development-framework/dm-core'
Expand All @@ -24,49 +24,45 @@ const JobButtonWrapper = styled.div`
gap: 8px;
`

interface ITargetAddress {
targetAddress: string
addressScope?: 'local' | 'global'
}

interface JobPluginConfig {
jobTargetAddress: {
type: string
jobAddress: string
jobAddressScope: string
}
jobTargetAddress: ITargetAddress
label: string
runner: {
type: string
}
runner: TJobHandler
outputTarget: string
jobInput: {
type: string
_type: string
referenceType: string
jobInputAddress: string
jobInputAddressScope: string
}
jobInput: ITargetAddress
}

export const JobPlugin = (props: IUIPlugin) => {
export const JobPlugin = (props: IUIPlugin & { config: JobPluginConfig }) => {
const {
config,
idReference,
}: { config?: JobPluginConfig; idReference: string } = props
}: { config: JobPluginConfig; idReference: string } = props
const DmssApi = useDMSS()
const defaultTargetOutput = idReference + config?.outputTarget

const jobTargetAddress = (): string => {
if (config?.jobTargetAddress.jobAddressScope === 'local') {
return idReference + config?.jobTargetAddress.jobAddress
if (config.jobTargetAddress.addressScope !== 'local') {
return config.jobTargetAddress.targetAddress
}
if (['self', '.'].includes(config?.jobTargetAddress.targetAddress)) {
return idReference
}
return config?.jobTargetAddress.jobAddress ?? ''
return idReference + config.jobTargetAddress.targetAddress
}

const jobInputAddress = (): string | undefined => {
if (config?.jobInput.jobInputAddressScope === 'local') {
const { dataSource, documentPath } = splitAddress(idReference)
return `dmss://${dataSource}/${documentPath}${config?.jobInput.jobInputAddress}`
const jobInputAddress = (): string => {
if (config.jobInput.addressScope !== 'local') {
return config.jobInput.targetAddress
}
return config?.jobInput.jobInputAddress
if (['self', '.'].includes(config.jobInput.targetAddress)) {
return idReference
}
return idReference + config.jobInput.targetAddress
}
console.log(jobInputAddress())
const { tokenData } = useContext(AuthContext)
const username = tokenData?.preferred_username

Expand All @@ -90,19 +86,16 @@ export const JobPlugin = (props: IUIPlugin) => {
label: config?.label,
type: EBlueprint.JOB,
status: JobStatus.NotStarted,
triggeredBy: username ?? 'unknown user', // TODO: Add propper fallback
triggeredBy: username ?? 'unknown user', // TODO: Add proper fallback
applicationInput: {
type: config?.jobInput._type,
referenceType: config?.jobInput.referenceType,
type: EBlueprint.REFERENCE,
referenceType: 'link',
address: jobInputAddress(),
},
runner: config?.runner,
}

const jobEntityFormData = {
...jobEntity,
outputTarget: defaultTargetOutput,
}
if (config?.outputTarget) jobEntity.outputTarget = config.outputTarget

const updateDocument = async (
jobAddress: string,
Expand Down Expand Up @@ -154,9 +147,9 @@ export const JobPlugin = (props: IUIPlugin) => {
function createNewJob(): Promise<unknown> {
setAllowJobStart(true)
if (jobExists) {
return updateDocument(jobTargetAddress(), jobEntityFormData)
return updateDocument(jobTargetAddress(), jobEntity)
} else {
return addDocument(jobTargetAddress(), jobEntityFormData)
return addDocument(jobTargetAddress(), jobEntity)
}
}

Expand Down

0 comments on commit 98ca91a

Please sign in to comment.