Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Issue365 add jobs #366

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Issue365 add jobs #366

wants to merge 18 commits into from

Conversation

leenyburger
Copy link
Collaborator

@leenyburger leenyburger commented Jun 1, 2018

Description of changes

Added job functionality.
Includes the following (copied from issue):
new db table
new GET index endpoint
new resource in ActiveAdmin
test coverage
API docs

Jobs table to include:
title
source_url
source
city
state
country
description
status (i.e. active, inactive)
remote
Also include tagging.

Issue Resolved

Fixes #365

@hpjaj hpjaj self-requested a review June 1, 2018 19:52
@jjhampton
Copy link
Member

@leenyburger @hpjaj Any reason that status has to be a string? When using this data in the front-end, it seems a bit fragile to match on strings, especially if they're user-entered via Admin Dashboard, where there's a chance for human typos. Thoughts on using boolean instead? Example: active: true or active: false.

@hpjaj
Copy link
Collaborator

hpjaj commented Jun 2, 2018

@jjhampton - We would create a few constants to ensure data integrity. And a dropdown in ActiveAdmin to choose from.

That said, we can definitely switch to a boolean if you don't foresee any use case where more than two statuses would ever be of value?

If we don't see any value there, then I agree, changing the column name to active and type to boolean would be a good call.

@jjhampton
Copy link
Member

@hpjaj I've already coded up the front-end stuff to filter on for status === "active" for now, should be fine for the time being.
POC here is @ksmacleod99 - Please see above comments - do you envision ever needing to set a Job's status to anything other than just active / inactive?

Copy link
Collaborator

@hpjaj hpjaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

column :remote

actions
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pls add a form for creating/updating. Here is an example:

https://github.com/OperationCode/operationcode_backend/blob/master/app/admin/code_school.rb#L28-L45

Copy link
Collaborator Author

@leenyburger leenyburger Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I add the form and try to add a job I get the following error: "

"exception": "#<ActionView::Template::Error: To use the :country input, please install a country_select plugin, like this one: https://github.com/stefanpenner/country_select>",

Should I install that gem, or are we already using something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hpjaj I don't see where you responded here. If @leenyburger issue has been addressed, disregard just getting visibility.

@@ -0,0 +1,11 @@
module Api
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this extra controller sneak in?

@@ -31,6 +31,9 @@
Service.create!(:name => service)
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -31,6 +31,9 @@
Service.create!(:name => service)
end

# Create jobs
Job.create!(title: "A great job", source_url: "www.applyhere.com", source: "Company A", city: "Virginia Beach", state: "VA", country: "USA", description: "Our job is fun!", status: "active", remote: "false")

# Create team members
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,3 @@
class Job < ApplicationRecord
acts_as_taggable_on
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pls add a method similar to this one in here:

https://github.com/OperationCode/operationcode_backend/blob/master/app/models/user.rb#L130-L141

As well as an associated test. This will confirm that a given job can have tags (plural) added to it, and then we can use this method to query for any jobs that match the search criteria.

require 'test_helper'

class JobTest < ActiveSupport::TestCase
# test "the truth" do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pls create a test in here confirm that the associated Factory is valid. All this would need to do is:

  • use the factory to create a new Job
  • assert that it is valid?

This keeps us honest with respect to any validations that we add to the Job model class, and its associated Factory staying in step with those requirements.

@hpjaj
Copy link
Collaborator

hpjaj commented Jul 14, 2018

re: @jjhampton 's comment here: #366 (comment)

I agree, would be easier to go the boolean route. If that is still on the table (as I know it would require a bit of a refactor on the FE), I would recommend that, as it is for sure the cleanest solution.

If not, then @leenyburger you'll want to follow this pattern in order to implement choices for "active" and "inactive":

#375 (comment)

After this piece is wrapped up, this PR should be ready to ship.

@dmarchante
Copy link
Contributor

Can you review the conflicts and address the final comments from @hpjaj @leenyburger?

