Skip to content
This repository has been archived by the owner on Oct 6, 2019. It is now read-only.

Serverless Functions #22

Open
eaba opened this issue May 8, 2018 · 8 comments
Open

Serverless Functions #22

eaba opened this issue May 8, 2018 · 8 comments

Comments

@eaba
Copy link

eaba commented May 8, 2018

Hi,
Given the way phosphorusfive works, a thought came to my mind: If I were to create a serverless platform, can phosphorusfive be used for things like invoking Custom Functions just the way Azure Functions works? It is just a thought

@polterguy
Copy link
Owner

Hi Eaba,

I must admit that I am not entirely sure about how an Azure Function works, but you can use Hyperlambda, and most of the plugins from the "/plugins/" folder in other types of applications (non-web/server based apps). In fact, there is a project in the source code called "lambda.exe", which allows you to evaluate Hyperlambda files from the Console, arguably giving you the ghist of what would be necessary to implement for instance a WinForm/Console plugin, using Hyperlambda (and its Active Events) in "non-web" apps.

I must admit that it's been a long time since I actually fiddled with this myself, but if my memory serves me correctly, and I haven't created some breaking changes that somehow destroyed this little Console application, I think its syntax was roughly like the following.

lambda.exe -f "hyperlambda-file.hl"

If you're on Linux or Mac, you must prepend mono in front of "lambda.exe".

The above will "execute" the "hyperlambda-file.hl" (assuming it exists). This project only loads some few of the core assemblies, but you can load additional plugins with -p some-plugin.dll.

This project even has an -i argument, allowing you to write Hyperlambda directly into the Console, arguably the same way PowerShell on Windows allows you to directly type in code.

If you fiddle around with this project, and look at its code, I am certain you'll figure out how to use Active Events and the core assemblies in "non-web" scenarios, which I think is kind of your question ...

And in fact, the project is only 300 lines of code, so using it as a starter-kit for your own (non-web apps) would probably be easily achieved. Hopefully this answers at least to some extent your question :)

@eaba
Copy link
Author

eaba commented May 8, 2018

Thanks @polterguy

@eaba eaba closed this as completed May 8, 2018
@polterguy
Copy link
Owner

NP

@eaba
Copy link
Author

eaba commented May 9, 2018

Hi @polterguy looking at this line Loader.Instance.LoadAssembly ("p5.active-event-sample-plugin");
a thought came to mind: am fond of saving uploaded files to the database, so I thought what if Loader.Instance.LoadAssembly can load assembly from a zip file bytes this bytes containing the assembly with Active Events and dependencies? Can this work as I have thought?

@eaba eaba reopened this May 9, 2018
@polterguy
Copy link
Owner

polterguy commented May 9, 2018

Well, I have considered creating Active Event hooks that allows you to (even more) dynamically load assemblies, which would be beneficial while for instance installing apps through the "Desktop" module. Being able to load these from "where ever" might come in handy.

I am not sure I would implement the above myself, since I am a fan of having files in the filesystem myself though - But, if I provided a generic event to load them from Hyperlambda, I guess the step to being able to load them also from "anywhere" would be small enough to justify allowing for it, by allowing developers to create their own loading logic, which again could of course load them from the database.

My personal use-case for dynamically loading assemblies from Hyperlambda, is to make it possible to create "modules" which have custom C# Active Events and code. In fact, the reason why that MSSQL data adapter issue thing is still open (even though it's a year old), is because I have played with the idea of using this type of logic for it. (I don't want to have closed source dependencies in the core project)

Unfortunately, I am now feature complete for the current release cycle though (8.1), so this would be something I would have to re-iterated in a later release (8.2?). Besides, it's a pretty massive change, so I'd need a lot of time to make sure I got it right ...

PS!
You can easily implement this (largely) yourself, by creating an Active Event, from where you de-serialise some piece of "blob" from your database, and save it to some temporary folder ("/commons/documents/private/something/" comes to mind). For then to load it up using the LoadAssembly method from the Loader class.

Just be careful with this though, since all users (including "guest" accounts) happens to have write access to the above (example) folder. However, if you do not create/expose any UI that actually allows any "guest" users to write to it in any ways, you should be safe. An alternative (and safer way) would be to create a custom folder for instance at the root of your system, and then create a startup file, that dynamically loads all assemblies from that folder, after having extracted them from the database, and saved these to your custom folder.

Notice, I am not really sure if I can say that this would be "good practice" though, however it is possible ...

@eaba
Copy link
Author

eaba commented May 9, 2018

some temporary folder (_"/commons/documents/private/something/" comes to mind) I have thought of that while also considering performance if i had a thousand users' functions triggered at the same time.
I know docker containers can help isolate each process but I fancy reading the assembly from bytes, I can even have it saved in-memory.

This feature will be worth it, I perceive!, when you eventually get to implement it.

@eaba
Copy link
Author

eaba commented Oct 23, 2018

Hi @polterguy just checking up on this issue!

@polterguy
Copy link
Owner

Hi Eaba, I'm sorry to say I just haven't found the time for this :(

But it's actually not that difficult to implement yourself, in p5.core everything needed to dynamically load up assemblies is already implemented. You just have to implement something that allows you to invoke it with your own paths to an assembly ...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants