unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* How to call a local function from a mcron job?
@ 2020-11-29 23:58 EuAndreh
  2020-12-20 22:19 ` Joshua Branson
  0 siblings, 1 reply; 3+ messages in thread
From: EuAndreh @ 2020-11-29 23:58 UTC (permalink / raw)
  To: help-guix

Hi Guix!

I wrote a Guile function that works like a script that take no arguments
and interacts with the filesystem, something like:

  (define (my-fn)
    ...)

It is a wrapper over other functions defined in the same file, and calls
them in the right order.

Then I wanted to make this function run as a mcron job, and I tried:

  (define my-fn-job
    #(job "* * * * *"
          my-fn))

But that doesn't work. At reconfigure time, Guix complains about not
knowing the variable 'my-fn':

  Unbound variable: my-fn

I tried wrapping it in a '(with-imported-modules ...)' call, but the
code isn't in a module, but in the same file.

I guess that putting all my code from 'my-fn' and all the functions it
calls inlined in a lambda in the job definition would solve it, but it
feels wrong to me.

Is there a way to reference it from the job, without embedding all the
scheme code in the job definition?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to call a local function from a mcron job?
  2020-11-29 23:58 How to call a local function from a mcron job? EuAndreh
@ 2020-12-20 22:19 ` Joshua Branson
  2020-12-22 23:44   ` EuAndreh via
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Branson @ 2020-12-20 22:19 UTC (permalink / raw)
  To: EuAndreh; +Cc: help-guix


Heyo EuAndreh!

Perhaps you could put your scheme function into a file in the same
directory as your config.scm.  Call said file "my-fn.scm" with the
content:

#+BEGIN_SRC scheme
(define-module (my-fn)
    #:export (my-fn))

(define (my-fn)
   ...)
#+END_SRC

Then the top of your config.scm should look like this:

#+BEGIN_SRC scheme
(add-to-load-path (dirname (current-filename)))

(use-modules
(gnu)
(guix)
(my-fn)
...)
#+END_SRC

That should solve your issue.  :)

--
Joshua Branson
Sent from Emacs and Gnus
  https://gnucode.me
  https://video.hardlimit.com/accounts/joshua_branson/video-channels
  https://propernaming.org
  "You can have whatever you want, as long as you help

enough other people get what they want." - Zig Ziglar


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to call a local function from a mcron job?
  2020-12-20 22:19 ` Joshua Branson
@ 2020-12-22 23:44   ` EuAndreh via
  0 siblings, 0 replies; 3+ messages in thread
From: EuAndreh via @ 2020-12-22 23:44 UTC (permalink / raw)
  To: Joshua Branson; +Cc: , help-guix

That makes sense. I'll try it later and report back.

Thanks!


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-22 23:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-29 23:58 How to call a local function from a mcron job? EuAndreh
2020-12-20 22:19 ` Joshua Branson
2020-12-22 23:44   ` EuAndreh via

unofficial mirror of help-guix@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guix-user/0 guix-user/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guix-user guix-user/ https://yhetil.org/guix-user \
		help-guix@gnu.org
	public-inbox-index guix-user

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.gnu.guix.user
	nntp://news.gmane.io/gmane.comp.gnu.guix.user


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git