GithubHelp home page GithubHelp logo

Comments (5)

martinhpedersen avatar martinhpedersen commented on June 6, 2024

Have you considered using inotifywait? That's what Pat uses internally to refresh it's state once a new message is received or posted to the outbox.

from pat.

martinhpedersen avatar martinhpedersen commented on June 6, 2024

https://github.com/la5nta/pat/blob/master/websocket_hub.go#L100-L131

from pat.

Mihara avatar Mihara commented on June 6, 2024

Have you considered using inotifywait?

Yes, when I said "a perpetually running process or a cron job". It can already be done. There are reasons why I don't consider that a good solution:

  1. Yet another program needs to be kept running in parallel waiting for notify or cycling on timer, when, in addition to Pat we already have, at the very least, modems to consider.
  2. Are file writes to mailbox actually atomic? On the whole file level? What if my filter takes a while to complete due to making a number of http requests to decide what to write?
  3. Now, instead of being a simple filter, this hypothetical program needs to keep track of which files it has already modified.

Etc, etc. Pat deciding when to invoke the filter instead is the natural solution that doesn't feel like a hack.

from pat.

martinhpedersen avatar martinhpedersen commented on June 6, 2024
  1. Are you concerned about the complexity of managing this extra process (e.g. start/stop), or is it the system load you are concerned about?
  2. No, those operations are not atomic. This can easily be fixed in Pat by first writing to a temp file, and then renaming it once the data has been fully written. I think we should do this anyway, because the race condition you're concerned about is already there in Pat (in theory).
  3. I'm not sure I follow.. inotifywait will give you the filename of the created message. You would only receive one event per message.

Although I understand it would be easier just to define some hooks in the config, my main concern here is the added complexity to the project when all of this could be implemented using standard unix tools. I mean, where do we draw the line? Some questions that comes to mind:

  1. For inbound messages, when should we trigger this hook? Immediately after the message is received, or do we wait for the session to complete?
  2. Should we block until the process exits?
  3. What should we do if the process exists with an error code?
  4. What should we do with data written to stdout/stderr?
  5. Should the process inherit the environment of the parent process (i.e. Pat)?
  6. Should we spawn the process if a message is moved from one location to another?
  7. Should we spawn the process if the message is updated/modified?

I believe the answer to some of these questions depends on the concrete use case, so this might need to be configurable as well.

Btw, we also provide the eventlog.json file which you could read (in a separate process) for use cases like this. Pat appends events to this file, each event is a JSON encoded message separated by \n. We could extend this with missing information/events to suit your needs.

from pat.

Mihara avatar Mihara commented on June 6, 2024

Are you concerned about the complexity of managing this extra process (e.g. start/stop), or is it the system load you are concerned about?

I am more concerned about managing this extra process than load. Me, I'll be able to do it, no problem. Then I write a program for someone else, through some mischance it gets popular, and people all over are wracking their brains how to properly set it up...

I'm not sure I follow.. inotifywait will give you the filename of the created message. You would only receive one event per message.

Is a message only written to once by Pat in its lifecycle, though? I'm afraid I haven't gotten that deep yet.

Although I understand it would be easier just to define some hooks in the config, my main concern here is the added complexity to the project when all of this could be implemented using standard unix tools. I mean, where do we draw the line?

If you ask me, the line should be drawn where Pat would be able to invoke the equivalent of procmail, but it should not be such a program itself. To that end:

For inbound messages, when should we trigger this hook? Immediately after the message is received, or do we wait for the session to complete?

If the session protocol permits swapping between mail receive and send multiple times per session, and Pat can do that, and pick up newly appearing outbound mail while inbound mail is still transferring, then the hook should trigger immediately -- it's possible that a mail robot will answer a message before the session completes and save everyone time. Otherwise it can wait until the session is complete.

Should we block until the process exits?

The thread (or goroutine) that saves the message to disk should block until the process exits. Everything else shouldn't.

What should we do if the process exists with an error code?

Keep unfiltered message and save that instead, write an error in the log.

What should we do with data written to stdout/stderr?

Assuming a filter, save stdout to the file, print stderr in the log.

Should the process inherit the environment of the parent process (i.e. Pat)?

That would be a handy way to pass configuration variables to some of them, so yes.

Should we spawn the process if a message is moved from one location to another?

No, only when it enters the system and leaves.

Should we spawn the process if the message is updated/modified?

Also no.

I believe the answer to some of these questions depends on the concrete use case, so this might need to be configurable as well.

The most common - but far from only - use case I imagine is what, back in FidoNET era, was called a "mail robot" and is still occasionally seen in the form of email-based services. You send a message to a specially configured address, which a program then acts upon and sends you a reply. A filter is simply a more generic and powerful mechanism for implementing these than reading a mailbox, and beyond simple question-response will also allow general transformations on messages. Like silently converting jpeg images into webp to save transmission time, or transliterating Cyrillic into Latin to make a Russian email readable despite ISO-8859-1.

from pat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.