# `Lightning.Workflows.Job`
[🔗](https://github.com/OpenFn/lightning/blob/main/lib/lightning/workflows/job.ex#L1)

Ecto model for Jobs.

A Job contains the fields for defining a job.

* `body`
  The expression/javascript code
* `name`
  A plain text identifier
* `adaptor`
  An NPM style string that contains both the module name and it's version.
  E.g. `@openfn/language-http@v1.2.3` or `@openfn/language-foo@latest`.
  While the version suffix isn't enforced here as it's not strictly necessary
  in this context, the front end will ensure a version is stated (`@latest`
  being the default).

# `t`

```elixir
@type t() :: %Lightning.Workflows.Job{
  __meta__: Ecto.Schema.Metadata.t(),
  adaptor: String.t() | nil,
  body: String.t() | nil,
  credential:
    nil | Lightning.Credentials.Credential.t() | Ecto.Association.NotLoaded.t(),
  delete: term(),
  id: Ecto.UUID.t() | nil,
  inserted_at: term(),
  keychain_credential:
    nil
    | Lightning.Credentials.KeychainCredential.t()
    | Ecto.Association.NotLoaded.t(),
  keychain_credential_id: term(),
  name: String.t() | nil,
  project: term(),
  project_credential: term(),
  project_credential_id: term(),
  steps: term(),
  updated_at: term(),
  workflow:
    nil | Lightning.Workflows.Workflow.t() | Ecto.Association.NotLoaded.t(),
  workflow_id: term()
}
```

# `new`

# `put_project_credential`

# `put_workflow`

```elixir
@spec put_workflow(
  Ecto.Changeset.t(t()),
  Ecto.Changeset.t(Lightning.Workflows.Workflow.t())
) :: Ecto.Changeset.t(t())
```

Attaches a workflow to a job, this is useful when you have an unpersisted
Workflow changeset - and want it to be created at the same time as a Job.

Example:

    workflow =
      Ecto.Changeset.cast(
        %Lightning.Workflows.Workflow{},
        %{ "project_id" => attrs[:project_id], "id" => Ecto.UUID.generate() },
        [:project_id, :id]
      )

    job =
      %Job{}
      |> Ecto.Changeset.change()
      |> Job.put_workflow(workflow)
      |> Job.changeset(attrs)

# `validate`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
