Add an ability to schedule jobs to be executed in the future. #6

Closed
eugenijm wants to merge 0 commits from gitlab-mr-iid-3 into master
Member

Closes #2

This can be used for scheduled activities pleroma/pleroma#4375

Closes #2 This can be used for scheduled activities https://git.pleroma.social/pleroma/pleroma/pulls/4375#note_23055
Author
Member

Going to rework this a bit to properly handle entries with the same timestamps.
Edit: Done

Going to rework this a bit to properly handle entries with the same timestamps. Edit: Done
Author
Member

The idea is that persistence can be added if needed by creating and plugging in a different store (e.g. mnesia-based).

The idea is that persistence can be added if needed by creating and plugging in a different store (e.g. mnesia-based).
Member

❤️

:heart:
Member

Markdown lists style is not consistent: some use - and some *. I don't care which one we use, but maybe * is better because it's used by Pleroma.

Please, make sure all lists have the same symbol.

Markdown lists style is not consistent: some use `-` and some `*`. I don't care which one we use, but maybe `*` is better because it's used by Pleroma. Please, make sure all lists have the same symbol.
Member

One # per line is enough ;)

One `#` per line is enough ;)
Member

Here and also line 17: need to add a default value [] to Application.get_env/3, like this:

|> Application.get_env(:scheduler, [])

Otherwise, if there is no configuration, it would fail with FunctionClauseError.

Here and also line 17: need to add a default value `[]` to `Application.get_env/3`, like this: ```elixir |> Application.get_env(:scheduler, []) ``` Otherwise, if there is no configuration, it would fail with `FunctionClauseError`.
Member

Please, add a default value to Application.get_env/3.

Please, add a default value to `Application.get_env/3`.
Member

Can you please elaborate on why we need it here?

Can you please elaborate on why we need it here?
Member

I think it should be false by default. We have another pleroma related project which uses the queue and it doesn't need scheduled jobs.

I think it should be `false` by default. We have another pleroma related project which uses the queue and it doesn't need scheduled jobs.
Author
Member

Mainly for tests. What do you think about moving it to config/test.exs? Feels a bit better than adding Application.put_env in test files to enable it since it's going to be disabled by default

Mainly for tests. What do you think about moving it to `config/test.exs`? Feels a bit better than adding `Application.put_env` in test files to enable it since it's going to be disabled by default
Member

PleromaJobQueue.Scheduler.Store behavior states that init/1 may also return {:error, error :: any()}.

I suggest to wrap it into with statement, so a potential store error won't cause a MatchError. Something like this:

def init(_) do
  with true <- PleromaJobQueue.enabled?() and enabled?(),
        {:ok, state} <- @store.init([]) do
    schedule_next(:poll)
    {:ok, state}
  else
    _ -> :ignore
  end
end
`PleromaJobQueue.Scheduler.Store` behavior states that `init/1` may also return `{:error, error :: any()}`. I suggest to wrap it into `with` statement, so a potential store error won't cause a `MatchError`. Something like this: ```elixir def init(_) do with true <- PleromaJobQueue.enabled?() and enabled?(), {:ok, state} <- @store.init([]) do schedule_next(:poll) {:ok, state} else _ -> :ignore end end ```
Member

I see. When you add default values to all Application.get_env calls it will work without config (I've just tried and it worked on my machine).

I see. When you add default values to all `Application.get_env` calls it will work without config (I've just tried and it worked on my machine).
Author
Member

Probably you tried it with enabled: true. With enabled set to false by default, the scheduler doesn't start in tests, so they don't pass. Confirmed it on my machine :)

Probably you tried it with `enabled: true`. With `enabled` set to `false` by default, the scheduler doesn't start in tests, so they don't pass. Confirmed it on my machine :)
Member

Oh right. :face_palm: Yeah, in this case we need config :pleroma_job_queue, :scheduler, enabled: true let's put it in config/test.exs.

Oh right. :face\_palm: Yeah, in this case we need `config :pleroma_job_queue, :scheduler, enabled: true` let's put it in `config/test.exs`.
Member

I just updated the CI config in master, it should fix the pipeline.

I just updated the CI config in master, it should fix the pipeline.
Member

Hmm, {:ok, state} = @store.init([]) should be {:ok, state} <- @store.init([]) otherwise it would still fail with MatchError.

Also, please don't force push it's hard to track changes.

Hmm, `{:ok, state} = @store.init([])` should be `{:ok, state} <- @store.init([])` otherwise it would still fail with `MatchError`. Also, please don't force push it's hard to track changes.
Author
Member

Nice catch, done. Re: commit history, sure, noted.

Nice catch, done. Re: commit history, sure, noted.
Author
Member

Thanks. I also updated the config so that it doesn't fail in a non-test env

Thanks. I also updated the config so that it doesn't fail in a non-test env
Author
Member

Resolved this. The only place where - is used is the changelog. This is to be consistent with the Pleroma's changelog.

Resolved this. The only place where `-` is used is the changelog. This is to be consistent with the Pleroma's changelog.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pleroma-elixir-libraries/pleroma_job_queue!6
No description provided.