Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. Ways to handle code execution
  2. Separate process
  3. Queue
  4. Blocking in event loop
  5.  
  6. Users register events in a YAML mapping file
  7. User can add to this file, and then call command which makes event loop read from file without having to restart loop
  8. Mapping in the form of: "EventName (sent from JS): fully qualified name", e.g.:
  9.  
  10. "AuthenticateUser": "Namespace\UserAuthenticator"
  11.  
  12. Event handler class which is executed is just standard class which user can use DI in as normal. Completely decoupled from EVERYTHING.
  13.  
  14. Event execution class: strategy to decide which way to execute the code (depending on which of the three interfaces is implemented).
  15.  
  16. Interfaces
  17.  
  18. QueueExecutable
  19. ProcessExecutable
  20. BlockingExecutable
  21. (Fallback if each one not available? Chain of command maybe?)
  22.  
  23. ------
  24.  
  25. QueueExecutable
  26.  
  27. Tool available in application to manage event loops, queues, workers. Stop start etc all of these from a simple UI.
  28.  
  29. Worker code would could be remote or local so... mapping a class wouldn't work if remote. So needs to be a mapping between event name and tube name (beanstalkd terminology). Can ask queue for tube name to see if it exists?
  30.  
  31. So flow: users sends "authenticate" from js, authenticate event is registered as a queued executable. Event handler has mapping between "authenticate" event name and "authenticate-tube" tube name. Adds job to queue with payload of whatever, and loop keeps mapping between connection ID of who sent request and job id (does beanstalk give an id of a worker who accepted the job? If not, fuck... will have to send connection ID through to worker which means coupling...)
  32.  
  33. Assuming no coupling, worker does job, sends back to event loop, look up map for response and connection ID to send it to, and send it.
  34.  
  35. Allow user also to specify how often to have this data pushed to them (how many times we add event to queue). What if job takes 5 seconds, and user specifies 2? Only allow queueing up to max amount? Or something like that... anyway, going off topic.
  36.  
  37. Above was if remote OR local, the queue handles the rest.
  38.  
  39. QueueExecutable defines which tube it sends its payload to (interface method or configuration in YAML file?)? If a worker ID is also required, then maybe a QueueExecutable must return a Response value object which contains this, or gets one back, or something like that...
  40.  
  41. ProcessExecutable
  42. Class locally as process is also locally, so 1:1 mapping between event name and class name. Same options as queue one: i.e. How often to repeat.
  43.  
  44. BlockingExecutable
  45.  
  46. Code executed as standard in-line PHP within event loop - do any IO here and it's your own fault without async
  47.  
  48. Flow
  49.  
  50. User sends .subscribe({subject: torrents}) over wss:// with other body data that event requires
  51. Event loop and onSubscribe() is triggered
  52. Look up to see "torrents" has been configured as a queue executable (torrents class) and for "torrents-ws" tube because of TorrentsQueueExecutable::getTubeName()
  53. TorrentsQueueExecutable can manipulate data before it is returned in required Response object - like Symfony controllers require an object of type Response returned
  54. Send data into torrents-ws queue
  55. Worker somewhere else picks up job, uses payload to get torrent data via CLI and takes as long as it wants
  56. Worker returns data (using zmq) and is passed back into TorrentsQueueExecutableClass to manipulate before it is sent to client via lookup of connection id stored earlier
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement