Git Product home page Git Product logo

queue-sample's Introduction

ELM説明用コード

はじめに

プロジェクトがRailsだからRailsでスケルトンにした。 でも深い意味は無い。

構成概要

ElmDummyはRJB実装が面倒だったから、それっぽいダミーをつくった。 さすがにJavaのダミークラスをつくるのはめんどくさすぎた。

なので、ElmCallerがとりあえずRJBで書くヤツ Rails4のqueue apiは実はないっぽいのでこんな書き方にして損した気がする。

それはさておき、非同期実行はdelayed_jobを使った。 ちなみに主要コードはlib下の2つのみ。

セットアップ

bundle install --path vendor/bundle
bundle exec rails g delayed_job:active_record
bundle exec rake db:migrate

実行のしかた

まずは非同期ジョブ実行用のworkerを起動する

bundle exec rake jobs:work

で、あとはRails consoleで試してみる。 とりあえず通常の処理(同期処理)

elm = ElmCaller.new("PluginA", "data")
elm.run
elm.run
elm.run

とりあえず普通に処理されるはず。でもこれだとWebで同時接続があると同時に走って、ELM的に多分よろしくない。ついでに遅いはず。というわけで非同期処理。(のんぶろっきんぐ)

elm = ElmCaller.new("PluginA", "data")
elm.delay.run
elm.delay.run
elm.delay.run

これでworker側で動くはず。workerをシングルプロセスで上げていると、シリアル処理になるので、つまるところELMの多重実行される心配がない(はず)。加えて、ユーザには先に結果を戻せるので、多少混み合っててもなんとかなる。

queue-sample's People

Contributors

unagi avatar

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.