Add devloop release examples
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
687cecd67c21cd558c71dc78d15f5caa27fe3f5e- Parents
-
9b6b6b6 - Tree
1bc4c03
687cecd
687cecd67c21cd558c71dc78d15f5caa27fe3f5e9b6b6b6
1bc4c03| Status | File | + | - |
|---|---|---|---|
| M |
.github/workflows/ci.yml
|
3 | 0 |
| A |
example/service_restart_demo.f90
|
40 | 0 |
| A |
example/watch_cycle_demo.f90
|
59 | 0 |
| M |
fpm.toml
|
1 | 1 |
.github/workflows/ci.ymlmodified@@ -68,3 +68,6 @@ jobs: | ||
| 68 | 68 | |
| 69 | 69 | - name: Run test suite |
| 70 | 70 | run: fpm test --verbose |
| 71 | + | |
| 72 | + - name: Run examples | |
| 73 | + run: fpm run --example --all | |
example/service_restart_demo.f90added@@ -0,0 +1,40 @@ | ||
| 1 | +program service_restart_demo | |
| 2 | + use fgof_devloop, only : & | |
| 3 | + FGOF_DEVLOOP_JOB_ACTION_NONE, & | |
| 4 | + FGOF_DEVLOOP_JOB_ACTION_RESTART, & | |
| 5 | + attach_devloop_job, & | |
| 6 | + devloop_change_trigger, & | |
| 7 | + devloop_job_restart_plan, & | |
| 8 | + devloop_service_job, & | |
| 9 | + release_devloop_job | |
| 10 | + use fgof_devloop_types, only : & | |
| 11 | + devloop_job_plan, & | |
| 12 | + devloop_job_spec, & | |
| 13 | + devloop_job_state | |
| 14 | + implicit none | |
| 15 | + | |
| 16 | + type(devloop_job_spec) :: spec | |
| 17 | + type(devloop_job_state) :: job | |
| 18 | + type(devloop_job_plan) :: plan | |
| 19 | + type(devloop_job_plan) :: released_plan | |
| 20 | + | |
| 21 | + spec = devloop_service_job("serve-example", label="example service") | |
| 22 | + job = attach_devloop_job(spec, pid=4242, process_group=4242) | |
| 23 | + plan = devloop_job_restart_plan(job, devloop_change_trigger(1, "source changed")) | |
| 24 | + | |
| 25 | + if (plan%action /= FGOF_DEVLOOP_JOB_ACTION_RESTART) then | |
| 26 | + error stop "running service should plan a restart" | |
| 27 | + end if | |
| 28 | + if (.not. plan%should_stop) error stop "restart plan should stop the old service" | |
| 29 | + if (.not. plan%should_start) error stop "restart plan should start the replacement" | |
| 30 | + | |
| 31 | + call release_devloop_job(job) | |
| 32 | + released_plan = devloop_job_restart_plan(job, devloop_change_trigger(1, "after release")) | |
| 33 | + if (released_plan%action /= FGOF_DEVLOOP_JOB_ACTION_NONE) then | |
| 34 | + error stop "released service should no longer be managed" | |
| 35 | + end if | |
| 36 | + | |
| 37 | + print '(a,i0)', "managed pid: ", plan%pid | |
| 38 | + print '(a)', "restart reason: " // plan%reason | |
| 39 | + print '(a)', "released reason: " // released_plan%reason | |
| 40 | +end program service_restart_demo | |
example/watch_cycle_demo.f90added@@ -0,0 +1,59 @@ | ||
| 1 | +program watch_cycle_demo | |
| 2 | + use fgof_devloop, only : & | |
| 3 | + clear_devloop_options, & | |
| 4 | + devloop_build_command, & | |
| 5 | + devloop_smoke_command, & | |
| 6 | + devloop_summarize_watch_events, & | |
| 7 | + devloop_watch_trigger, & | |
| 8 | + run_devloop_cycle, & | |
| 9 | + start_devloop | |
| 10 | + use fgof_devloop_types, only : & | |
| 11 | + devloop_command_spec, & | |
| 12 | + devloop_options, & | |
| 13 | + devloop_state, & | |
| 14 | + devloop_supervision_result, & | |
| 15 | + devloop_trigger, & | |
| 16 | + devloop_watch_summary | |
| 17 | + use fgof_process, only : & | |
| 18 | + process_options, & | |
| 19 | + shell | |
| 20 | + use fgof_watch_types, only : & | |
| 21 | + FGOF_WATCH_EVT_MODIFIED, & | |
| 22 | + watch_event | |
| 23 | + implicit none | |
| 24 | + | |
| 25 | + type(watch_event) :: events(2) | |
| 26 | + type(devloop_options) :: loop_options | |
| 27 | + type(process_options) :: command_options | |
| 28 | + type(devloop_watch_summary) :: summary | |
| 29 | + type(devloop_trigger) :: trigger | |
| 30 | + type(devloop_state) :: state | |
| 31 | + type(devloop_command_spec) :: build | |
| 32 | + type(devloop_command_spec) :: smoke | |
| 33 | + type(devloop_supervision_result) :: supervision | |
| 34 | + | |
| 35 | + loop_options = clear_devloop_options() | |
| 36 | + command_options = process_options() | |
| 37 | + command_options%capture_stdout = .true. | |
| 38 | + | |
| 39 | + events(1)%kind = FGOF_WATCH_EVT_MODIFIED | |
| 40 | + events(1)%path = "src/app.f90" | |
| 41 | + events(2)%kind = FGOF_WATCH_EVT_MODIFIED | |
| 42 | + events(2)%path = "test/app_test.f90" | |
| 43 | + | |
| 44 | + summary = devloop_summarize_watch_events(events) | |
| 45 | + trigger = devloop_watch_trigger(summary, loop_options, "example watch batch") | |
| 46 | + | |
| 47 | + call start_devloop(state, loop_options) | |
| 48 | + build = devloop_build_command(shell("printf build-ok"), command_options, "example build") | |
| 49 | + smoke = devloop_smoke_command(shell("printf smoke-ok"), command_options, "example smoke") | |
| 50 | + supervision = run_devloop_cycle(state, trigger, build_command=build, smoke_command=smoke) | |
| 51 | + | |
| 52 | + if (.not. supervision%succeeded) error stop "example devloop cycle should succeed" | |
| 53 | + if (supervision%command_count /= 2) error stop "example should run build and smoke" | |
| 54 | + | |
| 55 | + print '(a,i0)', "cycle id: ", supervision%cycle%id | |
| 56 | + print '(a,i0)', "changed files: ", supervision%cycle%change_count | |
| 57 | + print '(a)', "build stdout: " // supervision%build%process%stdout | |
| 58 | + print '(a)', "smoke stdout: " // supervision%smoke%process%stdout | |
| 59 | +end program watch_cycle_demo | |
fpm.tomlmodified@@ -9,7 +9,7 @@ description = "Watch-driven development loop helpers for modern Fortran tools" | ||
| 9 | 9 | [build] |
| 10 | 10 | auto-executables = false |
| 11 | 11 | auto-tests = true |
| 12 | -auto-examples = false | |
| 12 | +auto-examples = true | |
| 13 | 13 | |
| 14 | 14 | [install] |
| 15 | 15 | library = true |