{"action":"created","comment":{"url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/comments/45594955","id":45594955,"diff_hunk":"@@ -28,19 +28,57 @@ def self.get_algorithms\n     end\n \n     ##\n-    # Arguments:\n-    # * name - symbol representing Algorithm implementation\n-    # * experiment,\n-    #   user_id,\n-    #   allowed_infrastructures,\n-    #   planned_finish_time - standard attributes for Algorithms (see #SampleAlgorithm for example)\n-    # * params - hash with additional parameters for specific Algorithm implementations\n+    # Arguments: attributes hash containing:\n+    #  * name - symbol representing Algorithm implementation\n+    #  * experiment_id,\n+    #    user_id,\n+    #    allowed_infrastructures,\n+    #    planned_finish_time,\n+    #    last_update_time - standard attributes for Algorithms (see #Algorithm for details)\n+    #  * params (optional) - hash with additional parameters for specific Algorithm implementations\n     # Returns new instance of Algorithm implementation for given name\n     # Raises AlgorithmNameUnknown if given name is unknown\n-    # Raises AlgorithmParameterMissing if attributes required by Algorithm implementation are not present in params\n-    def self.create_algorithm(name, experiment, user_id, allowed_infrastructures, planned_finish_time, params = {})\n-      raise AlgorithmNameUnknown unless ALGORITHMS.keys.include? name\n-      ALGORITHMS[name].new(experiment, user_id, allowed_infrastructures, planned_finish_time, params)\n+    # Raises AlgorithmParameterMissing if attributes required by Algorithm are not present\n+    def self.create_algorithm(attributes)\n+      attributes.symbolize_keys!\n+      validate_attributes(attributes)\n+      class_name = attributes[:name].to_sym\n+      raise AlgorithmNameUnknown.new unless ALGORITHMS.keys.include? class_name\n+      ALGORITHMS[class_name].new(attributes).initialize_runtime_fields\n+    end\n+\n+\n+    ##\n+    # Returns instance of algorithm from cache\n+    # If Algorithm is not stored in cache, new one will be created\n+    # If stored algorithm has last_update_time older than the one in database,\n+    # it will be deleted from cache\n+    def self.get_algorithm(experiment_id)\n+      cache_key = \"workers_scaling_algorithm_#{experiment_id}\"\n+      if Rails.cache.exist?(cache_key)\n+        last_update_time = Algorithm.where({experiment_id: experiment_id},\n+                                           fields: [:last_update_time])\n+                               .first.last_update_time\n+        if Rails.cache.read(cache_key).last_update_time < last_update_time\n+          Rails.cache.delete(cache_key)\n+        end\n+      end\n+\n+      Rails.cache.fetch(cache_key) do","path":"app/models/workers_scaling/algorithm_factory.rb","position":60,"original_position":60,"commit_id":"d264e6a9d570523ca6307e8b7e770511dd9abd37","original_commit_id":"d264e6a9d570523ca6307e8b7e770511dd9abd37","user":{"login":"mpaciore","id":3855041,"avatar_url":"https://avatars.githubusercontent.com/u/3855041?v=3","gravatar_id":"","url":"https://api.github.com/users/mpaciore","html_url":"https://github.com/mpaciore","followers_url":"https://api.github.com/users/mpaciore/followers","following_url":"https://api.github.com/users/mpaciore/following{/other_user}","gists_url":"https://api.github.com/users/mpaciore/gists{/gist_id}","starred_url":"https://api.github.com/users/mpaciore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpaciore/subscriptions","organizations_url":"https://api.github.com/users/mpaciore/orgs","repos_url":"https://api.github.com/users/mpaciore/repos","events_url":"https://api.github.com/users/mpaciore/events{/privacy}","received_events_url":"https://api.github.com/users/mpaciore/received_events","type":"User","site_admin":false},"body":"Jaki dokładnie jest nie wiem, ale znalazłem taką informację na temat MemCacheStore:\r\nhttp://stackoverflow.com/questions/14404584/what-is-the-default-expiry-time-for-rails-cache\r\nWynika z tego, że to działa tak jak chcieliśmy - nieużywane wpisy znikają, używane nie.\r\nGdzieś przewinęła się informacja na temat 1 minuty, ale nie jestem pewien. Jaki czas byłby najlepszy? 5, 10 minut?","created_at":"2015-11-23T11:51:26Z","updated_at":"2015-11-23T11:51:26Z","html_url":"https://github.com/Scalarm/scalarm_experiment_manager/pull/152#discussion_r45594955","pull_request_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/152","_links":{"self":{"href":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/comments/45594955"},"html":{"href":"https://github.com/Scalarm/scalarm_experiment_manager/pull/152#discussion_r45594955"},"pull_request":{"href":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/152"}}},"pull_request":{"url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/152","id":51407576,"html_url":"https://github.com/Scalarm/scalarm_experiment_manager/pull/152","diff_url":"https://github.com/Scalarm/scalarm_experiment_manager/pull/152.diff","patch_url":"https://github.com/Scalarm/scalarm_experiment_manager/pull/152.patch","issue_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues/152","number":152,"state":"open","locked":false,"title":"WSS-28: Changing AlgorithmRunner architecture","user":{"login":"mpaciore","id":3855041,"avatar_url":"https://avatars.githubusercontent.com/u/3855041?v=3","gravatar_id":"","url":"https://api.github.com/users/mpaciore","html_url":"https://github.com/mpaciore","followers_url":"https://api.github.com/users/mpaciore/followers","following_url":"https://api.github.com/users/mpaciore/following{/other_user}","gists_url":"https://api.github.com/users/mpaciore/gists{/gist_id}","starred_url":"https://api.github.com/users/mpaciore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpaciore/subscriptions","organizations_url":"https://api.github.com/users/mpaciore/orgs","repos_url":"https://api.github.com/users/mpaciore/repos","events_url":"https://api.github.com/users/mpaciore/events{/privacy}","received_events_url":"https://api.github.com/users/mpaciore/received_events","type":"User","site_admin":false},"body":"https://jira.plgrid.pl/jira/browse/SCAL-1113\r\n\r\n * Algorithms are saved to database\r\n * AlgorithmRunner now runs in background, runs Algorithms that are saved into database\r\n * AlgorithmRunner has pool of threads\r\n * If Algorithm is already running (e.g. in another EM instance) then its execution is skipped\r\n * AlgorithmFactory caches Algorithms, validates their last_update_time\r\n * Allowed infrastructure are converted to HashWithIndifferentAccess for compatibility with database","created_at":"2015-11-20T20:59:43Z","updated_at":"2015-11-23T11:51:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/152/commits","review_comments_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/152/comments","review_comment_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues/152/comments","statuses_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/statuses/d264e6a9d570523ca6307e8b7e770511dd9abd37","head":{"label":"Scalarm:WSS-28","ref":"WSS-28","sha":"d264e6a9d570523ca6307e8b7e770511dd9abd37","user":{"login":"Scalarm","id":4244361,"avatar_url":"https://avatars.githubusercontent.com/u/4244361?v=3","gravatar_id":"","url":"https://api.github.com/users/Scalarm","html_url":"https://github.com/Scalarm","followers_url":"https://api.github.com/users/Scalarm/followers","following_url":"https://api.github.com/users/Scalarm/following{/other_user}","gists_url":"https://api.github.com/users/Scalarm/gists{/gist_id}","starred_url":"https://api.github.com/users/Scalarm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scalarm/subscriptions","organizations_url":"https://api.github.com/users/Scalarm/orgs","repos_url":"https://api.github.com/users/Scalarm/repos","events_url":"https://api.github.com/users/Scalarm/events{/privacy}","received_events_url":"https://api.github.com/users/Scalarm/received_events","type":"Organization","site_admin":false},"repo":{"id":7915145,"name":"scalarm_experiment_manager","full_name":"Scalarm/scalarm_experiment_manager","owner":{"login":"Scalarm","id":4244361,"avatar_url":"https://avatars.githubusercontent.com/u/4244361?v=3","gravatar_id":"","url":"https://api.github.com/users/Scalarm","html_url":"https://github.com/Scalarm","followers_url":"https://api.github.com/users/Scalarm/followers","following_url":"https://api.github.com/users/Scalarm/following{/other_user}","gists_url":"https://api.github.com/users/Scalarm/gists{/gist_id}","starred_url":"https://api.github.com/users/Scalarm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scalarm/subscriptions","organizations_url":"https://api.github.com/users/Scalarm/orgs","repos_url":"https://api.github.com/users/Scalarm/repos","events_url":"https://api.github.com/users/Scalarm/events{/privacy}","received_events_url":"https://api.github.com/users/Scalarm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Scalarm/scalarm_experiment_manager","description":"Scalarm Experiment Manager is the main component of the Scalarm platform for data farming.","fork":false,"url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager","forks_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/forks","keys_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/teams","hooks_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/hooks","issue_events_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues/events{/number}","events_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/events","assignees_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/assignees{/user}","branches_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/branches{/branch}","tags_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/tags","blobs_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/statuses/{sha}","languages_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/languages","stargazers_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/stargazers","contributors_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/contributors","subscribers_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/subscribers","subscription_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/subscription","commits_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/contents/{+path}","compare_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/merges","archive_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/downloads","issues_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues{/number}","pulls_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls{/number}","milestones_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/milestones{/number}","notifications_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/labels{/name}","releases_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/releases{/id}","created_at":"2013-01-30T13:34:10Z","updated_at":"2015-04-20T15:56:04Z","pushed_at":"2015-11-23T11:12:24Z","git_url":"git://github.com/Scalarm/scalarm_experiment_manager.git","ssh_url":"git@github.com:Scalarm/scalarm_experiment_manager.git","clone_url":"https://github.com/Scalarm/scalarm_experiment_manager.git","svn_url":"https://github.com/Scalarm/scalarm_experiment_manager","homepage":null,"size":38318,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":1,"default_branch":"master"}},"base":{"label":"Scalarm:WSS-master","ref":"WSS-master","sha":"9c899c79e1b606e5a1d20d1a7c1429437f7bc4a6","user":{"login":"Scalarm","id":4244361,"avatar_url":"https://avatars.githubusercontent.com/u/4244361?v=3","gravatar_id":"","url":"https://api.github.com/users/Scalarm","html_url":"https://github.com/Scalarm","followers_url":"https://api.github.com/users/Scalarm/followers","following_url":"https://api.github.com/users/Scalarm/following{/other_user}","gists_url":"https://api.github.com/users/Scalarm/gists{/gist_id}","starred_url":"https://api.github.com/users/Scalarm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scalarm/subscriptions","organizations_url":"https://api.github.com/users/Scalarm/orgs","repos_url":"https://api.github.com/users/Scalarm/repos","events_url":"https://api.github.com/users/Scalarm/events{/privacy}","received_events_url":"https://api.github.com/users/Scalarm/received_events","type":"Organization","site_admin":false},"repo":{"id":7915145,"name":"scalarm_experiment_manager","full_name":"Scalarm/scalarm_experiment_manager","owner":{"login":"Scalarm","id":4244361,"avatar_url":"https://avatars.githubusercontent.com/u/4244361?v=3","gravatar_id":"","url":"https://api.github.com/users/Scalarm","html_url":"https://github.com/Scalarm","followers_url":"https://api.github.com/users/Scalarm/followers","following_url":"https://api.github.com/users/Scalarm/following{/other_user}","gists_url":"https://api.github.com/users/Scalarm/gists{/gist_id}","starred_url":"https://api.github.com/users/Scalarm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scalarm/subscriptions","organizations_url":"https://api.github.com/users/Scalarm/orgs","repos_url":"https://api.github.com/users/Scalarm/repos","events_url":"https://api.github.com/users/Scalarm/events{/privacy}","received_events_url":"https://api.github.com/users/Scalarm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Scalarm/scalarm_experiment_manager","description":"Scalarm Experiment Manager is the main component of the Scalarm platform for data farming.","fork":false,"url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager","forks_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/forks","keys_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/teams","hooks_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/hooks","issue_events_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues/events{/number}","events_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/events","assignees_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/assignees{/user}","branches_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/branches{/branch}","tags_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/tags","blobs_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/statuses/{sha}","languages_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/languages","stargazers_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/stargazers","contributors_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/contributors","subscribers_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/subscribers","subscription_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/subscription","commits_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/contents/{+path}","compare_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/merges","archive_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/downloads","issues_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues{/number}","pulls_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls{/number}","milestones_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/milestones{/number}","notifications_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/labels{/name}","releases_url":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/releases{/id}","created_at":"2013-01-30T13:34:10Z","updated_at":"2015-04-20T15:56:04Z","pushed_at":"2015-11-23T11:12:24Z","git_url":"git://github.com/Scalarm/scalarm_experiment_manager.git","ssh_url":"git@github.com:Scalarm/scalarm_experiment_manager.git","clone_url":"https://github.com/Scalarm/scalarm_experiment_manager.git","svn_url":"https://github.com/Scalarm/scalarm_experiment_manager","homepage":null,"size":38318,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/152"},"html":{"href":"https://github.com/Scalarm/scalarm_experiment_manager/pull/152"},"issue":{"href":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues/152"},"comments":{"href":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/issues/152/comments"},"review_comments":{"href":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/152/comments"},"review_comment":{"href":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/pulls/152/commits"},"statuses":{"href":"https://api.github.com/repos/Scalarm/scalarm_experiment_manager/statuses/d264e6a9d570523ca6307e8b7e770511dd9abd37"}}}}