{"action":"created","comment":{"url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/comments/24891733","id":24891733,"diff_hunk":"@@ -5,19 +5,19 @@ tags:\n - Scheduler\r\n ---\r\n \r\n-With the NServiceBus scheduling capability you can schedule a task to be executed repeatedly in a given interval.\r\n+The NServiceBus Scheduler is a lightweight/non-durable API that helps to schedule a task that needs to be executed repeatedly based on a specified interval. The scheduling infrastructure leverages the reliable messaging approach and the NServiceBus core functionality. This allows scheduling to include features such as built in retries and forwarding to the error queue. \r\n \r\n-## Use cases\r\n+## When not to use it\r\n \r\n-You could use the scheduler to repeatedly poll some folder on your HDD for a file, schedule a reoccurring re-index of a database in a multi-tenant environment, and so on.\r\n+- As soon as your task starts to get some branching logic (`if` or `switch` statements) or you start to add business logic, instead of a simple Bus.Send() or a Bus.SendLocal(), you should consider moving to a [saga](sagas-in-nservicebus.md) .\r\n \r\n-Do not add any business logic in your tasks; instead, use [sagas](sagas-in-nservicebus.md).\r\n+- Often times, rather than poll for a certain state using the Scheduler API, you can use an eventing model instead, where an event is published when that state transition occurs and take the necessary action in that event message handler.\r\n \r\n-### Push versus Poll\r\n+## How the scheduler works\r\n \r\n-In the scenario where you are \"polling\" for some change in information state you should instead consider a \"push\" approach.\r\n+The scheduler holds a all list of tasks scheduled in a non-durable in-memory dictionary. In version 3 and 4 tasks are scoped per `AppDomain`. In version 5 they are scoped per Bus instance.\r\n \r\n-The scheduling API is often used to poll state, for example the file system or an external webservice. In these scenarios it is much more efficient to adopt a push based model. In the case of the file system you should instead consider a [FileSystemWatcher](http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx). In the case a webservice should instead consider a [WebHook](http://en.wikipedia.org/wiki/Webhook).\r\n+When a new scheduled task is created it is given an unique identifier and stored in the endpoint's in-memory dictionary. The identifier for the task is sent in a message to the Timeout Manager for the message to be deferred for the specified time interval. When the specified time elapses, the Timeouts dispatcher returns the message containing the identifier to the endpoint with the scheduled task identifier, the endpoint uses that identifier to fetch and invoke the task from its internal list of tasks and executes them.\r","path":"nservicebus/scheduling-with-nservicebus.md","position":23,"original_position":23,"commit_id":"08fa9eaa857043e90263d7e04242e0acccd0f1b1","original_commit_id":"08fa9eaa857043e90263d7e04242e0acccd0f1b1","user":{"login":"mauroservienti","id":1325611,"avatar_url":"https://avatars.githubusercontent.com/u/1325611?v=3","gravatar_id":"","url":"https://api.github.com/users/mauroservienti","html_url":"https://github.com/mauroservienti","followers_url":"https://api.github.com/users/mauroservienti/followers","following_url":"https://api.github.com/users/mauroservienti/following{/other_user}","gists_url":"https://api.github.com/users/mauroservienti/gists{/gist_id}","starred_url":"https://api.github.com/users/mauroservienti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mauroservienti/subscriptions","organizations_url":"https://api.github.com/users/mauroservienti/orgs","repos_url":"https://api.github.com/users/mauroservienti/repos","events_url":"https://api.github.com/users/mauroservienti/events{/privacy}","received_events_url":"https://api.github.com/users/mauroservienti/received_events","type":"User","site_admin":false},"body":"is the Saxon genitive form correct? \"endpoint's in-memory\" shouldn't is simply be \"endpoint in-memory\"\r\n","created_at":"2015-02-18T10:29:05Z","updated_at":"2015-02-18T10:29:05Z","html_url":"https://github.com/Particular/docs.particular.net/pull/571#discussion_r24891733","pull_request_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/571","_links":{"self":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/comments/24891733"},"html":{"href":"https://github.com/Particular/docs.particular.net/pull/571#discussion_r24891733"},"pull_request":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/571"}}},"pull_request":{"url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/571","id":29513917,"html_url":"https://github.com/Particular/docs.particular.net/pull/571","diff_url":"https://github.com/Particular/docs.particular.net/pull/571.diff","patch_url":"https://github.com/Particular/docs.particular.net/pull/571.patch","issue_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/571","number":571,"state":"open","locked":false,"title":"WIP - Fixing guidelines for the scheduler. ","user":{"login":"indualagarsamy","id":854553,"avatar_url":"https://avatars.githubusercontent.com/u/854553?v=3","gravatar_id":"","url":"https://api.github.com/users/indualagarsamy","html_url":"https://github.com/indualagarsamy","followers_url":"https://api.github.com/users/indualagarsamy/followers","following_url":"https://api.github.com/users/indualagarsamy/following{/other_user}","gists_url":"https://api.github.com/users/indualagarsamy/gists{/gist_id}","starred_url":"https://api.github.com/users/indualagarsamy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indualagarsamy/subscriptions","organizations_url":"https://api.github.com/users/indualagarsamy/orgs","repos_url":"https://api.github.com/users/indualagarsamy/repos","events_url":"https://api.github.com/users/indualagarsamy/events{/privacy}","received_events_url":"https://api.github.com/users/indualagarsamy/received_events","type":"User","site_admin":false},"body":"DO NOT MERGE\r\nRelates to: https://github.com/Particular/Requirements/issues/188\r\nClarified the limitations of the scheduler. \r\n\r\n**Questions:**\r\n- Do you think its better to separate out the last section to its own article? \r\n\r\n**Still to do**\r\n- Add code snippet for the saga sample for v3 and v4","created_at":"2015-02-18T10:17:25Z","updated_at":"2015-02-18T10:29:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/571/commits","review_comments_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/571/comments","review_comment_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/571/comments","statuses_url":"https://api.github.com/repos/Particular/docs.particular.net/statuses/08fa9eaa857043e90263d7e04242e0acccd0f1b1","head":{"label":"Particular:scheduler-api","ref":"scheduler-api","sha":"08fa9eaa857043e90263d7e04242e0acccd0f1b1","user":{"login":"Particular","id":5038441,"avatar_url":"https://avatars.githubusercontent.com/u/5038441?v=3","gravatar_id":"","url":"https://api.github.com/users/Particular","html_url":"https://github.com/Particular","followers_url":"https://api.github.com/users/Particular/followers","following_url":"https://api.github.com/users/Particular/following{/other_user}","gists_url":"https://api.github.com/users/Particular/gists{/gist_id}","starred_url":"https://api.github.com/users/Particular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Particular/subscriptions","organizations_url":"https://api.github.com/users/Particular/orgs","repos_url":"https://api.github.com/users/Particular/repos","events_url":"https://api.github.com/users/Particular/events{/privacy}","received_events_url":"https://api.github.com/users/Particular/received_events","type":"Organization","site_admin":false},"repo":{"id":11727301,"name":"docs.particular.net","full_name":"Particular/docs.particular.net","owner":{"login":"Particular","id":5038441,"avatar_url":"https://avatars.githubusercontent.com/u/5038441?v=3","gravatar_id":"","url":"https://api.github.com/users/Particular","html_url":"https://github.com/Particular","followers_url":"https://api.github.com/users/Particular/followers","following_url":"https://api.github.com/users/Particular/following{/other_user}","gists_url":"https://api.github.com/users/Particular/gists{/gist_id}","starred_url":"https://api.github.com/users/Particular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Particular/subscriptions","organizations_url":"https://api.github.com/users/Particular/orgs","repos_url":"https://api.github.com/users/Particular/repos","events_url":"https://api.github.com/users/Particular/events{/privacy}","received_events_url":"https://api.github.com/users/Particular/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Particular/docs.particular.net","description":"Contains all the content including code snippets particular documentation","fork":false,"url":"https://api.github.com/repos/Particular/docs.particular.net","forks_url":"https://api.github.com/repos/Particular/docs.particular.net/forks","keys_url":"https://api.github.com/repos/Particular/docs.particular.net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Particular/docs.particular.net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Particular/docs.particular.net/teams","hooks_url":"https://api.github.com/repos/Particular/docs.particular.net/hooks","issue_events_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/events{/number}","events_url":"https://api.github.com/repos/Particular/docs.particular.net/events","assignees_url":"https://api.github.com/repos/Particular/docs.particular.net/assignees{/user}","branches_url":"https://api.github.com/repos/Particular/docs.particular.net/branches{/branch}","tags_url":"https://api.github.com/repos/Particular/docs.particular.net/tags","blobs_url":"https://api.github.com/repos/Particular/docs.particular.net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Particular/docs.particular.net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Particular/docs.particular.net/git/refs{/sha}","trees_url":"https://api.github.com/repos/Particular/docs.particular.net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Particular/docs.particular.net/statuses/{sha}","languages_url":"https://api.github.com/repos/Particular/docs.particular.net/languages","stargazers_url":"https://api.github.com/repos/Particular/docs.particular.net/stargazers","contributors_url":"https://api.github.com/repos/Particular/docs.particular.net/contributors","subscribers_url":"https://api.github.com/repos/Particular/docs.particular.net/subscribers","subscription_url":"https://api.github.com/repos/Particular/docs.particular.net/subscription","commits_url":"https://api.github.com/repos/Particular/docs.particular.net/commits{/sha}","git_commits_url":"https://api.github.com/repos/Particular/docs.particular.net/git/commits{/sha}","comments_url":"https://api.github.com/repos/Particular/docs.particular.net/comments{/number}","issue_comment_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/comments/{number}","contents_url":"https://api.github.com/repos/Particular/docs.particular.net/contents/{+path}","compare_url":"https://api.github.com/repos/Particular/docs.particular.net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Particular/docs.particular.net/merges","archive_url":"https://api.github.com/repos/Particular/docs.particular.net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Particular/docs.particular.net/downloads","issues_url":"https://api.github.com/repos/Particular/docs.particular.net/issues{/number}","pulls_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls{/number}","milestones_url":"https://api.github.com/repos/Particular/docs.particular.net/milestones{/number}","notifications_url":"https://api.github.com/repos/Particular/docs.particular.net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Particular/docs.particular.net/labels{/name}","releases_url":"https://api.github.com/repos/Particular/docs.particular.net/releases{/id}","created_at":"2013-07-28T23:18:15Z","updated_at":"2015-02-18T10:12:34Z","pushed_at":"2015-02-18T10:12:34Z","git_url":"git://github.com/Particular/docs.particular.net.git","ssh_url":"git@github.com:Particular/docs.particular.net.git","clone_url":"https://github.com/Particular/docs.particular.net.git","svn_url":"https://github.com/Particular/docs.particular.net","homepage":"http://docs.particular.net","size":25647,"stargazers_count":7,"watchers_count":7,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":53,"mirror_url":null,"open_issues_count":94,"forks":53,"open_issues":94,"watchers":7,"default_branch":"master"}},"base":{"label":"Particular:master","ref":"master","sha":"c9477038fb4d035d3fdd8830dad36d734350169a","user":{"login":"Particular","id":5038441,"avatar_url":"https://avatars.githubusercontent.com/u/5038441?v=3","gravatar_id":"","url":"https://api.github.com/users/Particular","html_url":"https://github.com/Particular","followers_url":"https://api.github.com/users/Particular/followers","following_url":"https://api.github.com/users/Particular/following{/other_user}","gists_url":"https://api.github.com/users/Particular/gists{/gist_id}","starred_url":"https://api.github.com/users/Particular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Particular/subscriptions","organizations_url":"https://api.github.com/users/Particular/orgs","repos_url":"https://api.github.com/users/Particular/repos","events_url":"https://api.github.com/users/Particular/events{/privacy}","received_events_url":"https://api.github.com/users/Particular/received_events","type":"Organization","site_admin":false},"repo":{"id":11727301,"name":"docs.particular.net","full_name":"Particular/docs.particular.net","owner":{"login":"Particular","id":5038441,"avatar_url":"https://avatars.githubusercontent.com/u/5038441?v=3","gravatar_id":"","url":"https://api.github.com/users/Particular","html_url":"https://github.com/Particular","followers_url":"https://api.github.com/users/Particular/followers","following_url":"https://api.github.com/users/Particular/following{/other_user}","gists_url":"https://api.github.com/users/Particular/gists{/gist_id}","starred_url":"https://api.github.com/users/Particular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Particular/subscriptions","organizations_url":"https://api.github.com/users/Particular/orgs","repos_url":"https://api.github.com/users/Particular/repos","events_url":"https://api.github.com/users/Particular/events{/privacy}","received_events_url":"https://api.github.com/users/Particular/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Particular/docs.particular.net","description":"Contains all the content including code snippets particular documentation","fork":false,"url":"https://api.github.com/repos/Particular/docs.particular.net","forks_url":"https://api.github.com/repos/Particular/docs.particular.net/forks","keys_url":"https://api.github.com/repos/Particular/docs.particular.net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Particular/docs.particular.net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Particular/docs.particular.net/teams","hooks_url":"https://api.github.com/repos/Particular/docs.particular.net/hooks","issue_events_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/events{/number}","events_url":"https://api.github.com/repos/Particular/docs.particular.net/events","assignees_url":"https://api.github.com/repos/Particular/docs.particular.net/assignees{/user}","branches_url":"https://api.github.com/repos/Particular/docs.particular.net/branches{/branch}","tags_url":"https://api.github.com/repos/Particular/docs.particular.net/tags","blobs_url":"https://api.github.com/repos/Particular/docs.particular.net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Particular/docs.particular.net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Particular/docs.particular.net/git/refs{/sha}","trees_url":"https://api.github.com/repos/Particular/docs.particular.net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Particular/docs.particular.net/statuses/{sha}","languages_url":"https://api.github.com/repos/Particular/docs.particular.net/languages","stargazers_url":"https://api.github.com/repos/Particular/docs.particular.net/stargazers","contributors_url":"https://api.github.com/repos/Particular/docs.particular.net/contributors","subscribers_url":"https://api.github.com/repos/Particular/docs.particular.net/subscribers","subscription_url":"https://api.github.com/repos/Particular/docs.particular.net/subscription","commits_url":"https://api.github.com/repos/Particular/docs.particular.net/commits{/sha}","git_commits_url":"https://api.github.com/repos/Particular/docs.particular.net/git/commits{/sha}","comments_url":"https://api.github.com/repos/Particular/docs.particular.net/comments{/number}","issue_comment_url":"https://api.github.com/repos/Particular/docs.particular.net/issues/comments/{number}","contents_url":"https://api.github.com/repos/Particular/docs.particular.net/contents/{+path}","compare_url":"https://api.github.com/repos/Particular/docs.particular.net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Particular/docs.particular.net/merges","archive_url":"https://api.github.com/repos/Particular/docs.particular.net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Particular/docs.particular.net/downloads","issues_url":"https://api.github.com/repos/Particular/docs.particular.net/issues{/number}","pulls_url":"https://api.github.com/repos/Particular/docs.particular.net/pulls{/number}","milestones_url":"https://api.github.com/repos/Particular/docs.particular.net/milestones{/number}","notifications_url":"https://api.github.com/repos/Particular/docs.particular.net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Particular/docs.particular.net/labels{/name}","releases_url":"https://api.github.com/repos/Particular/docs.particular.net/releases{/id}","created_at":"2013-07-28T23:18:15Z","updated_at":"2015-02-18T10:12:34Z","pushed_at":"2015-02-18T10:12:34Z","git_url":"git://github.com/Particular/docs.particular.net.git","ssh_url":"git@github.com:Particular/docs.particular.net.git","clone_url":"https://github.com/Particular/docs.particular.net.git","svn_url":"https://github.com/Particular/docs.particular.net","homepage":"http://docs.particular.net","size":25647,"stargazers_count":7,"watchers_count":7,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":53,"mirror_url":null,"open_issues_count":94,"forks":53,"open_issues":94,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/571"},"html":{"href":"https://github.com/Particular/docs.particular.net/pull/571"},"issue":{"href":"https://api.github.com/repos/Particular/docs.particular.net/issues/571"},"comments":{"href":"https://api.github.com/repos/Particular/docs.particular.net/issues/571/comments"},"review_comments":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/571/comments"},"review_comment":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Particular/docs.particular.net/pulls/571/commits"},"statuses":{"href":"https://api.github.com/repos/Particular/docs.particular.net/statuses/08fa9eaa857043e90263d7e04242e0acccd0f1b1"}}}}