Skip to content

Commit bb9085f

Browse files
author
Vidas P
committed
Refactor agent runner and scheduler
Multiple fixes and refactorings in preparation for completely new runner architecture. Refactor agent running and scheduling code into a separate component. Remove SchedulerAgent (to be implemented as core funtionality). Multiple other changes.
1 parent 474d1e2 commit bb9085f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+269
-1792
lines changed

.rubocop.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
Layout/SpaceAroundMethodCallOperator:
2+
Enabled: true
3+
Lint/RaiseException:
4+
Enabled: true
5+
Lint/StructNewOverride:
6+
Enabled: true
7+
Style/ExponentialNotation:
8+
Enabled: true
9+
Style/HashEachMethods:
10+
Enabled: true
11+
Style/HashTransformKeys:
12+
Enabled: true
13+
Style/HashTransformValues:
14+
Enabled: true
115
Metrics/ModuleLength:
216
Enabled: false
317
Metrics/ClassLength:
418
Enabled: false
5-
Metrics/LineLength:
19+
Layout/LineLength:
620
Enabled: false
721
Style/NumericPredicate:
822
Enabled: false

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Removed
1717
- Wunderlist agent removed (service has shut down).
1818

19+
### Changed
20+
- Remove SchedulerAgent (to be implemented as a core functionality).
21+
- Refactor agent runner and scheduler.
22+
1923

2024
## [0.9.8] - 2020-05-11
2125
### Fixed

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
start:
33
bundle exec foreman start
44

5-
.PHONY: setup-heroku
6-
setup-heroku:
7-
bundle exec bin/setup_heroku
8-
95
.PHONY: build-image
106
build-image:
117
docker build -t local/active_workflow .

Procfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
web: bundle exec puma -C ./deployment/heroku/puma.rb
2-
31
# Use configuration bellow to run jobs on a separate dyno.
4-
#web: bundle exec puma
5-
#jobs: bundle exec rails runner bin/threaded.rb
2+
web: bundle exec puma
3+
scheduler: bundle exec rails runner bin/pro_scheduler.rb
4+
worker: bundle exec script/delayed_job -n 4 run
65

76
###############################
87
# Multiple DelayedJob workers #

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,6 @@ These are agents that control the workflow and perform common and simple data pr
205205
<td><strong>JavaScript Agent</strong></td>
206206
<td>Allows you to write JavaScript code that can create and receive messages. If other agents aren’t meeting your needs, try this one!</td>
207207
</tr>
208-
<tr>
209-
<td><strong>Scheduler Agent</strong></td>
210-
<td>Periodically takes an action on target agents according to a user-defined schedule.</td>
211-
</tr>
212208
<tr>
213209
<td><strong>Attribute&nbsp;Difference&nbsp;Agent</strong></td>
214210
<td>Receives messages and emits a new message with the difference or change of a specific attribute in comparison to the message received.</td>
@@ -342,19 +338,11 @@ source tree, you could do that using Heroku's command line interface.
342338
Please install Heroku's command line interface tool from
343339
[Heroku Toolbelt](https://toolbelt.heroku.com).
344340

345-
For your convenience there is a helper script that guides you through all the
346-
steps necessary to deploy to Heroku. It helps with Heroku app creation, plugin
347-
installation, initial configuration and repository synchronisation. Helper
348-
script is run with:
349-
350-
```sh
351-
make setup-heroku
352-
```
353-
354341
For additional configuration options please take a look at the `.env` file.
355342
Don't forget to set any configuration options you may require using the
356343
`heroku config` command line tool.
357344

345+
FIXME:
358346
The default ActiveWorkflow configuration uses the same single dyno to run both
359347
the web server and workers.
360348

app/assets/javascripts/components/worker-checker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
$(function() {
2-
let sinceId = null;
32
let previousJobs = null;
43

54
if ($(".job-indicator").length) {
65
var check = function() {
6+
let sinceId = $("#message-indicator").data("sinceId");
7+
78
const query =
89
(sinceId != null) ?
910
`?since_id=${sinceId}`
@@ -41,7 +42,8 @@ $(function() {
4142
$("#message-indicator").tooltip('dispose').fadeOut();
4243
}
4344

44-
if (sinceId == null) { sinceId = json.max_id; }
45+
$("#message-indicator").data("sinceId", json.max_id);
46+
4547
const currentJobs = [json.pending, json.awaiting_retry, json.recent_failures];
4648
if ((document.location.pathname === '/jobs') && ($(".modal[aria-hidden=false]").length === 0) && (previousJobs != null) && (previousJobs.join(',') !== currentJobs.join(','))) {
4749
if (!document.location.search || (document.location.search === '?page=1')) {

app/assets/javascripts/pages/workflow-show-page.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
this.WorkflowShowPage = class WorkflowShowPage {
22
constructor() {
3+
this.changeModalText();
34
}
45

56
changeModalText() {
67
$('.disable-all-agents').click(function() {
7-
$('#enable-disable-agents .modal-body-action').text('Would you like to disable all agents?');
88
$('#workflow-disabled-value').val('true');
9+
$('#enable-disable-agents .modal-body-action').text('Would you like to disable all agents?');
910
});
1011
$('.enable-all-agents').click(function() {
11-
$('#enable-disable-agents .modal-body-action').text('Would you like to enable all agents?');
1212
$('#workflow-disabled-value').val('false');
13+
$('#enable-disable-agents .modal-body-action').text('Would you like to enable all agents?');
1314
});
1415
}
1516
};

app/concerns/long_runnable.rb

Lines changed: 0 additions & 144 deletions
This file was deleted.

app/controllers/worker_status_controller.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
class WorkerStatusController < ApplicationController
22
def show
33
start = Time.now
4-
messages = current_user.messages
54

6-
if params[:since_id].present?
7-
since_id = params[:since_id].to_i
8-
messages = messages.where('id > ?', since_id)
9-
end
5+
since_id = params[:since_id].presence || 0
6+
7+
messages = current_user.messages.where('id > ?', since_id)
108

119
result = messages.select('COUNT(id) AS count', 'MAX(id) AS max_id')
1210
.reorder(Arel.sql('min(created_at)')).first
1311
count, max_id = result.count, result.max_id
1412

13+
# Max aggregate only works if there are any new messages.
14+
max_id = since_id if count == 0
15+
1516
render json: {
1617
pending: Delayed::Job.pending.where('run_at <= ?', start).count,
1718
awaiting_retry: Delayed::Job.awaiting_retry.count,

app/helpers/jobs_helper.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,8 @@ def agent_from_job(job)
2727
case data['job_class']
2828
when 'AgentCheckJob', 'AgentReceiveJob'
2929
Agent.find_by_id(data['arguments'][0])
30-
when 'AgentRunScheduleJob'
31-
"Run Agent schedule '#{data['arguments'][0]}'"
3230
when 'AgentCleanupExpiredJob'
3331
'Run Message cleanup'
34-
when 'AgentPropagateJob'
35-
'Run Message propagation'
3632
else
3733
false
3834
end

0 commit comments

Comments
 (0)