@@ -18,4 +18,18 @@ module JobsHelper  | 
            ||
| 18 | 18 | 
                'in ' + distance_of_time_in_words(time, now)  | 
            
| 19 | 19 | 
                end  | 
            
| 20 | 20 | 
                end  | 
            
| 21 | 
                +  | 
            |
| 22 | 
                + # Given an queued job, parse the stored YAML to retrieve the ID of the Agent  | 
            |
| 23 | 
                + # meant to be ran.  | 
            |
| 24 | 
                + #  | 
            |
| 25 | 
                + # Can return nil, or an instance of Agent.  | 
            |
| 26 | 
                + def agent_from_job(job)  | 
            |
| 27 | 
                + begin  | 
            |
| 28 | 
                + Agent.find_by_id(YAML.load(job.handler).args[0])  | 
            |
| 29 | 
                + rescue ArgumentError  | 
            |
| 30 | 
                + # We can get to this point before all of the agents have loaded (usually,  | 
            |
| 31 | 
                + # in development)  | 
            |
| 32 | 
                + nil  | 
            |
| 33 | 
                + end  | 
            |
| 34 | 
                + end  | 
            |
| 21 | 35 | 
                end  | 
            
                @@ -11,6 +11,7 @@  | 
            ||
| 11 | 11 | 
                <table class='table table-striped events'>  | 
            
| 12 | 12 | 
                <tr>  | 
            
| 13 | 13 | 
                <th>Status</th>  | 
            
| 14 | 
                + <th>Agent</th>  | 
            |
| 14 | 15 | 
                <th>Created</th>  | 
            
| 15 | 16 | 
                <th>Next Run</th>  | 
            
| 16 | 17 | 
                <th>Attempts</th>  | 
            
                @@ -19,9 +20,11 @@  | 
            ||
| 19 | 20 | 
                </tr>  | 
            
| 20 | 21 | 
                 | 
            
| 21 | 22 | 
                <% @jobs.each do |job| %>  | 
            
| 23 | 
                + <% agent = agent_from_job(job) %>  | 
            |
| 22 | 24 | 
                <tr>  | 
            
| 23 | 25 | 
                <td><%= status(job) %></td>  | 
            
| 24 | 
                - <td title='<%= job.created_at %>'><%= time_ago_in_words job.created_at %> ago</td>  | 
            |
| 26 | 
                + <td><%= agent ? link_to(agent.name, agent_path(agent)) : "(deleted)" %></td>  | 
            |
| 27 | 
                +            <td title='<%= job.created_at %>'><%= time_ago_in_words job.created_at %> ago <%= agent ? "for #{agent.user.username}" : '' %></td>
               | 
            |
| 25 | 28 | 
                <td title='<%= job.run_at %>'>  | 
            
| 26 | 29 | 
                <% if !job.failed_at %>  | 
            
| 27 | 30 | 
                <%= relative_distance_of_time_in_words job.run_at %>  | 
            
                @@ -4,8 +4,15 @@ describe JobsController do  | 
            ||
| 4 | 4 | 
                 | 
            
| 5 | 5 | 
                describe "GET index" do  | 
            
| 6 | 6 | 
                before do  | 
            
| 7 | 
                - Delayed::Job.create!  | 
            |
| 8 | 
                - Delayed::Job.create!  | 
            |
| 7 | 
                + async_handler_yaml =  | 
            |
| 8 | 
                + "--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/class 'Agent'\nmethod_name: :async_check_without_delay\nargs:\n- %d\n"  | 
            |
| 9 | 
                +  | 
            |
| 10 | 
                + Delayed::Job.create!(handler: async_handler_yaml % [agents(:jane_website_agent).id])  | 
            |
| 11 | 
                + Delayed::Job.create!(handler: async_handler_yaml % [agents(:bob_website_agent).id])  | 
            |
| 12 | 
                + Delayed::Job.create!(handler: async_handler_yaml % [agents(:jane_weather_agent).id])  | 
            |
| 13 | 
                + agents(:jane_website_agent).destroy  | 
            |
| 14 | 
                + Delayed::Job.create!(handler: async_handler_yaml % [agents(:bob_weather_agent).id], locked_at: Time.now, locked_by: 'test')  | 
            |
| 15 | 
                +  | 
            |
| 9 | 16 | 
                expect(Delayed::Job.count).to be > 0  | 
            
| 10 | 17 | 
                end  | 
            
| 11 | 18 | 
                 | 
            
                @@ -19,7 +26,7 @@ describe JobsController do  | 
            ||
| 19 | 26 | 
                expect(users(:jane)).to be_admin  | 
            
| 20 | 27 | 
                sign_in users(:jane)  | 
            
| 21 | 28 | 
                get :index  | 
            
| 22 | 
                - expect(assigns(:jobs).length).to eq(2)  | 
            |
| 29 | 
                + expect(assigns(:jobs).length).to eq(4)  | 
            |
| 23 | 30 | 
                end  | 
            
| 24 | 31 | 
                end  | 
            
| 25 | 32 | 
                 |