Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server-side events as configuration #1871

Merged
merged 6 commits into from
Feb 1, 2022
Merged

Server-side events as configuration #1871

merged 6 commits into from
Feb 1, 2022

Conversation

ctrekker
Copy link
Collaborator

@ctrekker ctrekker commented Jan 30, 2022

As discussed in the developer call on 1/27, here are a few changes related to server-side event listeners.

List of changes

  • Move event listener to configuration
    • Had to add a MsgPack.to_msgpack for functions that returns null so Pluto doesn't try to serialize the event listener function
  • Update Events.jl docstring with updated instructions
  • Rename event_listener to on_event since its shorter and maybe more descriptive?
  • Assign configuration port if none was provided (see comment below)

Example Usage

import Pluto

# catches unwanted events
function myfn(a::PlutoEvent)
    nothing
end
# catches the notebook `save` event
function myfn(a::FileSaveEvent)
    HTTP.post("https://my.service.com/count_saves")
end

Pluto.run(; on_event=myfn)

Backwards Compatibility

This PR would technically break backwards compatibility. I don't think refactoring everything to kwargs is too bad, but if others think otherwise we can add the following method definition for ServerSession and everything should (I didn't test it) be backwards compatible.

function ServerSession(; event_listener::Function, kwargs...)
    s = ServerSession(; kwargs...)
    s.options.server.on_event = event_listener
    s
end

TODO

  • On server start event that sends port

@github-actions
Copy link
Contributor

Try this Pull Request!

Open Julia and type:

julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/fonsp/Pluto.jl", rev="cb/events-as-config")
julia> using Pluto

@@ -130,6 +130,7 @@ function run(session::ServerSession, pluto_router)
hostIP = parse(Sockets.IPAddr, host)
if port === nothing
port, serversocket = Sockets.listenany(hostIP, UInt16(1234))
session.options.server.port = port
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added this because otherwise server-side event consumers would have no way of knowing what port Pluto is running on. This would only assign the configured port when it is not explicitly provided.

@fonsp fonsp merged commit 2af3d55 into main Feb 1, 2022
@fonsp fonsp deleted the cb/events-as-config branch February 1, 2022 15:48
pankgeorg added a commit that referenced this pull request Feb 8, 2022
> Try this release in your browser! _(Available 30 minutes after the release)_
>
> <a href="https://binder.plutojl.org/v0.18.0/"><img alt="Binder logo" src="https://mybinder.org/badge_logo.svg"></a>

