Skip to content

Commit

Permalink
update docs and add other docker compose services
Browse files Browse the repository at this point in the history
  • Loading branch information
Andykmcc committed Jun 13, 2024
1 parent 3ee605f commit 14d410f
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 24 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ Follow the steps below to use the tool to create your own cutouts. The San Franc
4. Open [config.json](config.json) and add an entry for the extract you'd like to create. Copy an existing entry and replace the values accordingly.
5. [testing] Build the docker container by running:
```
docker build . -t osm-extractor:testing-new-extract
docker build . -t osm-extractor
```
6. [testing] Generate the extract by running the docker container. This should create a new .pbf file in `./volumes/output`.
In your first shell start the temporal server by running
```
docker run -v ./volumes/output:/mnt/output -v ./volumes/input:/mnt/input osm-extractor:testing-new-extract osmium extract -d /mnt/output -c /app/config.json /mnt/input/latest.osm.pbf
temporal server start-dev`
```

In a seprate shell run
```
docker compose up
```
7. Open [http://localhost:8233/namespaces/default/schedules/extract-osm-cutouts-schedule](http://localhost:8233/namespaces/default/schedules/extract-osm-cutouts-schedule) in your browser. Click the arrow in the top right corner of the window, click "trigger", then click "trigger" in the popup modal. This will cause the workflow to run, if it fails it will retry indefinitely.
62 changes: 62 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
services:
osm-extractor-workflow-start:
container_name: osm-extractor-workflow-start
working_dir: /home/node/app
env_file:
- path: .env.development.local
required: true
environment:
TEMPORAL_URL: host.docker.internal
extra_hosts:
- "host.docker.internal:host-gateway"
image: osm-extractor
labels:
- 'app=osm-extractor-workflow-start'
command: ['node', '/app/lib/start-schedule.js']
osm-extractor-worker:
container_name: osm-extractor-worker
working_dir: /home/node/app
Expand All @@ -16,3 +30,51 @@ services:
- ./volumes/input:/mnt/input
- ./volumes/output:/mnt/output
command: ['node', '/app/lib/worker.js']
depends_on:
osm-extractor-workflow-start:
condition: service_completed_successfully
osm-extractor-workflow-delete:
profiles: ['delete']
container_name: osm-extractor-workflow-delete
working_dir: /home/node/app
env_file:
- path: .env.development.local
required: true
environment:
TEMPORAL_URL: host.docker.internal
extra_hosts:
- "host.docker.internal:host-gateway"
image: osm-extractor
labels:
- 'app=osm-extractor-workflow-delete'
command: ['node', '/app/lib/delete-schedule.js']
osm-extractor-workflow-unpause:
profiles: ['unpause']
container_name: osm-extractor-workflow-unpause
working_dir: /home/node/app
env_file:
- path: .env.development.local
required: true
environment:
TEMPORAL_URL: host.docker.internal
extra_hosts:
- "host.docker.internal:host-gateway"
image: osm-extractor
labels:
- 'app=osm-extractor-workflow-unpause'
command: ['node', '/app/lib/unpause-schedule.js']
osm-extractor-workflow-pause:
profiles: ['pause']
container_name: osm-extractor-workflow-pause
working_dir: /home/node/app
env_file:
- path: .env.development.local
required: true
environment:
TEMPORAL_URL: host.docker.internal
extra_hosts:
- "host.docker.internal:host-gateway"
image: osm-extractor
labels:
- 'app=osm-extractor-workflow-pause'
command: ['node', '/app/lib/pause-schedule.js']
21 changes: 21 additions & 0 deletions src/pause-schedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Connection, Client } from '@temporalio/client';

const temporalUrl = process.env.TEMPORAL_URL || 'localhost:7233';

async function run() {
const client = new Client({
connection: await Connection.connect({
address: temporalUrl
}),
});

const handle = client.schedule.getHandle('extract-osm-cutouts-schedule');
await handle.pause();

console.log(`Schedule is now paused.`);
}

run().catch((err) => {
console.error(err);
process.exit(1);
});
49 changes: 27 additions & 22 deletions src/start-schedule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Connection, Client, ScheduleOverlapPolicy } from '@temporalio/client';
import { Connection, Client, ScheduleOverlapPolicy, ScheduleAlreadyRunning} from '@temporalio/client';
import { extract } from './workflows';

const temporalUrl = process.env.TEMPORAL_URL || 'localhost:7233';
Expand All @@ -11,27 +11,32 @@ async function run() {
});

// https://typescript.temporal.io/api/classes/client.ScheduleClient#create
const schedule = await client.schedule.create({
action: {
type: 'startWorkflow',
workflowType: extract,
args: [],
taskQueue: 'schedules',
},
scheduleId: 'extract-osm-cutouts-schedule',
policies: {
catchupWindow: '1 day',
overlap: ScheduleOverlapPolicy.CANCEL_OTHER,
},
spec: {
intervals: [{ every: '1 day' }],
jitter: '2m'
},
});

console.log(`Started schedule '${schedule.scheduleId}'.`);

await client.connection.close();
try {
const schedule = await client.schedule.create({
action: {
type: 'startWorkflow',
workflowType: extract,
args: [],
taskQueue: 'schedules',
},
scheduleId: 'extract-osm-cutouts-schedule',
policies: {
catchupWindow: '1 day',
overlap: ScheduleOverlapPolicy.CANCEL_OTHER,
},
spec: {
intervals: [{ every: '1 day' }],
jitter: '2m'
},
});
console.log(`Started schedule '${schedule.scheduleId}'.`);
} catch (error) {
if (!(error instanceof ScheduleAlreadyRunning)) {
throw error;
}
} finally {
await client.connection.close();
}
}

run().catch((err) => {
Expand Down
21 changes: 21 additions & 0 deletions src/unpause-schedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Connection, Client } from '@temporalio/client';

const temporalUrl = process.env.TEMPORAL_URL || 'localhost:7233';

async function run() {
const client = new Client({
connection: await Connection.connect({
address: temporalUrl
}),
});

const handle = client.schedule.getHandle('extract-osm-cutouts-schedule');
await handle.unpause();

console.log(`Schedule is now paused.`);
}

run().catch((err) => {
console.error(err);
process.exit(1);
});

0 comments on commit 14d410f

Please sign in to comment.