@leenyburger
Copy link
Collaborator Author

@dmarchante Yes. I'm out of town until next week but can take a look then.

@apex-omontgomery
Copy link
Member

Hi @leenyburger how is this going? Is there anything blocking you that I can assist with?

@leenyburger
Copy link
Collaborator Author

@wimo7083 No blockers, just haven't been able to find the time. Making up for hurricane delay next week, can take a look the week of the 24th.

@leenyburger
Copy link
Collaborator Author

@wimo7083 I'm not going to be able to get to this in a timely manner. Sorry to leave you hanging!

@apex-omontgomery
Copy link
Member

Okay so I'm going to make the decision we want to use a boolean instead of a string. I think this would align better with what the frontend needs.

For this I'd recommend:

  1. changing status to is_active_status
  2. changing all the mocks to respect a boolean instead of string
  3. changing the schema to respect the new type.

If nobody objects I'd like to finish this up.

@robbkidd
Copy link
Collaborator

robbkidd commented Oct 3, 2018

I have a maybe philosophical question: what does it mean for a job to have an "active status"?

@kylemh
Copy link
Member

kylemh commented Oct 5, 2018

@robbkidd Agreed. I feel like that field is unnecessary. I'd prefer a self-cleaning database.

We could end up having tons of inactive jobs

@apex-omontgomery
Copy link
Member

Since we don't know when the job will expire. it's probably best to make it adjustable. I can add something to the route so we eliminate innactive jobs.

I went with is_open because apparently using open in Factory girl gave me a security warning.

@robbkidd
Copy link
Collaborator

robbkidd commented Oct 5, 2018

🤔 One option for flagging jobs as either open or closed is to record the date on which it closed. This is a bit like a technique named "soft delete." It would involve adding a datetime column closed_at (if you wanted to match the Rails timestamps style). A nil closed_at means the job is still open; a non-nil closed_at means the job is closed and you also know the date it closed. Knowing the closed date means old-and-closed jobs could be removed from the system.

class Job

  scope :open, -> { where(closed_at: nil) }
  scope :closed, -> { where.not(closed_at: nil) }

  def open?
    self.closed_at.nil?
  end

  def closed?
    !open?
  end
end

There is an open method on Kernel that does IO object instantiation. That might have been the cause of the error from FactoriGirl. It is safe to override that method here with the query scope. The Job class is probably not going to use that Kernel method directly to open a file or some other IO stream.

Makefile Outdated Show resolved Hide resolved
.PHONY: test
test: bg
docker-compose run operationcode-psql bash -c "while ! psql --host=operationcode-psql --username=postgres -c 'SELECT 1'; do sleep 5; done;"
docker-compose run ${RAILS_CONTAINER} bash -c 'export RAILS_ENV=test && rake db:test:prepare && rake test && rubocop'
$(DOCKER_COMPOSE) run operationcode-psql bash -c "while ! psql --host=operationcode-psql --username=postgres -c 'SELECT 1'; do sleep 5; done;"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to feel odd about this.

As this gets bigger it should really be things in their own target, or in a bash script. Large makefiles with lots of distractions are hard to understand. Plus hiding tests behind a very long bash script means I can't pass in parameters to run test groups.

city Faker::Address.city
state Faker::Address.state
country Faker::Address.country
description Faker::Lorem.paragraph
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the attributes being set above this comment should get assigned with block to evaluate the Faker data lazily each time the factory is used instead of at test load time. Otherwise all jobs created with this factory will have the same values.

e.g. title { Faker::Lorem.characters(7) }

@@ -0,0 +1,10 @@
class Job < ApplicationRecord
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does having this in the models section of the code base make it clear enough that this is separate from Sidekiq Jobs?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, yes. Though, it might be helpful to rename the background jobs from Job(s) to Worker(s).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you don't want JobJobs?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you mention it, maybe WorkJobber.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add jobs table, endpoint, and functionality
8 participants