**Generate your own binder links using [pluto-on-binder.glitch.me](https://pluto-on-binder.glitch.me/)!**

[Diff since v0.17.7](v0.17.7...v0.18.0)

**Merged pull requests:**
- Make document currentscript work (#1765) (@dralletje)
- don't count logs messages multiple times for pluto-logs width (#1843) (@Pangoraw)
- Pattern matching system for lezer code (#1849) (@dralletje)
- minor fix: Tables integration caused method ambiguation for Union{}[] (#1851) (@16bitmood)
- Fix #1852, relocatable changes for sysimage usage. (#1853) (@MichaelHatherly)
- Re-enable parseMixed (#1855) (@pankgeorg)
- DOI in REAMDE for citation (#1864) (@rikhuijzer)
- Use pkgdir instead of pathof (#1867) (@rikhuijzer)
- Hide banner in CI (#1868) (@rikhuijzer)
- Server-side events as configuration (#1871) (@ctrekker)
- fix is_stdlib() for nightly and enable nightly tests (#1874) (@Pangoraw)
- Awesome! Line wrapping! (#1876) (@dralletje)
- respect maxlog keyword for logs, fixes #1858 (#1877) (@Pangoraw)
- allow .. as an identifier, fixes #1875 (#1878) (@Pangoraw)
- Server start event (#1882) (@ctrekker)
- Julia 1.6 minimum (#1885) (@fonsp)
- New heuristic to skip intermediate bond values (#1892) (@fonsp)
- Send queued bond changes when last script finishes (#1898) (@fonsp)

**Closed issues:**
- Pkg.jl will corrupt itself on Windows (#671)
- Failure creating JuMP DenseAxisArray (#806)
- Frontend tests fail too often (#1234)
- Open multiple notebooks at start and without browser (#1278)
- Segmentation faults on Julia 1.7 M1 (#1722)
- Table of content overlaps text in static HTML (#1770)
- Pluto hangs when cell contains `(md" ", md"$t")` (#1800)
- Cell drag drop broken in Linux Chrome v97 (#1809)
- Tables integration causes method ambiguities for `pluto_showable` (#1815)
- Segfault with CSV, SQLite, tables (M1) (#1842)
- Use RelocatableFolders.jl instead of project_relative_dir to allow sysimages (#1852)
- Logging doesn't respect `maxlog` (#1858)
- TOC in dark mode is still light when aside (#1860)
- ProgressLogging: suppressed logging in Turing.jl (#1862)
- Cannot update to version 0.17.7 (#1869)
- Stdlib packages marked as not found (#1872)
- EllipsisNotation.jl (`randn((10,10))[1, ..]`) does not work (#1875)
- Too many intermediate bond values (#1891)
pankgeorg added a commit that referenced this pull request Feb 8, 2022
> Try this release in your browser! _(Available 30 minutes after the release)_
>
> <a href="https://binder.plutojl.org/v0.18.0/"><img alt="Binder logo" src="https://mybinder.org/badge_logo.svg"></a>

**Generate your own binder links using [pluto-on-binder.glitch.me](https://pluto-on-binder.glitch.me/)!**

[Diff since v0.17.7](v0.17.7...v0.18.0)

**Merged pull requests:**
- Make document currentscript work (#1765) (@dralletje)
- don't count logs messages multiple times for pluto-logs width (#1843) (@Pangoraw)
- Pattern matching system for lezer code (#1849) (@dralletje)
- minor fix: Tables integration caused method ambiguation for Union{}[] (#1851) (@16bitmood)
- Fix #1852, relocatable changes for sysimage usage. (#1853) (@MichaelHatherly)
- Re-enable parseMixed (#1855) (@pankgeorg)
- DOI in REAMDE for citation (#1864) (@rikhuijzer)
- Use pkgdir instead of pathof (#1867) (@rikhuijzer)
- Hide banner in CI (#1868) (@rikhuijzer)
- Server-side events as configuration (#1871) (@ctrekker)
- fix is_stdlib() for nightly and enable nightly tests (#1874) (@Pangoraw)
- Awesome! Line wrapping! (#1876) (@dralletje)
- respect maxlog keyword for logs, fixes #1858 (#1877) (@Pangoraw)
- allow .. as an identifier, fixes #1875 (#1878) (@Pangoraw)
- Server start event (#1882) (@ctrekker)
- Julia 1.6 minimum (#1885) (@fonsp)
- New heuristic to skip intermediate bond values (#1892) (@fonsp)
- Send queued bond changes when last script finishes (#1898) (@fonsp)

**Closed issues:**
- Pkg.jl will corrupt itself on Windows (#671)
- Failure creating JuMP DenseAxisArray (#806)
- Frontend tests fail too often (#1234)
- Open multiple notebooks at start and without browser (#1278)
- Segmentation faults on Julia 1.7 M1 (#1722)
- Table of content overlaps text in static HTML (#1770)
- Pluto hangs when cell contains `(md" ", md"$t")` (#1800)
- Cell drag drop broken in Linux Chrome v97 (#1809)
- Tables integration causes method ambiguities for `pluto_showable` (#1815)
- Segfault with CSV, SQLite, tables (M1) (#1842)
- Use RelocatableFolders.jl instead of project_relative_dir to allow sysimages (#1852)
- Logging doesn't respect `maxlog` (#1858)
- TOC in dark mode is still light when aside (#1860)
- ProgressLogging: suppressed logging in Turing.jl (#1862)
- Cannot update to version 0.17.7 (#1869)
- Stdlib packages marked as not found (#1872)
- EllipsisNotation.jl (`randn((10,10))[1, ..]`) does not work (#1875)
- Too many intermediate bond values (#1891)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants