Skip to content

Commit

Permalink
ready for v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
attdona committed Dec 3, 2023
1 parent df3260c commit bc608ba
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 73 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Change Log

## 0.2.0 (3 December, 2023)

- Renamed functions:
- is_shutdown=>isshutdown
- is_request=>isrequest
- if_restart=>ifrestart

- Add `handler` keyword arg to supervise. `handler` value is a callback function for handling process lifecycles events. Currently manages events are task exceptions and `ProcessFatal`.

- Removed `supervisor_shutdown` in case of a `ProcessFatal` exception. This implies that the other processes continue to run despite the process that thrown `ProcessFatal` will never restart.

- Log a warn message when starting a process task throws a MethodError exception.

- New function `isprocstarted`: check if process task is running.

- @isshutdown macro.

## 0.1.0 (November 13, 2023)

- Initial release.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ In the above example the `printer` function is the supervised task function of t

Applications messages sent to the task and the `Shutdown` control message are received from the `td.inbox` Channel.

To check for a termination request use the method `is_shutdown`:
To check for a termination request use the method `isshutdown`:

```julia
function mytask(td)
for msg in td.inbox
if is_shutdown(msg)
if isshutdown(msg)
break
end
# process application messages
Expand All @@ -127,7 +127,7 @@ function mytask(td)
end
```

If the task is only interested in checking for shutdown request then the method `is_shutdown(td)` suffice, but in this case remember that other messages in the process inbox are silently discarded.
If the task is only interested in checking for shutdown request then the method `isshutdown(td)` suffice, but in this case remember that other messages in the process inbox are silently discarded.

`simple-process.jl`:

Expand All @@ -142,7 +142,7 @@ function worker(td; steps=15, check_interrupt_every=Inf)
@info "[$(td.id)]: doing $i ..."
sleep(0.5)
if i % check_interrupt_every == 0
if is_shutdown(td)
if isshutdown(td)
return
end
end
Expand Down Expand Up @@ -174,7 +174,7 @@ To send application messages the standard Channel api may be used or the utiliti
* `cast(td, "path.to.target", message)`: send a message to the node with full name `path.to.target`.
* `call(td, "path.to.target", request)`: send a request to and wait for a response.
* `is_request(message)`: check if `message` is a request.
* `isrequest(message)`: check if `message` is a request.
* `reply(message, response)`: send the `response` to the `call` method that issued the `message` request .
The following example shows the mechanics of inter-task communication.
Expand All @@ -196,11 +196,11 @@ end
function db_service(td)
@info "[$td] starting"
for msg in td.inbox
if is_shutdown(msg)
if isshutdown(msg)
break
elseif isa(msg, CounterMsg)
@info "[$td] got message: $msg"
elseif is_request(msg)
elseif isrequest(msg)
if isa(msg.request, ControllerMsg)
reply(msg, :on)
end
Expand All @@ -218,7 +218,7 @@ function app_counter(td)
while true
sleep(2)
if is_shutdown(td)
if isshutdown(td)
break
end
# send a data message to db_service process
Expand All @@ -236,7 +236,7 @@ function app_controller(td)
while true
sleep(2)
if is_shutdown(td)
if isshutdown(td)
break
end
Expand Down
16 changes: 8 additions & 8 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end
function level_1_task(td)
@info "starting $td"
for msg in td.inbox
if is_shutdown(msg)
if isshutdown(msg)
break
elseif isa(msg, AppData)
@info "$td recv: $msg"
Expand All @@ -46,7 +46,7 @@ function level_2_task(td)
n = 0
while true
sleep(0.5)
if is_shutdown(td)
if isshutdown(td)
break
end
# send a data message to process named level_1_task
Expand Down Expand Up @@ -78,27 +78,27 @@ A [Process](@ref) is a supervised task that is started/stopped in a deterministi
A process task function has a mandatory first argument that is a task descriptor `td` value that:
* check if a shutdown request is pending with `is_shutdown`;
* check if a shutdown request is pending with `isshutdown`;
* receive messages from the `inbox` Channel;
```julia
function level_2_task(td)
while true
# do something ...
if is_shutdown(td)
if isshutdown(td)
break
end
end
end
```
If the task function is designed to receive messages the argument of `is_shutdown` MUST BE the message and not the `task` object:
If the task function is designed to receive messages the argument of `isshutdown` MUST BE the message and not the `task` object:
```julia
function level_1_task(td)
for msg in td.inbox
# check if it is a shutdown request
if is_shutdown(msg)
if isshutdown(msg)
break
elseif isa(msg, AppMessage)
# do something with the application message
Expand Down Expand Up @@ -147,7 +147,7 @@ function consumer(td)
msg = take!(td.inbox)
# Check if msg is the shutdown control message ...
!is_shutdown(msg) || break
!isshutdown(msg) || break
println(msg)
if msg == 5
Expand All @@ -169,7 +169,7 @@ function producer(td)
cast("consumer", count)
# check if was requested a shutdown (for example by SIGINT signal)
!is_shutdown(td) || break
!isshutdown(td) || break
count += 1
end
Expand Down
2 changes: 1 addition & 1 deletion docs/src/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ using Visor

function server(self)
for msg in self.inbox
is_shutdown(msg) && break
isshutdown(msg) && break
put!(msg.inbox, msg.request*2)
end
end
Expand Down
2 changes: 1 addition & 1 deletion examples/call.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Visor

function server(task)
for msg in task.inbox
is_shutdown(msg) && break
isshutdown(msg) && break
put!(msg.inbox, msg.request * 2)
end
println("server done")
Expand Down
8 changes: 4 additions & 4 deletions examples/introduction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ function db_service(td)
@info "[$td] starting"
try
for msg in td.inbox
if is_shutdown(msg)
if isshutdown(msg)
break
elseif isa(msg, CounterMsg)
@info "[$td] got message: $msg"
elseif is_request(msg)
elseif isrequest(msg)
if isa(msg.request, ControllerMsg)
reply(msg, :on)
end
Expand All @@ -33,7 +33,7 @@ function app_counter(td)
n = 0
while true
sleep(2)
if is_shutdown(td)
if isshutdown(td)
break
end
# send a data message to process named db_service
Expand All @@ -47,7 +47,7 @@ function app_controller(td)
@info "[$td] starting"
while true
sleep(2)
if is_shutdown(td)
if isshutdown(td)
break
end
response = call("db_service", ControllerMsg("select status from ..."))
Expand Down
2 changes: 1 addition & 1 deletion examples/multiples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function worker(self; steps=15, check_interrupt_every=Inf)
sleep(0.5)
if i % check_interrupt_every == 0
@info "[$(self.id)]: checkpoint for shutdown request"
if Visor.is_shutdown(self)
if Visor.isshutdown(self)
return nothing
end
end
Expand Down
4 changes: 2 additions & 2 deletions examples/producer_consumer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function consumer(self)
msg = take!(self.inbox)

# Check if msg is the shutdown control message ...
!is_shutdown(msg) || break
!isshutdown(msg) || break

println(msg)
if msg == 5
Expand All @@ -32,7 +32,7 @@ function producer(self)
cast("consumer", count)

# check if was requested a shutdown (for example by SIGINT signal)
!is_shutdown(self) || break
!isshutdown(self) || break

count += 1
end
Expand Down
4 changes: 2 additions & 2 deletions examples/publisher_tcp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function publisher(self)
msg = fetch(self.inbox)

# Check if msg is the shutdown control message ...
!is_shutdown(msg) || break
!isshutdown(msg) || break

# otherwise send the data
if isopen(sock)
Expand All @@ -47,7 +47,7 @@ function producer(self)
cast("publisher", count)

# check if was requested a shutdown (for example by SIGINT signal)
!is_shutdown(self) || break
!isshutdown(self) || break

count += 1
end
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_interruptable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function worker(self, steps=15, check_interrupt_every=Inf)
sleep(1)
if i % check_interrupt_every == 0
@info "[$(self.id)]: checkpoint for shutdown request"
if Visor.is_shutdown(self)
if Visor.isshutdown(self)
return nothing
end
end
Expand Down
2 changes: 1 addition & 1 deletion examples/stop_process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using Visor
function fair_task(self)
while true
println("[$(self.id)] checkpoint ...")
if is_shutdown(self)
if isshutdown(self)
println("[$(self.id)] cleanup and resources deallocation")
break
end
Expand Down
Loading

2 comments on commit bc608ba

@attdona
Copy link
Member Author

@attdona attdona commented on bc608ba Dec 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96380

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" bc608bab81464bbb54367207c13e8ea0879656cb
git push origin v0.2.0

Please sign in to comment.